9/32
Part 3 of 6 · The loss and its gradientLearn and do

Softmax plus cross-entropy

Together they give softmax minus one-hot

Two examples with two classes. Example 1's label is class 0, and example 2's label is class 1.

logits = np.array([[1.0, 1.0], [1.0, -1.0]])
y = np.array([0, 1])
n = len(y)

p = np.exp(logits) / np.exp(logits).sum(axis=1, keepdims=True)
dlogits = p.copy()
dlogits[np.arange(n), y] -= 1
dlogits /= n
print(p.round(2))
print(dlogits.round(2))
Predict

Example 2 has logits [1, -1], label 1 and softmax [0.88, 0.12]. What is its row of dlogits, with the batch of 2?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

Which example sends back the biggest gradient?

Pick an answer above to see the rest