A three-class classifier outputs the probability vector y^=[0.3, 0.6, 0.1]⊤, and the true class is the second one. What is the cross-entropy loss?

Deep learning, Loss functions
Level L2 Elementary. Length One-liner. Nature Mat Mathematical.

What's being asked

Whether you can apply the cross-entropy formula with a one-hot target.

Key idea

The target y is one-hot: 1 for the true class and 0 elsewhere. So only the true class survives in the sum: L=−∑kyklog⁡y^k=−log⁡y^true=−ln⁡0.6≈0.511 nats (units of natural log).

Steps

  1. Write the one-hot target, y=[0,1,0]⊤.
  2. Substitute: L=−(0⋅ln⁡0.3+1⋅ln⁡0.6+0⋅ln⁡0.1)=−ln⁡0.6≈0.511 nats.
  3. If the course uses base 2, the answer is −log⁡20.6≈0.737 bits. State which log you use.

Common mistakes

How long your answer should be

One line.

Last checked on 4 December 2026.

Read this

Previous in Deep learning: You plot training and validation loss against epochs. What do the curves look like for (a) underfitting, (b) overfitting and (c) a learning rate that is too high, and what would you do in each case?
Next in Deep learning: Let f(x,y)=ax2log⁡(by+c), where the inputs x,y and the parameters a,b,c are all scalars and log⁡ is the natural log. What is the computational graph with intermediate nodes, and how do you use backpropagation on it to compute ∂f/∂b?