Skip to content

Instantly share code, notes, and snippets.

@riodw
Created June 25, 2017 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riodw/eb09e76551b54ea71ec71264da209d91 to your computer and use it in GitHub Desktop.
Save riodw/eb09e76551b54ea71ec71264da209d91 to your computer and use it in GitHub Desktop.
"""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."""
pass # TODO: Compute and return softmax(x)
return np.exp(x) / np.sum(np.exp(x), 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