Created
May 11, 2022 14:53
-
-
Save AlessandroMondin/bdae749bc38895b9c0b054052fcfd2f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def softmax(self, logits): | |
if self.library == "tf": | |
exp = tf.exp(logits) | |
denom = tf.math.reduce_sum(exp, 1, keepdims=True) | |
else: | |
exp = torch.exp(logits) | |
denom = torch.sum(exp, dim=1, keepdim=True) | |
return exp/denom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment