-
-
Save iamaaditya/68dc58b3260783f6f3c298ddbc2745ca to your computer and use it in GitHub Desktop.
multi dimensional softmax with tensorflow
This file contains 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
import tensorflow as tf | |
""" | |
Multi dimensional softmax, | |
refer to https://github.com/tensorflow/tensorflow/issues/210 | |
compute softmax along the dimension of target | |
the native softmax only supports batch_size x dimension | |
""" | |
def softmax(target, axis, name=None): | |
with tf.op_scope([target], name, 'softmax'): | |
max_axis = tf.reduce_max(target, axis, keep_dims=True) | |
target_exp = tf.exp(target-max_axis) | |
normalize = tf.reduce_sum(target_exp, axis, keep_dims=True) | |
softmax = target_exp / normalize | |
return softmax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment