Skip to content

Commit

Permalink
added stable version of the softmax link
Browse files Browse the repository at this point in the history
  • Loading branch information
eljanmahammadli committed Nov 7, 2023
1 parent 86c6494 commit 1f23b7f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gradipy/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def _backward() -> None:
def matmul(self, other: "Tensor") -> "Tensor":
return self @ other

# there is more stable way to compute softmax :D
# https://ogunlao.github.io/2020/04/26/you_dont_really_know_softmax.html
def softmax(self) -> "Tensor":
exps = np.exp(self.data - np.max(self.data, axis=1, keepdims=True))
probs = exps / np.sum(exps, axis=1, keepdims=True)
Expand Down

0 comments on commit 1f23b7f

Please sign in to comment.