Skip to content

Instantly share code, notes, and snippets.

@domarps
Created April 21, 2018 02:42
Show Gist options
  • Save domarps/b21356780a8723f0243d185d99201ac2 to your computer and use it in GitHub Desktop.
Save domarps/b21356780a8723f0243d185d99201ac2 to your computer and use it in GitHub Desktop.
#FC1 activation
z1 = np.dot(X,W1) + b1 # N X H
# RELU layer
h1 = z1.copy() # N X H
h1[h1 < 0] = 0 # N X H
#FC2 layer
z2 = np.dot(h1, W2) + b2 # N X C
#Output scores
scores = z2
# numerical stability trick (adapted from softmax)
f = scores - scores.max(axis=1)[:, np.newaxis]
# calculate softmax
sum_f = np.sum(np.exp(f), axis = 1, keepdims = True)
softmax_scores = np.exp(f)/sum_f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment