Last active
November 2, 2018 20:07
-
-
Save nad2000/6310c1f0cd196f707480 to your computer and use it in GitHub Desktop.
Compute softmax values for each sets of scores in x. #ml, #deep_learning
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
"""Softmax.""" | |
scores = [3.0, 1.0, 0.2] | |
import numpy as np | |
def softmax(x): | |
"""Compute softmax values for each sets of scores in x.""" | |
E = np.exp(x) | |
return E / E.sum(axis=0) | |
print(softmax(scores)) | |
# Plot softmax curves | |
import matplotlib.pyplot as plt | |
x = np.arange(-2.0, 6.0, 0.1) | |
scores = np.vstack([x, np.ones_like(x), 0.2 * np.ones_like(x)]) | |
plt.plot(x, softmax(scores).T, linewidth=2) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment