Intuition The ONE core idea
A loss function is a single number that measures how wrong a prediction is, and training a network means shrinking that number. To read the MSE and cross-entropy formulas you need only a handful of building blocks — a prediction, a truth, a way to combine many errors into one number, and the two "mathematical magnifying glasses" (the square and the logarithm) that decide how mistakes get punished.
This page assumes you have seen none of the notation on the parent note the Loss Functions topic . We will earn every symbol before it is used. Read top to bottom; each block leans only on the ones above it.
Everything starts with two numbers.
y (read "why")
y is the correct answer — the thing reality hands us. If the real house price is 3 lakh, then y = 3 .
Picture: a fixed dot on a number line, painted as the bullseye of a dartboard.
Why we need it: without a correct answer there is nothing to be wrong about .
y ^ (read "why-hat")
The little hat ^ always means "the machine's guess of" . So y ^ is the network's guess at the answer.
Picture: a second dot — where your dart actually landed.
Why we need it: the whole point of a network is to produce y ^ ; the loss compares it to y .
Intuition Error = the gap
The error is simply y − y ^ : how far the guess sits from the truth. On the dartboard it is the arrow from your dart to the bullseye. A loss function is just a rule for turning that gap into a single "how bad" number.
We rarely have one prediction — we have many. We need notation for "the i -th one" and for "add them all up".
i and subscripts y i , y ^ i
i is a counter : i = 1 , 2 , 3 , … . Then y i means "the truth for example number i ", and y ^ i is "the guess for example number i ".
Picture: a numbered row of dartboards — board 1, board 2, board 3.
Why: a network is judged on a whole dataset, not one point.
Definition The summation symbol
∑
i = 1 ∑ n (a big Greek capital sigma) is a machine that says "plug in i = 1 , then 2 , then 3 , up to n , and add every result together" . The number under the sigma (i = 1 ) is where the counter starts ; the number on top (n ) is where it stops .
∑ i = 1 3 a i = a 1 + a 2 + a 3
Picture: a funnel that swallows a list of numbers and pours out their total.
Why the topic needs it: the loss over a dataset is one number, so we must collapse many per-example errors into a single sum. n is just "how many examples".
The raw error y − y ^ has a problem: sometimes it is negative (guess too high), sometimes positive (guess too low). If we just added them, a + 2 and a − 2 would cancel to 0 and hide two bad guesses.
( a ) 2 = a × a . Squaring erases the sign (a negative times a negative is positive) and grows fast for big inputs: 0. 5 2 = 0.25 but 2 2 = 4 .
Picture: a curved "U" bowl — flat and forgiving near zero, steep and punishing far out (see figure).
Why the topic needs it: MSE squares the error so that (a) all errors count as positive, and (b) a mistake twice as large is punished four times as hard.
This "square bowl" is the entire shape of MSE. Its lowest point sits exactly where guess equals truth (y ^ = y ), which is precisely the point training tries to reach.
MSE works when the answer is a plain number (a price, a temperature). But for classification — "cat or dog?" — the network instead outputs a probability : a number between 0 and 1 saying how sure it is.
A probability is a number from 0 (impossible) to 1 (certain). y ^ = 0.9 means "90% sure this is a dog". The little "∈ ( 0 , 1 ) " means "lives strictly between 0 and 1".
Picture: a slider bar from 0% on the left to 100% on the right.
Why: classification losses need a belief , not a raw number, so the machine's guess is a probability. Producing these valid probabilities is the job of Softmax and Sigmoid .
Common mistake Never feed a raw score to the logarithm
A raw network score (a "logit") can be negative or huge — it is not a probability. You must squash it into ( 0 , 1 ) first (sigmoid for one class, softmax for many). Skipping this is the classic "log of a negative number → NaN" crash.
For probabilities we do not use the square. We use the logarithm, because it answers a different question: "how surprised should I be?" Before anything else we must pin down its base .
e , exp , and the natural logarithm ln
e ≈ 2.718 is a special constant. The natural logarithm ln ( x ) is "the logarithm with base e ", and exp ( x ) = e x is its exact opposite: ln and exp undo each other, so ln ( e x ) = x .
Picture: exp blows small numbers up; ln shrinks them back down.
Why: softmax uses exp to turn raw scores into positive numbers before normalising, and every loss on the parent note uses ln to measure surprise.
log " in ML always means "ln "
In machine learning the bare symbol log always means the natural log ln (base e ), never base 10. Throughout this vault, read every log as ln . We say "logarithm" for the general idea but the base is fixed at e .
− ln , with the minus sign
ln of a probability is always negative or zero (since probabilities are ≤ 1 ). We want loss to be a positive "badness" score, so we flip the sign: surprise = − ln ( y ^ ) . Now:
Confident and right (y ^ ≈ 1 ): loss ≈ 0 .
Confident and wrong (y ^ ≈ 0 ): loss → + ∞ .
This savage punishment of confident-wrong answers is exactly what cross-entropy is built from.
Three last pieces of notation let the compact formulas on the parent note make sense.
Definition The class index
k and the count K
When there are several categories, K is how many classes there are (e.g. K = 3 for cat/dog/bird), and k is a counter over classes : k = 1 , 2 , … , K , just like i counted examples. So y ^ k is "the predicted probability of class k " and y k is "the truth for class k ".
Picture: K numbered boxes; k is a finger pointing at box number k .
Definition One-hot vector
The truth over K classes is written as a list of K numbers where the correct class is 1 and all others are 0 . For "class 1 out of 3": y = [ 1 , 0 , 0 ] , so y 1 = 1 and y 2 = y 3 = 0 .
Picture: a row of light switches, exactly one flipped ON.
θ
θ (Greek "theta") is a stand-in for all the network's tunable numbers (its weights). Changing θ changes every y ^ .
Picture: a wall of dials the network can turn.
arg max and arg min
arg max θ f ( θ ) means "the value of θ that makes f largest ". arg min is the same for smallest . The parent note flips a "make-probability-biggest" problem into a "make-loss-smallest" problem — that sign flip is why maximising likelihood equals minimising loss.
Why: training is literally an arg min : find the dial settings that make the loss as small as possible. The machine that turns the dials is Gradient Descent , and the tool that computes which way to turn them is Backpropagation .
Read this map as "which small idea you must own before the arrow's target makes sense" . It restates, in one glance, the exact notation chain of this page: the two dots (y , y ^ ) give an error, the square turns it into MSE; probabilities plus − ln plus the one-hot label give cross-entropy; and θ with arg min turns either loss into training.
prediction y-hat and truth y
error gap y minus y-hat (sec 0)
square makes a bowl (sec 2)
index i and sum sigma (sec 1)
average one over n (sec 1)
probability in zero to one (sec 3)
natural log ln equals surprise (sec 4)
minus ln is badness (sec 4)
one-hot label and index k (sec 5)
argmin find best dials (sec 6)
Test yourself — cover the right side and answer out loud.
What does the hat in y ^ always mean? "The machine's guess of" — a prediction.
What is the error between truth and prediction? The gap y − y ^ .
In ∑ i = 1 n , what do the bottom and top numbers mean? Where the counter i starts (1 ) and where it stops (n ).
How do you turn a sum of n numbers into an average? Multiply by n 1 (sum then divide).
Give two reasons MSE squares the error. To remove the sign, and to punish big errors much harder.
What range must a probability live in? Strictly between 0 and 1.
When ML writes "log ", which base does it mean? Natural log ln , base e .
What is ln ( 1 ) , and what does that represent? 0 — zero surprise at a certain, correct guess.
What happens to ln ( x ) as x → 0 ? It plunges to − ∞ (infinite surprise).
Why do we put a minus sign in − ln y ^ ? Log of a probability is negative; the minus makes loss a positive "badness".
What do k and K count in cross-entropy? k counts classes from 1 to K ; K is the number of classes.
In a one-hot label, how many entries are 1? Exactly one — the correct class.
Why does − ∑ k = 1 K y k log y ^ k collapse to one term? The zeros in the one-hot label kill every non-true class.
Expand − log [ y ^ y ( 1 − y ^ ) 1 − y ] . − [ y log y ^ + ( 1 − y ) log ( 1 − y ^ )] — binary cross-entropy.
What does θ stand for? All the network's tunable weights (its dials).
What does arg min θ L ask for? The dial settings that make the loss smallest.
Once every answer feels easy, you are ready for the parent note Loss functions - MSE, cross-entropy (index 3.1.8) , and the deeper machinery in Maximum Likelihood Estimation and Logistic Regression .