How Probability Powers Artificial Intelligence
In 1913, Russian mathematician Andrey Markov sat down with Alexander Pushkin's verse novel Eugene Onegin and counted letters by hand. He studied 20,000 of them to measure how often a vowel follows a consonant and vice versa.
He was showing that the probability of the next letter depends on the current one. More than a century later, the chatbots you talk to do something with the same basic shape at vast scale: they estimate the probability of the next piece of text given what came before.
AI Doesn't Output Answers, It Outputs Probabilities
When an image classifier says "cat," it didn't decide on "cat." It calculated something like 92% cat, 6% dog, 2% fox, and reported the top choice. When a language model writes a sentence, at each step it produces a probability for every possible next token and then samples one.
That's why the same chatbot can give different answers to the same question. The randomness isn't a glitch. It's built in.
Idea 1: Conditional Probability
Almost everything in AI is a conditional probability, the probability of A given B:
P(A | B) = P(A and B) / P(B)
- P(spam | email contains "free money")
- P(tumor | this X-ray)
- P(next word = "Paris" | "The capital of France is")
The whole job of a model is to estimate these numbers well.
Idea 2: Bayes' Theorem
Bayes' theorem flips a conditional probability around:
P(A | B) = P(B | A) × P(A) / P(B)
Suppose half of all emails are spam. The phrase "free money" appears in 40% of spam emails but only 1% of legitimate ones. Given that an email contains the phrase:
P(spam | phrase) = 0.40 × 0.5 / (0.40 × 0.5 + 0.01 × 0.5)
= 0.20 / 0.205
≈ 97.6%
An Insider Reference: The Spam Filter That Changed Email
In August 2002, programmer and essayist Paul Graham published "A Plan for Spam." He described a filter that combined word probabilities with Bayes' theorem, learning from each user's own spam and legitimate mail.
He reported catching 99.5% of spam with very few false positives. The essay helped trigger a wave of Bayesian spam filters, and probabilistic filtering is still part of how email services fight junk mail.
The standard version is called naive Bayes, because it "naively" assumes each word appears independently of the others. That assumption is false, yet the method works remarkably well in practice.
Idea 3: The Base Rate Trap
Bayes' theorem also explains why AI accuracy numbers can mislead. Suppose a model detects a rare disease that affects 1% of people. It catches 90% of real cases, and it wrongly flags 9% of healthy people.
If it flags you, what's the chance you actually have the disease?
P(disease | flagged) = 0.90 × 0.01 / (0.90 × 0.01 + 0.09 × 0.99)
≈ 0.009 / 0.0981
≈ 9.2%
Only about 9%. Because healthy people vastly outnumber sick people, most positive flags are false alarms. This is the base rate fallacy, and it matters whenever AI screens for rare events like fraud or disease.
Idea 4: Language Models Predict the Next Token
A language model assigns a probability to a sequence of tokens (words or word pieces) using the chain rule of probability:
P(w₁, w₂, …, wₙ) = P(w₁) × P(w₂ | w₁) × P(w₃ | w₁, w₂) × …
Markov's approach assumed only the last letter mattered. Claude Shannon extended the idea in 1948, generating increasingly English-like text by conditioning on longer and longer context. Modern neural networks condition on thousands of previous tokens at once.
At each step, the network produces a raw score for each token in its vocabulary, and the softmax function converts scores into probabilities:
P(token i) = e^(zᵢ) / Σ e^(zⱼ)
Idea 5: Temperature
Chatbots often have a temperature setting T that divides the scores before softmax:
P(token i) = e^(zᵢ/T) / Σ e^(zⱼ/T)
With scores (2.0, 1.0, 0.1):
| Temperature | Probabilities |
|---|---|
| T = 0.5 | 0.86, 0.12, 0.02 |
| T = 1.0 | 0.66, 0.24, 0.10 |
| T = 2.0 | 0.50, 0.30, 0.19 |
Low temperature sharpens the distribution, so the model sticks with its favorite. High temperature flattens it, so output becomes more varied and surprising.
Idea 6: Training Maximizes Likelihood
How does a model learn good probabilities? It's trained to make real training text as likely as possible. In practice, that means minimizing cross-entropy loss:
Loss = −log P(actual next token)
If the model gave the true next token 70% probability, the loss is −ln(0.7) ≈ 0.36. If it gave only 10%, the loss is about 2.30. The logarithm turns products of many probabilities into sums, which are far easier to work with. Try values with the logarithm calculator.
Two Concepts Worth Knowing
Probability Distributions
A probability distribution lists every possible outcome with its probability, and the probabilities sum to 1. A language model's output at each step is a distribution over tens of thousands of possible tokens.
Calibration
A model is calibrated if, among all the times it says "80% confident," it's right about 80% of the time. Many neural networks are overconfident, and calibration methods adjust their outputs.
Quick Answer: How Is Probability Used in AI?
AI uses probability to handle uncertainty. Classifiers output probabilities for each label, spam filters apply Bayes' theorem, and language models predict a probability for every possible next token and sample from it. Models are trained by maximizing the likelihood of real data, usually by minimizing cross-entropy loss.
Try Them Yourself
- Random Number Generator: sample from a distribution yourself
- Logarithm Calculator: compute log-likelihoods
- Statistics Formulas: probability rules and Bayes' theorem
- Standard Normal Table: the most famous distribution
- Z-Score Calculator: measure how surprising a value is
- The Math Behind Neural Networks: where the scores come from
Write a short sentence, then for each word guess three alternatives and assign probabilities. You'll be doing, by hand, what a language model does for every token.