AI State of the Art
Math/Probability and Statistics/10 min
Section 325

Probability: Axioms, Conditional, Bayes

Listen as a podcast →

Why probability in AI?

Machine learning is fundamentally about uncertainty. When a model predicts that an image contains a cat with 92% confidence, it's expressing a probability. When a language model generates the next word, it chooses from a probability distribution over the entire vocabulary. Without probabilities, no classification, no generation, no learning.

Probabilities provide the mathematical language for reasoning about uncertainty. And in AI, uncertainty is everywhere: in noisy data, in model parameters, in predictions.

Two views of probability

The frequentist approach

Probability is the frequency of an event over a large number of repetitions. Roll a die 10,000 times and observe that 6 appears roughly 1/6 of the time. It's concrete, measurable, but limited: how do you talk about the probability of rain tomorrow? You can't "repeat" tomorrow.

The Bayesian approach

Probability is a degree of belief. You can say "I believe there's a 70% chance it will rain tomorrow" based on available information. This view is more flexible and better matches what ML models do: they update their beliefs as they see data.

In deep learning, both approaches coexist. Training by maximum likelihood is frequentist. Adding priors on weights (regularization) is Bayesian. Understanding both is essential.

Kolmogorov axioms

All of probability theory rests on three axioms, laid down by Andrey Kolmogorov in 1933. They are simple but fundamental.

Axiom 1: non-negativity

For any event AA, the probability is positive or zero:

P(A)≥0P(A) \geq 0

A negative probability makes no sense. A model that predicts a probability of −0.3-0.3 for a class has a problem.

Axiom 2: normalization

The probability of the entire sample space equals 1:

P(Ω)=1P(\Omega) = 1

Something must happen. In classification, the sum of probabilities across all classes must equal 1. That's exactly what the softmax function does at the output of a network.

Axiom 3: additivity

For two mutually exclusive events (that cannot occur at the same time):

P(A∪B)=P(A)+P(B)P(A \cup B) = P(A) + P(B)

If AA = "the model predicts cat" and BB = "the model predicts dog", and the model can only predict one class, then P(cat or dog)=P(cat)+P(dog)P(\text{cat or dog}) = P(\text{cat}) + P(\text{dog}).

All rules of probability calculation follow from these three axioms.

Conditional probability

The intuition: "given that..."

Conditional probability P(A∣B)P(A|B) answers the question: "What is the probability of AA, knowing that BB has occurred?"

P(A∣B)=P(A∩B)P(B)P(A|B) = \frac{P(A \cap B)}{P(B)}

Think of it as a filter. Among all cases where BB is true, what fraction also satisfies AA?

A table of 20 faces split by two criteria (bearded or not, astigmatic or not), followed by two derivations that count cells: P(A given B) times P(B) and P(B given A) times P(A) yield the same quantity, which gives Bayes formula.
Conditioning means restricting the count to a sub-population. Across 20 people crossed by two criteria, P(A given B) reads off as the fraction of column B that also sits in row A. Doing the same count both ways leads straight to Bayes theorem in the next section.Source : Wikimedia Commons, Bayes theorem visualisation

Concrete example

Imagine a spam classifier. We have:

  • P(spam)=0.3P(\text{spam}) = 0.3 (30% of emails are spam)
  • P(contains "free")=0.1P(\text{contains "free"}) = 0.1
  • P(contains "free"∩spam)=0.08P(\text{contains "free"} \cap \text{spam}) = 0.08

Then P(spam∣contains "free")=0.080.1=0.8P(\text{spam} | \text{contains "free"}) = \frac{0.08}{0.1} = 0.8. Knowing that an email contains the word "free", the probability that it's spam jumps to 80%.

In ML: everywhere

All autoregressive modeling of language models relies on conditioning:

P(x1,x2,…,xn)=P(x1)⋅P(x2∣x1)⋅P(x3∣x1,x2)⋯P(xn∣x1,…,xn−1)P(x_1, x_2, \ldots, x_n) = P(x_1) \cdot P(x_2 | x_1) \cdot P(x_3 | x_1, x_2) \cdots P(x_n | x_1, \ldots, x_{n-1})

Each token is predicted conditionally on all previous tokens. It's a chain of conditional probabilities.

Bayes' theorem

The central formula

Bayes' theorem is the mathematical tool that lets you invert the conditioning:

P(A∣B)=P(B∣A)⋅P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}

This may be the most important formula in machine learning. It says: to know P(A∣B)P(A|B), you just need to know P(B∣A)P(B|A), P(A)P(A), and P(B)P(B).

Two probability trees. The first branches on A then on B, the second branches on B then on A. Both reach the same intersection probabilities, and Bayes theorem converts one tree into the other.
Both trees describe the same situation but condition in opposite order: the top one starts from A, the bottom one from B. They end on the same intersections, and moving from one tree to the other is exactly what Bayes theorem does.Source : Wikimedia Commons, Bayes theorem tree diagrams

Why it's powerful

Often, we know the likelihood P(B∣A)P(B|A) (relatively easy to compute or model) but we want the posterior P(A∣B)P(A|B) (what we actually care about for decision-making). Bayes bridges the two.

Example: we want P(disease∣positive test)P(\text{disease} | \text{positive test}). We know P(positive test∣disease)P(\text{positive test} | \text{disease}) (the test sensitivity, given by the manufacturer). Bayes lets us go from one to the other.

Bayesian vocabulary

Bayes' theorem breaks down into four terms, each with a specific name:

Prior: P(A)P(A)

The prior belief, before observing data. In ML, it's what we believe about the parameters before training. A Gaussian prior centered at 0 says: "I believe the weights are probably small."

Likelihood: P(B∣A)P(B|A)

The probability of observing the data if hypothesis AA is true. This is what the model maximizes during training (maximum likelihood).

Evidence (marginal likelihood): P(B)P(B)

The total probability of observing the data, averaged over all possible hypotheses. Often impossible to compute exactly in practice (intractable), which is why we use approximations like variational inference or MCMC (Markov Chain Monte Carlo) methods.

Posterior: P(A∣B)P(A|B)

The updated belief after observing the data. This is what we want: the distribution over parameters given the observed data.

P(θ∣D)⏟posterior=P(D∣θ)⏞likelihood⋅P(θ)⏞priorP(D)⏟evidence\underbrace{P(\theta | \mathcal{D})}_{\text{posterior}} = \frac{\overbrace{P(\mathcal{D} | \theta)}^{\text{likelihood}} \cdot \overbrace{P(\theta)}^{\text{prior}}}{\underbrace{P(\mathcal{D})}_{\text{evidence}}}

Applications in machine learning

Naive Bayes classification

The naive Bayes classifier applies Bayes directly. To classify an email xx as spam or not-spam:

P(spam∣x)∝P(x∣spam)⋅P(spam)P(\text{spam} | x) \propto P(x | \text{spam}) \cdot P(\text{spam})

The "naive" assumption supposes that features (words) are conditionally independent given the class. It's wrong, but it works surprisingly well in practice.

Bayesian deep learning

In Bayesian deep learning, instead of learning a single set of weights θ∗\theta^*, we learn a distribution P(θ∣D)P(\theta | \mathcal{D}) over the weights. This allows quantifying prediction uncertainty: if the posterior distribution over weights is wide, the model is uncertain.

Variational inference

Since the exact posterior is often impossible to compute (the evidence P(D)P(\mathcal{D}) requires an integral over the entire parameter space), we approximate it with a simpler distribution q(θ)q(\theta). This is the principle of variational inference, at the heart of VAEs (Variational Autoencoders).

Key takeaways

  • Probabilities are the language of uncertainty, and ML is steeped in uncertainty
  • Kolmogorov axioms guarantee the consistency of probabilities
  • Conditional probability is everywhere: autoregressive models, classification, attention
  • Bayes' theorem connects prior, likelihood, and posterior
  • Bayesian vocabulary (prior, likelihood, posterior) comes up constantly in modern ML
  • Bayesian inference is the theoretical foundation of regularization and uncertainty quantification

Where this is used. A language model is a conditional probability: see the LLM overview.