Skip to content
AI360Xpert
Beta

PAC-Bayes Bounds

Classical bounds blame model size, yet giant networks generalize. PAC-Bayes bounds blame the distance from initialization instead, which stays small even for huge models.

Training error 0.05 plus a complexity penalty near 0.15 certifies future error below 0.21 in the illustrative bound
Training error 0.05 plus a complexity penalty near 0.15 certifies future error below 0.21 in the illustrative bound

Why Does This Exist?

Classical capacity bounds charge by parameter count, and modern vision models carry millions of parameters against tens of thousands of images. The bounds evaluate above 1.01.0 — true, vacuous, useless. Yet the models generalize. Something in the classical accounting misprices what training actually does.

PAC-Bayes reprices it. Instead of counting parameters, it measures how far the learned weights travel from where they started, in nats of KL divergence between a posterior and a prior over weights. Training that barely moves (flat regions, good initialization) earns a tight bound regardless of parameter count. The neighboring pages are generalization theory and probabilistic foundations.

The one idea you need first. With probability at least 1−δ1 - \delta over training samples, the true error of a weight distribution QQ is bounded by its training error plus a complexity term shaped like (KL(Q ∥ P)+log⁡(2m/δ))/(2(m−1))\sqrt{(KL(Q\,\|\,P) + \log(2\sqrt{m}/\delta)) / (2(m-1))}, where PP is a fixed prior and mm is the sample count. The honest reading is qualitative: error grows with drift-from-prior and shrinks roughly as 1/m1/\sqrt{m}. Exact constants below are illustrative arithmetic on that shape, not published tight values.

Think of It Like This

A library fine, not a library census

A library wants to bound how many books go missing. The census approach counts every book on the shelves — millions — and posts a uselessly huge worst case. The ledger approach counts how far books traveled from their slots: borrowed books accrue fines per day away, shelved books cost nothing. A giant library with three books out has a tiny bill.

PAC-Bayes is the ledger. Parameters are the shelves; drift from initialization is books-out. A billion-parameter model that training barely moves owes little, while a tiny model dragged across the space owes plenty. Capacity was the wrong thing to count; distance traveled is what training actually spends.

How It Actually Works

Fix a prior PP before seeing data (usually centered at initialization). Train to a posterior QQ (a distribution around the learned weights, not just the point). Measure training error under QQ and the KL divergence KL(Q ∥ P)KL(Q\,\|\,P). Plug into the bound: small KL plus low training error certifies low future error. Flat minima help because a wide posterior around a flat minimum stays near the prior while keeping training error low — the same flatness story as loss landscape analysis, now with a certificate.

The prior must be data-free: peeking at training data to center it voids the guarantee silently.

Worked example

Illustrative numbers on the bound's shape: m=50,000m = 50{,}000 samples, training error 0.050.05, KL(Q ∥ P)=5,000KL(Q\,\|\,P) = 5{,}000 nats, δ=0.05\delta = 0.05.

  1. Confidence term: log⁡(250,000/0.05)=log⁡(2×223.6/0.05)=log⁡(8,944)≈9.1\log(2\sqrt{50{,}000}/0.05) = \log(2 \times 223.6 / 0.05) = \log(8{,}944) \approx 9.1.
  2. Complexity: (5,000+9.1)/49,999≈0.1002(5{,}000 + 9.1) / 49{,}999 \approx 0.1002.
  3. The bound constrains kl(0.05 ∥ true)≤0.1002kl(0.05 \,\|\, \text{true}) \le 0.1002. Inverting numerically, true error ≈0.205\approx 0.205 satisfies it (check: 0.05ln⁡(0.05/0.205)+0.95ln⁡(0.95/0.795)≈−0.0706+0.1697=0.099≤0.10020.05\ln(0.05/0.205) + 0.95\ln(0.95/0.795) \approx -0.0706 + 0.1697 = 0.099 \le 0.1002).

So the certificate reads: future error below about 0.210.21. Halve the drift to 2,5002{,}500 nats and the bound tightens toward 0.150.15 — the ledger rewards staying close to start.

Code

The point of this snippet is the inversion: binary KL solved for the certified error reproduces the 0.2050.205 bound.

import math

def binary_kl(p: float, q: float) -> float:    return p * math.log(p / q) + (1.0 - p) * math.log((1.0 - p) / (1.0 - q))

def certify(train_err: float, complexity: float) -> float:    q = train_err    while binary_kl(train_err, q) < complexity:  # raise q until KL bites        q += 0.001    return round(q, 3)

print(round(binary_kl(0.05, 0.205), 4))  # -> 0.099print(certify(0.05, 0.1002))  # -> 0.205

Watch Out For

A prior tuned on training data voids the certificate

Centering the prior at the trained weights, or picking its variance by training performance, spends the data twice. The bound's proof assumes the prior is fixed beforehand; a data-peeking prior makes the certificate circular while the numbers look identical.

Center priors at initialization (or on a held-out split) and freeze them before training. If the "prior" moved after seeing the training set, the bound is decoration.

Huge drift makes the bound vacuous again

Fine-tuning across tasks or long schedules can push KL(Q ∥ P)KL(Q\,\|\,P) into the millions of nats, and the bound sails past 1.01.0 — the same vacuity classical bounds suffered, relocated. The math holds; the certificate says nothing.

Track KL during training as a diagnostic: rising KL with falling training error is normal, but budget it. Data-dependent priors and compression-based bounds exist precisely to rescue drifted regimes.

The Quick Version

  • PAC-Bayes bounds future error by training error plus drift-from-prior measured in KL nats.
  • The worked illustration certifies error below about 0.210.21 from 0.050.05 training error and 5,0005{,}000 nats of drift.
  • Flat minima earn tight bounds: wide posteriors stay near the prior without raising training error.
  • Priors must be fixed before seeing data, or the certificate is circular.
  • Large drift reintroduces vacuity, so track KL as a training diagnostic.