Probability Intuition for Language Models
Learn probabilities, expectation, and conditional probability $P(A|B)$ which dictates next-token generation.
G-Eval Rubric Weights:
🎓 Learning objectives
- •Understand basic probability values (0.0 to 1.0)
- •Explain conditional probability and Bayes' Theorem
- •Calculate expected value from a set of probabilities
What is it?
[AI Engineering Prerequisite] Probability measures the likelihood of an event occurring, scaled between 0 (impossible) and 1 (certain). This isn't abstract math for AI Engineers — it IS how an LLM works: at every generation step, the model computes a full probability distribution over its entire vocabulary via softmax, then samples (or greedily picks) the next token from that distribution. Concepts like conditional probability, Bayes' theorem, and cross-entropy aren't just prerequisites to memorize — they're the literal mechanism behind next-token prediction, training loss, and model evaluation covered throughout this curriculum.
Why it exists
Language is non-deterministic. When predicting what word comes next, there are multiple options, each with a specific probability.
Problem it solves
Solves the challenge of generating natural, diverse text rather than printing the exact same rigid sentences.
Intuition
If you see "The sky is...", the probability of "blue" is high, while the probability of "banana" is nearly zero.
Analogy
Generating a word is like drawing colored marbles from a bag. If 8 out of 10 marbles are blue, you have an 80% chance of pulling a blue marble.
Technical explanation
Language models compute conditional probability $P(T_n | T_1, T_2, ..., T_{n-1})$. The outputs of the network are logits, converted to probabilities via the Softmax function: $sigma(z)_i = rac{e^{z_i}}{sum e^{z_j}}$.
Architecture
A probability model consists of sample spaces, probability distributions (such as Categorical distribution for tokens), and scaling functions.
Workflow
- Feed inputs -> 2. Compute token logits -> 3. Convert logits to probabilities -> 4. Sample next token.
Example
probs = {"Paris": 0.9, "London": 0.08, "Banana": 0.02}
expected score calculation example
score = (1 * 0.9) + (2 * 0.08) + (5 * 0.02) # 1.16
Real-world usage
Using expected value formulas in G-Eval to compute continuous scores for summarization quality.
Trade-offs
High temperature increases output diversity but decreases logical accuracy.
Visual explanation
Conditional probability chain: P("Paris" | "The capital of France is") = 0.95 P("blue" | "The capital of France is") = 0.0001
Advantages
- —
Enables creative, human-like outputs
- —
Allows adjusting temperature parameters to dial variance up or down
Disadvantages
- —
Can lead to hallucinations when low-probability tokens are sampled
Common mistakes
- —
Assuming all model outputs are deterministic
- —
Forgetting that probabilities must sum to exactly 1.0
🎤 Interview questions
How does the Softmax function turn arbitrary raw neural outputs (logits) into a valid probability distribution?
📂 Subtopics
Probability Fundamentals: Events, Distributions and Joint/Conditional/Marginal Probability
The basic vocabulary of probability — events, distributions, and the three ways of asking 'how likely' (joint, conditional, marginal) — that every later ML idea builds on.
~12 min
Bayes' Theorem: Prior, Likelihood and Posterior
Bayes' theorem is a formula for updating a belief once you see new evidence — turning 'how likely is the evidence given my belief' into 'how likely is my belief given the evidence.'
~13 min
Information Theory Basics: Entropy, Cross-Entropy and KL Divergence
Entropy measures how 'surprising' a distribution is on average; cross-entropy measures how well a predicted distribution matches the true one — and it's the actual loss function used to train every LLM.
~14 min
Probability in LLMs: Next-Token Prediction, Softmax and Perplexity
An LLM is, at its core, a probability machine: softmax turns raw scores into a valid next-token distribution, and perplexity turns that distribution's quality into one human-readable number.
~13 min