Softmax & Cross-Entropy Explained: From Logits to Loss | LLM Course #14
How does an LLM turn raw scores into probabilities, and how do we measure how wrong it was? In Lecture 14 of the LLM Masterclass: logits, the softmax function step by step, cross-entropy as surprise (minus the log of the correct word's probability), the loss curve, softmax and cross-entropy in NumPy, and how gradient descent uses this loss to train every LLM. 💻 Code for this lecture (branch lecture-14): https://github.com/programmingline/chotugpt/tree/lecture-14 Lecture 14 of 32 — LLM Masterclass · Module 2: Just enough maths ⚠️ ChotuGPT is a simplified teaching model. The scores (2.0, 1.0, 0.1) are illustrative numbers for teaching only. In this lecture: • Logits: the raw scores a model gives every word in its vocabulary • Softmax in two steps: e^score, then divide by the total (7.39, 2.72, 1.11 → 66%, 24%, 10%) • Cross-entropy = surprise = −log p(correct word), with the natural log • Worked example: correct word 'fresh' → loss 0.42; correct word 'sleepy' → loss 2.32 • The −log p curve, and why training averages the loss over every token • Softmax and cross-entropy in NumPy, plus the gradient: probabilities minus one-hot • One gradient step raises p(fresh) from 66% to 77% Chapters: 00:00 Lecture 13 quiz answer 00:14 Softmax and cross-entropy 00:27 Raw scores: logits 00:49 Like & subscribe 00:56 Softmax in two steps 01:36 Cross-entropy is surprise 01:58 Computing the loss 02:19 The loss curve 02:38 Softmax and cross-entropy in NumPy 03:05 Quiz 03:26 How the model learns from the loss 03:47 Recap & next lecture ✅ Lecture 13 quiz answer: B, opposite to the gradient, to reduce the loss. The gradient points uphill, so we step downhill. ❓ Quiz: If the model gives the correct word a probability of 1, the cross-entropy loss is… A) 0 B) 1 C) Infinity. Comment your answer. I reveal it in Lecture 15! 👍 Like, subscribe and comment your quiz answer. ⏮ Previous: Lecture 13 — How networks learn: gradient descent and backprop ⏭ Next: Lecture 15 — Tokenization and BPE Sources: I. Goodfellow, Y. Bengio and A. Courville, "Deep Learning", MIT Press 2016 (chapters 3.13 and 6.2). C. E. Shannon, "A Mathematical Theory of Communication", Bell System Technical Journal, 1948. J. S. Bridle, "Probabilistic Interpretation of Feedforward Classification Network Outputs, with Relationships to Statistical Pattern Recognition", 1990. #LLM #Softmax #CrossEntropy…more
How does an LLM turn raw scores into probabilities, and how do we measure how wrong it was? In Lecture 14 of the LLM Masterclass: logits, the softmax function step by step, cross-entropy as surprise (minus the log of the correct word's probability), the loss curve, softmax and cross-entropy in NumPy, and how gradient descent uses this loss to train every LLM. 💻 Code for this lecture (branch lecture-14): https://github.com/programmingline/chotugpt/tree/lecture-14 Lecture 14 of 32 — LLM Masterclass · Module 2: Just enough maths ⚠️ ChotuGPT is a simplified teaching model. The scores (2.0, 1.0, 0.1) are illustrative numbers for teaching only. In this lecture: • Logits: the raw scores a model gives every word in its vocabulary • Softmax in two steps: e^score, then divide by the total (7.39, 2.72, 1.11 → 66%, 24%, 10%) • Cross-entropy = surprise = −log p(correct word), with the natural log • Worked example: correct word 'fresh' → loss 0.42; correct word 'sleepy' → loss 2.32 • The −log p curve, and why training averages the loss over every token • Softmax and cross-entropy in NumPy, plus the gradient: probabilities minus one-hot • One gradient step raises p(fresh) from 66% to 77% Chapters: 00:00 Lecture 13 quiz answer 00:14 Softmax and cross-entropy 00:27 Raw scores: logits 00:49 Like & subscribe 00:56 Softmax in two steps 01:36 Cross-entropy is surprise 01:58 Computing the loss 02:19 The loss curve 02:38 Softmax and cross-entropy in NumPy 03:05 Quiz 03:26 How the model learns from the loss 03:47 Recap & next lecture ✅ Lecture 13 quiz answer: B, opposite to the gradient, to reduce the loss. The gradient points uphill, so we step downhill. ❓ Quiz: If the model gives the correct word a probability of 1, the cross-entropy loss is… A) 0 B) 1 C) Infinity. Comment your answer. I reveal it in Lecture 15! 👍 Like, subscribe and comment your quiz answer. ⏮ Previous: Lecture 13 — How networks learn: gradient descent and backprop ⏭ Next: Lecture 15 — Tokenization and BPE Sources: I. Goodfellow, Y. Bengio and A. Courville, "Deep Learning", MIT Press 2016 (chapters 3.13 and 6.2). C. E. Shannon, "A Mathematical Theory of Communication", Bell System Technical Journal, 1948. J. S. Bridle, "Probabilistic Interpretation of Feedforward Classification Network Outputs, with Relationships to Statistical Pattern Recognition", 1990. #LLM #Softmax #CrossEntropy