Skip to content

Instantly share code, notes, and snippets.

@AlessandroMondin
Created May 11, 2022 14:53
Show Gist options
  • Save AlessandroMondin/bdae749bc38895b9c0b054052fcfd2f4 to your computer and use it in GitHub Desktop.
Save AlessandroMondin/bdae749bc38895b9c0b054052fcfd2f4 to your computer and use it in GitHub Desktop.
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