In [1]:
import numpy as np


def softmax(x):
    """Compute softmax values for each sets of scores in x."""
    return np.exp(x) / np.sum(np.exp(x), axis=0)

logits = [3.0, 1.0, 0.2]
print(softmax(logits))


[ 0.8360188   0.11314284  0.05083836]

TensorFlow softmax


In [3]:
import tensorflow as tf


logit_data = [2.0, 1.0, 0.1]
logits = tf.placeholder(tf.float32)

softmax = tf.nn.softmax(logits)    

with tf.Session() as sess:
    output = sess.run(softmax, feed_dict={logits : logit_data })

print(output)


[ 0.65900117  0.24243298  0.09856589]

In [ ]: