Loss Functions: Softmax, Cross-Entropy & Numerical Stability
How do unconstrained scalar outputs get converted into calibrated probability distributions, and why does categorical cross-entropy provide the optimal loss surface for classification?
How this lesson unfolds.
Begin with How does the Softmax exponential max-trick stabilize numerical computation, and why is cross-entropy the optimal loss for classification?. Follow the visual diagrams to build an intuitive, mathematically grounded mental model of loss functions: softmax probabilities & categorical cross-entropy.
How does the Softmax function transform unconstrained real-valued logits into a valid probability distribution on the simplex?
Imagine an auction where three bidders shout out bids in completely arbitrary units: Bidder 1 shouts +5, Bidder 2 shouts -2, and Bidder 3 shouts 0. You cannot calculate percentages directly because Bidder 2 has a negative score, and probabilities can never be negative. To solve this, you pass every bid through an exponential megaphone (e^z): negative bids turn into tiny positive decimal fractions (e^(−2) ≈ 0.135), zero turns into 1.0 (e⁰ = 1.0), and high bids amplify into massive numbers (e⁵ ≈ 148.4). Then, you divide each megaphone score by the total sum of all megaphone scores. Now, every bidder owns a clean percentage of the pie, all scores are strictly positive, and they add up to exactly 100%.
- $$Softmax exponentiates raw logits to guarantee non-negativity and normalizes by their sum, mapping vectors $\mathbb{R}^K$ onto the probability simplex $\Delta^{K-1}$.$$
- Learning goalExplain how the Softmax function maps unconstrained real-valued logits R^K onto the probability simplex Δ^(K-1).
- Helpful foundationsNatural exponential function e^x · Probability simplex definition
- Common trapBelieving that Softmax changes the rank ordering of logits. Because f(x) = e^x is strictly monotonically increasing, Softmax preserves the exact relative ranking of all input logits.
- Next connectionNext, derive the Numerical Max-Trick proof and floating-point overflow prevention in Part B.
More context & mechanics
The Softmax function acts as a differentiable categorical normalizer:
- The Unconstrained Logit Space:
A neural network's final linear layer produces a vector of raw logits z = [z₁, z₂, ṡ, z_K] ∈ R^K, where entries can be negative, zero, or arbitrarily large.
- The Positivity Guarantee (Exponentiation):
Because the base of the natural exponential e > 0, exponentiating any real number zᵢ ∈ R strictly produces a positive quantity:
e^(zᵢ) > 0 (∀ zᵢ ∈ R)
This guarantees that negative logits never produce invalid negative probabilities.
- The Sum-to-One Normalization (Probability Simplex):
Dividing each exponentiated term by the partition sum ∑_(j=1)^K e^(zⱼ) enforces the probability simplex constraint:
P(y = i | z) = (e^(zᵢ)) / (∑_(j=1)^K e^(zⱼ))
Where ∑_(i=1)^K P(y = i | z) = 1.0 and P(y = i | z) ∈ (0, 1).
Softmax is the final layer in all multi-class classification networks and the core weighting mechanism in self-attention matrices (A = softmax(Q K^T / √(dₖ))).
The mathematical formula of Softmax originates in statistical mechanics (Ludwig Boltzmann, 1868), where it describes the Maxwell-Boltzmann distribution of energy states in a gas. John S. Bridle adapted it to neural networks in 1989 for multi-class classification.
- Exponentiate to make positive; divide to make sum to one: The two-stroke engine of Softmax.
- Logits to the simplex: Softmax projects unconstrained real space into a valid probability manifold.
How do we prove that subtracting max(z) from logits leaves Softmax probabilities invariant while preventing floating-point overflow?
Think of measuring the heights of people standing on the observation deck of the Empire State Building (altitude: 1,250 feet). If you measure their height relative to sea level, an 800-foot-tall radar mast and a 6-foot human both register astronomical numbers, risking overflowing your surveyor's digital counter. If you instead set your reference zero right at the highest point of the observation deck (max), all measurements become zero or negative numbers: the highest point is 0 feet, and the humans stand at -6 feet. The relative height difference between two people is completely unaffected, but your surveyor's tool never explodes.
- $$Subtracting $c = \max(z)$ from all logits shifts the largest exponent to $e^0 = 1.0$, algebraically canceling in numerator and denominator while preventing IEEE 754 float overflow.$$
- Learning goalDerive the algebraic proof of the Numerical Max-Trick (e^(−c) cancellation) and trace stable Softmax evaluation on extreme logits.
- Helpful foundationsSoftmax normalization formula · IEEE 754 floating-point overflow limits
- Common trapAssuming that subtracting max(z) shifts the resulting probability distribution. Because e^(−c) scales both numerator and denominator identically, the resulting probabilities are 100% mathematically invariant.
- Next connectionNext, evaluate how cross-entropy loss scores these predicted softmax probabilities against one-hot targets in Screen 2.
More context & mechanics
#### 1. The Catastrophic Overflow Trap (IEEE 754 FP32)
In standard 32-bit floating point arithmetic (FP32), the maximum representable value is:
MAX_(FP32) ≈ 3.4028 × 10^(38)
Because e^(88.7) ≈ 3.4028 × 10^(38), any logit zᵢ > 88.7 causes e^(zᵢ) to overflow to `+inf`!
When calculating Softmax:
(e^(1000)) / (∑ e^(zⱼ)) = inf/inf = NaN (Not a Number)
A single large logit instantly corrupts the entire neural network with NaNs, crashing training permanently.
Let c = max_(1 ≤ j ≤ K) zⱼ. We subtract c from every logit before exponentiating:
p̃ᵢ = (e^(zᵢ - c)) / (∑_(j=1)^K e^(zⱼ - c))
Using the algebraic exponent rule e^(a - b) = e^a · e^(−b):
p̃ᵢ = (e^(zᵢ) · e^(−c)) / (∑_(j=1)^K (e^(zⱼ) · e^(−c))) = (e^(−c) · e^(zᵢ)) / (e^(−c) · ∑_(j=1)^K e^(zⱼ)) = (e^(zᵢ)) / (∑_(j=1)^K e^(zⱼ)) = pᵢ
The scalar e^(−c) factors out identically from both numerator and denominator!
Stability Guarantee: Because zᵢ - c ≤ 0 for all i, the largest exponent is e⁰ = 1.0, and all other terms are e^(≤ 0) ∈ (0, 1]. Overflow is mathematically impossible! \blacksquare
Given extreme logits z = [1000.0, 1001.0, 1002.0]:
- Naive Softmax:
e^(1000) = inf, e^(1001) = inf, e^(1002) = inf ⟹ inf / inf = NaN.
- Numerical Max-Trick:
c = max(z) = 1002.0.
Shifted logits: z̃ = z - c = [1000 - 1002, 1001 - 1002, 1002 - 1002] = [-2.0, -1.0, 0.0].
Exponentials:
- e^(−2.0) ≈ 0.135335
- e^(−1.0) ≈ 0.367879
- e^(0.0) = 1.000000
Sum: d = 0.135335 + 0.367879 + 1.000000 = 1.503214.
Probabilities:
- p₁ = 0.135335 / 1.503214 = 0.0900
- p₂ = 0.367879 / 1.503214 = 0.2447
- p₃ = 1.000000 / 1.503214 = 0.6653
(Check: 0.0900 + 0.2447 + 0.6653 = 1.0000).
Clean, stable probabilities computed without a single NaN.
In NumPy and PyTorch, this is the universal production implementation:
```python
def stable_softmax(z):
exp_z = np.exp(z - np.max(z, axis=-1, keepdims=True))
return exp_z / np.sum(exp_z, axis=-1, keepdims=True)
```
The coordinate shift invariance of Softmax is a classic mathematical property of projective geometry and Gibbs distributions. Its adoption as the standard "Max-Trick" in scientific computing was codified by early LAPACK and SciPy developers in the 1990s.
- Subtract the max before you exp: The golden rule of numerical deep learning.
- e⁰ = 1.0 is the ceiling: Shift so the maximum exponent is always 1; overflow becomes impossible.
How does categorical cross-entropy loss measure the information discrepancy between predicted Softmax probabilities and one-hot ground truth?
Imagine you are taking a multiple-choice driving test with 4 options (A, B, C, D). Question 1 asks: 'What should you do at a red light?'. The correct ground-truth answer is Option B: 'Stop' (y = [0, 1, 0, 0]). If you answer Option B with 95% confidence, your instructor gives you a tiny error score (-ln(0.95) ≈ 0.05). If you are completely indecisive and give all 4 choices equal 25% odds, your error score rises to 1.38. If you arrogantly tell the instructor there is a 99% chance the answer is 'Accelerate', the instructor fails you with an astronomical penalty (-ln(0.001) ≈ 6.9). Cross-entropy grades your confidence on the truth.
- Learning goalFormulate categorical cross-entropy loss for one-hot targets and illustrate its logarithmic penalty dynamics as predicted probability approaches zero.
- Helpful foundationsSoftmax probability outputs · Natural logarithm properties
- Common trapBelieving that cross-entropy directly calculates penalties for wrong classes. For one-hot targets, cross-entropy only evaluates the probability of the correct class; the wrong classes are penalized indirectly because all probabilities must sum to 1.0.
- Next connectionNext, derive the sample loss, batch mean, and the 10^(-7) clipping boundary in Part B.
More context & mechanics
Categorical Cross-Entropy (CCE) is the gold standard loss function for multi-class classification:
- The Information-Theoretic Definition:
Given true distribution y and predicted distribution ŷ:
H(y, ŷ) = - ∑_(k=1)^K yₖ ln(ŷₖ)
- One-Hot Simplification:
In single-label classification, the target is a one-hot vector where y_c = 1 for the correct class c, and yₖ = 0 for all k ≠ c. The sum collapses to a single term:
Lᵢ = - ln(ŷ_(i, c))
The loss depends exclusively on the probability assigned to the true class.
- The Penalty Curve Dynamics:
- Perfect prediction (ŷ_c = 1.0): L = -ln(1.0) = 0.0.
- Confident error (ŷ_c → 0): L = -ln(0) → +∞.
The logarithmic curve provides an infinite penalty wall against confident mistakes, forcing gradients to aggressively correct erroneous weights.
Categorical cross-entropy powers image classifiers (ResNet on ImageNet-1k), speech recognition models, and every foundation LLM. In PyTorch, `nn.CrossEntropyLoss` combines Softmax and Cross-Entropy into a single numerically stable module.
The cross-entropy concept was developed by Claude Shannon in his 1948 paper establishing Information Theory. In 1951, Solomon Kullback and Richard Leibler formalized the KL divergence, proving that minimizing cross-entropy is mathematically identical to minimizing relative entropy between models and empirical truth.
- Loss is negative log of the correct class: Forget all other classes; find the true label and take -ln(p).
- Zero loss requires 100\% confidence: You only achieve zero loss when your predicted probability is exactly 1.0.
How do we compute the sample loss, batch mean, and implement the 10^(-7) clipping boundary to prevent ln(0) underflow?
Think of a digital scale that measures weights in grams. If you place a feather so light that the scale registers 0.0000000 grams, an old digital program that divides by weight crashes with a divide-by-zero error. To safeguard the software, engineers program a tiny threshold: if the weight is less than 0.0000001 grams, the scale reports 0.0000001 grams instead of zero. The 10^(-7) clipping shield is that safety buffer: it prevents the logarithm from attempting to evaluate ln(0) = -∞, keeping training rock-solid.
- $$Sample loss $L_i = -\ln(\text{clip}(\hat{y}_{i,c}, 10^{-7}, 1 - 10^{-7}))$ prevents $\ln(0) = -\infty$ crashes; batch loss computes the arithmetic mean $\frac{1}{N} \sum L_i$.$$
- Learning goalDerive the mathematical formulation of categorical cross-entropy with a 10^(-7) clipping boundary and trace numerical batch mean loss calculations.
- Helpful foundationsCategorical cross-entropy concepts · Natural logarithm limits and NumPy indexing
- Common trapAttempting to clip only at the lower bound (1e-7). You must also clip at the upper bound (1 - 1e-7) to prevent symmetrical numerical instability in binary cross-entropy formulations.
- Next connectionNext, discover how partial derivatives and gradient vectors guide loss minimization in Chapter 9 Screen 3.
More context & mechanics
#### 1. The ln(0) Catastrophic Underflow Trap
If a neural network assigns a predicted probability of exactly ŷ_(i, c) = 0.0 to the correct class (due to floating-point rounding), evaluating the loss triggers an unrecoverable mathematical error:
Lᵢ = -ln(0.0) = -(-∞) = +∞
Subsequent gradient calculations produce NaNs:
(∂ L) / (∂ z) = NaN
Training crashes instantly.
To safeguard numerical stability, predicted probabilities ŷ are clipped to a closed interval [ε, 1 - ε] (typically ε = 10^(-7)):
ŷ_(clipped) = clip(ŷ, 10^(-7), 1 - 10^(-7))
- Even if the model outputs ŷ = 0.0, the clipped value is 10^(-7), yielding a safe finite loss:
L_(max) = -ln(10^(-7)) = -(-16.11809565) ≈ 16.118
- The maximum possible loss is strictly bounded, preventing gradient explosions.
For a mini-batch of N samples, the total batch loss is the arithmetic mean:
L_(batch) = 1/N ∑_(i=1)^N Lᵢ = - 1/N ∑_(i=1)^N ln(ŷ_(i, cᵢ))
Given a batch of N = 3 samples across K = 3 classes:
- Target indices: y = [0, 1, 1] (Classes: Cat, Dog, Dog).
- Predicted probabilities:
ŷ =
0.70 & 0.20 & 0.10 \
0.10 & 0.50 & 0.40 \
0.02 & 0.90 & 0.08
Step 1: Extract Correct Class Probabilities:
- Sample 1 (c₁ = 0): ŷ_(1, 0) = 0.70
- Sample 2 (c₂ = 1): ŷ_(2, 1) = 0.50
- Sample 3 (c₃ = 1): ŷ_(3, 1) = 0.90
Step 2: Compute Sample Losses (with 10^(-7) clipping):
- L₁ = -ln(0.70) ≈ -(-0.3567) = 0.3567
- L₂ = -ln(0.50) ≈ -(-0.6931) = 0.6931
- L₃ = -ln(0.90) ≈ -(-0.1054) = 0.1054
Step 3: Compute Batch Mean:
L_(batch) = (0.3567 + 0.6931 + 0.1054) / (3) = (1.1552) / (3) ≈ 0.3851
In NumPy, this is implemented as:
```python
y_pred_clipped = np.clip(y_pred, 1e-7, 1.0 - 1e-7)
correct_confidences = y_pred_clipped[range(len(y_pred)), y_true]
negative_log_likelihoods = -np.log(correct_confidences)
loss = np.mean(negative_log_likelihoods)
```
The epsilon clipping technique was popularized in early machine learning libraries like scikit-learn and Keras (circa 2015) to prevent numerical divergence in binary and categorical cross-entropy implementations.
- Clip between 1e-7 and 1 - 1e-7: Never let the logarithm touch zero.
- Average across the batch: The batch loss is the mean of the individual sample penalties.
How does loss code and edge cases operate mathematically within the overall Loss Functions: Softmax Probabilities & Categorical Cross-Entropy?
What happens if the model assigns a probability of exactly 0.0 to the correct answer? The computer tries to calculate ln(0), which is negative infinity (-inf), which turns all your gradients into NaN (Not a Number), crashing your entire program! Clipping values slightly above 0 saves the model.
- $$\mathbf{y} = f(\mathbf{X} \mathbf{W} + \mathbf{b})$$
- Learning goalImplement epsilon clipping on probability tensors and audit numerical edge cases under extreme model miscalibration.
- Helpful foundationsMatrix multiplication and tensor broadcasting · Deep Learning Textbook (Goodfellow, Bengio & Courville, MIT Press 2016) · Linear Algebra and Learning from Data (Gilbert Strang, MIT 2019)
- Common trapClipping only the lower bound; clipping both lower and upper bounds ([eps, 1-eps]) prevents numerical issues in binary cross-entropy where (1 - p) is evaluated.
- Next connectionProceed to Chapter 09 to master optimization foundations, gradients, and loss surface landscapes.
More context & mechanics
To prevent numerical divergence when p → 0 or p → 1, probabilities are clipped to a safe epsilon range [ε, 1 - ε]:
p_(safe) = clip(p, 10^(-7), 1 - 10^(-7))
L = -ln(p_(safe))
This bounds maximum scalar loss to -ln(10^(-7)) ≈ 16.118, preventing catastrophic floating-point NaNs.
Standard defensive engineering inside PyTorch, Keras, and scikit-learn loss routines.
Developed through decades of numerical analysis in floating-point IEEE-754 arithmetic standards (Kahan, 1985).
Clip with epsilon to banish infinity: never let probability touch exact zero.
Why does the binary entropy function H_b(p) form a symmetric concave arch peaking at exactly p = 0.5?
Think of flipping a coin. If the coin is weighted with two heads (p = 1.0), you know the result before you flip: there is zero drama, zero suspense, zero uncertainty (0 bits). If the coin has two tails (p = 0.0), the uncertainty is also zero. But if the coin is perfectly fair (p = 0.50), your suspense is maximized: you have no clue which side will land face up. That fair coin carries exactly 1 full bit of pure uncertainty.
- $$Plot H_b(p) = -p log_2 p - (1-p) log_2(1-p), demonstrating zero entropy at certainty p in {0, 1} and maximum 1 bit of entropy at p = 0.5.$$
- Learning goalDerive the stationary point and strict concavity of the binary entropy function, verifying maximum uncertainty at p = 0.5.
- Helpful foundationsUnivariate calculus limits · Bernoulli trials · Elements of Information Theory (Cover & Thomas, 2006)
- Common trapThinking a 90% biased coin has high uncertainty; a 90/10 coin has Hb(0.9) = 0.469 bits, meaning over half of the uncertainty has already disappeared.
- Next connectionWhat happens when you encode data using a probability model that doesn't match the true distribution? You pay the transmission penalty of Cross-Entropy.
More context & mechanics
For a Bernoulli random variable with parameter p = P(X = 1):
H_b(p) = -p log₂ p - (1 - p) log₂(1 - p)
Analyzing its calculus and geometry:
- Boundary Limits:
lim_(p → 0^+) p log₂ p = 0, lim_(p → 1^-) (1 - p) log₂(1 - p) = 0 ⟹ H_b(0) = H_b(1) = 0
- First Derivative (Slope):
(d H_b) / (dp) = -log₂ p - (1) / (ln 2) + log₂(1 - p) + (1) / (ln 2) = log₂( (1 - p) / (p) )
Setting (d H_b) / (dp) = 0:
(1 - p) / (p) = 1 ⟹ 1 - p = p ⟹ p = 0.5
- Second Derivative (Strict Concavity):
(d² H_b) / (dp²) = -(1) / (ln 2) ( 1/p + (1) / (1 - p) ) = -(1) / (p(1 - p) ln 2) < 0, ∀ p ∈ (0, 1)
Since the second derivative is strictly negative everywhere, H_b(p) is strictly concave, and p = 0.5 is the unique global maximum:
H_b(0.5) = -0.5 log₂(0.5) - 0.5 log₂(0.5) = 0.5(1) + 0.5(1) = 1.0 bit
Binary cross-entropy loss L_(BCE) = -y log p - (1-y) log(1-p) in logistic regression and binary classification networks directly reflects this curve.
Claude Shannon plotted this exact symmetric arch as Figure 7 in his 1948 Bell Labs paper, introducing the universal graphic icon of information theory.
- Zero at the edges; 1 bit at the 50/50 peak.
- A fair coin has maximum uncertainty.
How does cross-entropy quantify the expected bit-length per message when encoding reality using an imperfect model codebook?
Imagine you are a telegraph operator in a city where 90% of all messages are about 'rain' and 10% are about 'sunshine'. An optimal codebook gives 'rain' a short 1-tap code (`.`) and 'sunshine' a longer 4-tap code (`----`). But suppose you mistakenly use a codebook designed for the Sahara Desert, where 'sunshine' gets the short 1-tap code and 'rain' gets the long 4-tap code. Sending daily weather reports from your rainy city now requires twice as many telegraph taps! Cross-entropy measures that total average tap cost: the penalty of using the wrong model codebook.
- $$Formulate cross-entropy H(p, q) = -sum p_i log q_i as the expected code length when reality follows p but the compression codebook is optimized for q.$$
- Learning goalDecompose cross-entropy into intrinsic entropy and KL divergence and prove that H(p, q) >= H(p).
- Helpful foundationsShannon entropy · On Information and Sufficiency (Kullback & Leibler, 1951)
- Common trapBelieving cross-entropy can be driven to absolute zero on real text; human language has intrinsic entropy H(p) > 0, so cross-entropy loss can never drop below the irreducible entropy of human speech.
- Next connectionWhat is that excess penalty term D_KL(p || q)? We examine Kullback-Leibler Divergence in depth.
More context & mechanics
Let p be the true target distribution (reality) and q be the predicted distribution (the model's codebook).
Cross-entropy is the expected surprisal under p using code lengths -log₂ qᵢ:
H(p, q) = E_(X ~ p)[-log₂ q(X)] = -∑_(i=1)^K pᵢ log₂ qᵢ
We decompose cross-entropy into true entropy plus excess penalty:
H(p, q) = -∑_(i=1)^K pᵢ log₂ qᵢ = -∑_(i=1)^K pᵢ log₂ pᵢ + ∑_(i=1)^K pᵢ log₂( pᵢ/qᵢ ) = H(p) + D_(KL)(p ∥ q)
Where:
- H(p) is the irreducible intrinsic entropy of reality (noise floor).
- D_(KL)(p ∥ q) ≥ 0 is the Kullback-Leibler divergence (the penalty for using model q).
By Gibbs' inequality, H(p, q) ≥ H(p), with equality if and only if q = p everywhere.
Cross-entropy is the universal loss function for classification and language generation. Minimizing H(p, q) during SGD pushes model q to match data distribution p perfectly, driving D_(KL)(p ∥ q) → 0.
Solomon Kullback and Richard Leibler formalized the relative cross-entropy divergence in 1951, providing the statistical bridge between Shannon's information theory and Fisher's hypothesis testing.
- Cross-entropy = True Entropy + KL Divergence.
- The cost of reality encoded through an imperfect model.
What is the precise mathematical difference between row collapse along axis=0 and column collapse along axis=1 in NumPy?
Imagine a classroom gradebook where rows are students and columns are test questions. If you sum along `axis=0`, you collapse the rows (squashing all students together) to find the average difficulty of each test question: you get a vector of question scores. If you sum along `axis=1`, you collapse the columns (squashing all tests together for each student) to calculate each student's final semester grade: you get a vector of student totals. In neural networks: `axis=0` calculates batch bias gradients; `axis=1` calculates softmax normalizations.
- $$Distinguish axis=0 reductions (collapsing across batch samples to produce feature summaries) from axis=1 reductions (collapsing across features per sample).$$
- Learning goalDifferentiate and implement axis=0 and axis=1 reductions in NumPy and map them to their corresponding deep learning operations.
- Helpful foundations2D array indexing and NumPy axes · Guide to NumPy (Oliphant, 2006)
- Common trapThinking axis=0 means 'operate along the row'; axis=0 means collapse the axis of rows, leaving only columns behind.
- Next connectionBefore computing gradients for deep layers, how does a tangent line define the instantaneous slope of a curve? We examine gradients and tangent lines.
More context & mechanics
For a 2D tensor A ∈ R^(M × N) with row index i and column index j:
- Row Collapse (`axis=0`):
Collapses along vertical rows:
s_(col) = ∑_(i=1)^M A_(i, j) ∈ R^N
- Shape: (M, N) →(i, j) } (sum across class columns)
Understanding axis reductions prevents catastrophic orientation errors when accumulating distributed gradients across GPUs (`all_reduce`).
The axis reduction conventions (`axis=0, 1, ...`) were established in APL (A Programming Language) by Kenneth Iverson in 1962 and adapted into NumPy and PyTorch.
- axis=0 squashes the rows (downward collapse).
- axis=1 squashes the columns (horizontal collapse).
What is the mathematical foundation and geometric intuition of Logits to Simplex: Projecting Real Space onto Probabilities?
Understand Logits to Simplex: Projecting Real Space onto Probabilities visually: Softmax normalizes an unconstrained 3D vector onto a 2D probability manifold.. Every transformation preserves core structural invariants while mapping coordinate spaces.
- Learning goalMaster the algebraic and geometric derivation of Logits to Simplex: Projecting Real Space onto Probabilities.
- Helpful foundationsLinear Algebra Fundamentals · Matrix Transformations · Vector Spaces
- Common trapAssuming Logits to Simplex: Projecting Real Space onto Probabilities is merely a computational trick rather than an invariant spatial law.
- Next connectionConnects to upstream spectral theory and downstream tensor operations.
More context & mechanics
A 3D perspective geometric diagram on clean ivory linen (#f7f6ee) with an 8px border.
Top section: Title in technical grotesque: "Logits to Simplex: Projecting Real Space onto Probabilities". Subtitle: "Softmax normalizes an unconstrained 3D vector onto a 2D probability manifold."
Middle section: A clean 3D coordinate frame (axes z₁, z₂, z₃).
Show the standard 2-simplex triangle Δ² lying on the plane z₁ + z₂ + z₃ = 1 in the positive octant.
Draw an unconstrained 3D logit point z = [3.0, 1.0, 0.0].
Draw a projection ray from z down onto point p = [0.84, 0.11, 0.05] on the simplex triangle surface.
Show temperature effect: As T -> ∞, point p slides toward the exact center of the triangle (maximum entropy uniform point [1/3, 1/3, 1/3]). As T -> 0, point p snaps to the closest vertex (1, 0, 0).
Bottom section: Formula card: "pᵢ = (e^(zᵢ / T)) / (∑ e^(zⱼ / T)) ⟹ Softmax is an exponential map followed by normalization onto the simplex manifold."
Crisp 3D coordinate lines, airy layout, elegant mathematical styling.
This principle is foundational across deep learning optimization, high-dimensional representation, and modern LLM architectures.
"Logits to Simplex: Projecting Real Space onto Probabilities: Invariance and structure determine stability under spatial and numerical transformations."
How does Logits to Simplex: Projecting Real Space onto Class Probabilities operate mathematically at scale?
A clean 3D isometric coordinate plane:
- $$Subtitle: "Softmax non-linearly maps unbounded scores R^K onto the bounded probability simplex \Delta^{K-1}."$$
- Learning goalMaster the algebraic and geometric derivation of Logits to Simplex: Projecting Real Space onto Class Probabilities.
- Helpful foundationsFoundations of Neural Networks From Scratch · Coordinate Invariance & Geometric Projections · Goodfellow, Bengio, and Courville (2016), Deep Learning, MIT Press
- Common trapAssuming Logits to Simplex: Projecting Real Space onto Class Probabilities is an arbitrary computational trick rather than an invariant spatial law.
- Next connectionConnects upstream foundational lemmas to modern high-dimensional computational systems.
More context & mechanics
A geometric probability projection diagram in square 1:1 format on warm cream parchment (#fcf0db) with a sepia frame.
Top section: Title in navy serif: "Logits to Simplex: Projecting Real Space onto Probabilities". Subtitle: "Softmax non-linearly maps unbounded scores R^K onto the bounded probability simplex Δ^(K-1)."
Middle section: A clean 3D isometric coordinate plane:
Show the unbounded real score space where raw logits z = [z₁, z₂, z₃]^T can range from -∞ to +∞.
Show the triangular probability simplex Δ² slicing through the axes.
Draw three gradient vectors showing how changing logit z₁ pushes the output point toward the corner vertex [1, 0, 0] (Pure Class 1).
Annotate the translation invariance property:
"Softmax(z + c 1) = Softmax(z)".
Subtracting max(z) prevents floating-point exponential overflow without changing output probabilities!
Bottom section: Formula: "pᵢ = (e^(zᵢ - max(z))) / (∑ⱼ e^(zⱼ - max(z))). Stable Softmax guarantees numeric safety across extreme logit scales."
Pristine isometric simplex diagram, clear projection arrows, elegant square composition.
Every transformation preserves structural invariants while mapping coordinate spaces. When operating in high dimensions, numerical precision and computational efficiency require adhering strictly to canonical mathematical laws.
Formal derivation and peer-reviewed analysis:
Goodfellow, Bengio, and Courville (2016), Deep Learning, MIT Press
"Logits to Simplex: Projecting Real Space onto Class Probabilities: Invariance, symmetry, and structure govern mathematical truth across continuous and discrete domains."