3.1.8 · D5Neural Network Fundamentals
Question bank — Loss functions - MSE, cross-entropy
Quick symbol reminder so line one is followable:
- = the truth (the correct answer we wanted).
- = the network's prediction (its guess).
- = the loss, one number saying "how wrong was ".
- = the number of training examples we average the loss over.
- (sigma) = the spread (standard deviation) of the assumed Gaussian noise in regression — it measures how noisy the targets are.
- = a logit, the raw pre-activation score before softmax/sigmoid turns it into a probability.
- = the Kronecker delta: it equals when the two indices match () and when they differ. Think of it as an "is-this-the-same-slot?" switch.
- (epsilon) = a tiny positive number (like ) used as a safety margin to keep probabilities away from the exact and where explodes.
- MSE = Mean Squared Error (regression). CE = Cross-Entropy (classification); BCE = Binary Cross-Entropy, which is simply CE in the special case of exactly classes.
- NLL = Negative Log-Likelihood — the single recipe both losses come from.
The one recipe, shown once (so the rest of the page stands on it)
Before the traps, let us actually watch the recipe both losses obey, so nothing below is asserted blindly.


True or false — justify
Both MSE and cross-entropy are just different names for the same formula.
False. They are the same recipe (negative log-likelihood) applied to different noise models — Gaussian for MSE, Bernoulli/Categorical for cross-entropy — so the resulting formulas differ.
Minimizing loss and maximizing likelihood are opposite goals.
False. They are the same goal. We take of the likelihood (log is monotonic, so it preserves the location of the best ) and flip the sign, turning "maximize probability" into "minimize loss".
The constant in MSE's derivation must be kept or the answer is wrong.
False. Here is the fixed noise spread, so this term does not depend on ; it shifts the loss by a constant and never moves the minimum. We drop it for cleanliness; the optimal weights are unchanged.
Cross-entropy can be negative.
False. It is , and of a number is , so with the minus sign CE . It reaches exactly only when the true-class probability is .
A loss of zero means the network is perfect on training data.
True but dangerous. Zero training loss only means it fits the seen data perfectly; that often signals overfitting, which is why we use Regularization and a held-out set.
MSE always has a smaller numerical value than cross-entropy, so it is "easier" to optimize.
False. The raw magnitude of a loss is meaningless across different losses — they live on different scales. What matters is the shape of the surface and the gradient, not the number's size.
Squaring the error in MSE is done only to remove the sign.
False. It removes the sign and penalizes large errors disproportionately: an error of costs an error of , not , which pushes the model to fix big misses first.
BCE is a different loss from categorical cross-entropy.
False. BCE is exactly categorical CE specialized to : one sigmoid output implies , and the two-term Categorical sum collapses into the compact BCE formula.
The in MSE averages over the output components of a single prediction.
False. Here is the number of examples; the averages the per-example squared errors, not the components of one output vector.
Spot the error
"I fed raw logits straight into to get cross-entropy."
The input to CE's log must be a valid probability in . Raw logits can be negative, so of a negative is undefined (NaN). Fix: apply softmax/sigmoid first, or use a combined logits-to-loss function.
"For my cat-vs-dog classifier I used MSE because outputs are just numbers."
With a sigmoid output, MSE's gradient carries a factor that vanishes when the model is confidently wrong, so learning stalls. Cross-entropy cancels that factor (see the cancellation shown above) and keeps the gradient .
"CE , so I summed the log-terms over all classes including the wrong ones."
Not an error to write the full sum, but note for every wrong class, so those terms are . Only the true-class term actually contributes.
"My BCE gradient is huge for a confident correct answer, which seems wasteful."
For a correct confident answer () the gradient , so it is small, not huge. The huge gradients happen for confident wrong answers — exactly where you want a big correction.
"I normalized my softmax probabilities to sum to 1, then re-applied softmax to be safe."
Softmax already outputs a valid probability distribution summing to . Re-applying it distorts the values (squashes them toward uniform) and breaks the clean softmax+CE gradient .
"I averaged CE over classes () the same way MSE averages over samples ()."
Wrong axis: the averages over examples, not components. CE for one example already collapses to a single term ; you average over examples, never over the class index.
Why questions
Why does the softmax+CE gradient simplify to the same as MSE-with-identity-output?
Because differentiating through softmax uses , and the terms telescope to (shown in the derivation above). It is the same prediction-minus-truth signal MSE gives with an identity output, which feeds clean gradients into Backpropagation.
Why does blow up as the predicted probability approaches ?
As , , so . This encodes "infinite surprise" at seeing an outcome you called impossible, punishing confident wrong answers savagely.
Why does the choice of loss depend on the task rather than the network architecture?
The loss encodes an assumption about how the data's noise/labels are distributed (Gaussian for real values, Categorical for classes). That assumption comes from the nature of the target, which is a property of the task, not the layers.
Why is cross-entropy preferred over MSE specifically when a sigmoid or softmax sits at the output?
Because is a factor that vanishes when is near or ; MSE keeps that factor and its gradient dies there, while CE's produces a matching that cancels it, leaving the live gradient — see Logistic Regression and the cancellation figure above.
Why do we take the log of the likelihood at all, instead of maximizing the raw product?
The product of many tiny probabilities underflows to in floating point, and products are hard to differentiate. turns the product into a sum (easy gradients) and is monotonic, so it does not move the optimum.
Why is a BCE hovering near a red flag during training?
is the loss of a model outputting (pure coin-flip) on every example. Staying there means the model has learned nothing discriminative.
Why does MSE-on-probabilities give a "poorly calibrated" classifier?
MSE assumes Gaussian noise, which is false for discrete labels, so its optimum does not match the true probability. The output numbers then fail to mean "actual chance of the class".
Edge cases
What is the BCE if the model predicts exactly but the truth is ?
It is . In practice we clip into (with a tiny positive number like ) to avoid infinities and NaNs.
What happens to MSE's loss surface if all targets are identical constants?
MSE still has a unique minimum where equals that constant. As a function of a single scalar output it is a parabola; in the full weight space it is a paraboloid (a multidimensional bowl) with one lowest point — nothing degenerates.
For a multi-class problem with classes, what CE does a totally uninformed model (uniform ) achieve?
, the maximum-uncertainty baseline. For this is , matching the binary coin-flip case.
If a true class has predicted probability exactly, what is CE and is that fine?
CE , the perfect score. It is mathematically fine, but reaching it usually needs infinite logits, so real training only approaches it — and forcing it invites overfitting.
What does MSE's gradient do at the exact minimum where ?
It is , so Gradient Descent takes no step — the model has stopped being wrong on that point and correctly leaves it alone.
In binary classification with a single sigmoid output, why can we use the compact BCE instead of the general -class CE?
A single probability implies , so the two-class Categorical collapses to the Bernoulli form . They are the same thing for .
What if two classes tie with equal top probability in softmax — is the loss undefined?
No. CE only reads the true class's probability ; ties among other classes never appear in the formula, so the loss is perfectly well-defined.
Recall One-line summary to lock in
Every trap here reduces to two facts: (1) each loss is an NLL for a specific noise model (derived, not asserted, above), and (2) both clean gradients are because the activation's derivative cancels. If an answer contradicts either, it is the misconception.