Skip to content

Instantly share code, notes, and snippets.

@llSourcell
Created July 18, 2018 00:15
Show Gist options
  • Select an option

  • Save llSourcell/0a5b5b1f939223502f981948bec30467 to your computer and use it in GitHub Desktop.

Select an option

Save llSourcell/0a5b5b1f939223502f981948bec30467 to your computer and use it in GitHub Desktop.
def cross_entropy(X,y):
"""
X is the output from fully connected layer (num_examples x num_classes)
y is labels (num_examples x 1)
"""
m = y.shape[0]
p = softmax(X)
log_likelihood = -np.log(p[range(m),y])
loss = np.sum(log_likelihood) / m
return loss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment