Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Don’t assume more than you know
Suppose all you know is that the English word “in” is translated as “dans” or “en” 30% of the time, and as “dans” or “à” 50% of the time. What probabilities should you give the five candidate words? Infinitely many answers fit. Maximum entropy picks the one that is otherwise as spread out (as uncommitted) as possible. Words the facts don’t mention get equal shares, and nothing is invented. The surprise is that this principle produces exactly the softmax model of logistic regression.
The maximum-entropy principle is a principled way to build models from partial knowledge: known averages, rates and moments. It justifies the exponential-family distributions used everywhere (Gaussian, exponential, Boltzmann). In classification it gives logistic and softmax regression a deeper meaning: they are the least-biased models that reproduce the observed feature statistics.
- 1. Maximum entropy chooses, among models consistent with the facts…
- 2. With no constraints, maximum entropy over 5 outcomes gives…
- 3. The conditional maxent classifier is the same as…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Berger’s example
The outcomes are dans, en, à, au cours de, pendant. The constraints are
- p(dans) + p(en) = 0.3;
- p(dans) + p(à) = 0.5;
- the probabilities sum to 1.
The maximum-entropy solution is
| Word | dans | en | à | au cours de | pendant |
|---|---|---|---|---|---|
| p | 0.186 | 0.114 | 0.314 | 0.193 | 0.193 |
- Both constraints hold exactly: 0.186 + 0.114 = 0.3 and 0.186 + 0.314 = 0.5.
- The two unmentioned words get the same probability.
- The entropy is 1.559 nats. The uniform distribution would have 1.609, but it violates the facts.
- The solution has the form p ∝ exp(λ₁f₁ + λ₂f₂), where f₁ = [word is dans or en] and f₂ = [word is dans or à].
The steps in plain English:
- Choose feature functions that encode what you know (indicators of words, of feature–class combinations, and so on).
- Measure their averages in the data. These become the constraints.
- The maxent model is p ∝ exp(Σ λᵢfᵢ). Find the λ that make the model’s feature averages equal the data’s.
- For classification, the features are pairs f(x, y), and this is fitting multinomial logistic regression.
- Add a Gaussian prior on λ (an L2 penalty) when features are many or data are few.
- 1. In the solution, p(au cours de) equals…
- 2. Entropy of the uniform distribution over 5 outcomes?
- 3. The λᵢ are chosen so that…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.Derivation and training
Primal problem: maximise H(p) = −Σ p log p subject to Σ p = 1 and E_p[fᵢ] = f̃ᵢ.
Lagrangian: setting ∂/∂p(y) = 0 gives −log p(y) − 1 + μ + Σ λᵢfᵢ(y) = 0, so p(y) = exp(Σ λᵢfᵢ(y))/Z(λ).
Dual = maximum likelihood. Substituting back, the dual objective is Σ λᵢf̃ᵢ − log Z(λ), the average log-likelihood of the data under the log-linear family. It is concave, and its gradient is f̃ − E_λ[f]. Maximum likelihood in the exponential family and maximum entropy subject to moment constraints are the same problem.
Conditional maxent (the classifier): p(y | x) = exp(Σ λᵢfᵢ(x, y))/Z(x). With fᵢ(x, y) = x_j·1[y = k], this is softmax regression (D2.23).
Training:
- GIS (Darroch and Ratcliff, 1972): λᵢ ← λᵢ + (1/C) log(f̃ᵢ/E_λ[fᵢ]). It requires Σᵢ fᵢ = C for every (x, y), so add a slack feature. It is simple, monotone and slow.
- IIS improves on GIS.
- Gradient methods, especially L-BFGS (Malouf, 2002), are far faster, and are what modern implementations use.
Gaussian prior (Chen and Rosenfeld, 2000): subtract Σ λᵢ²/(2σ²). The constraints are then only approximately met, which prevents infinite weights on rare or separating features.
from sklearn.linear_model import LogisticRegression
maxent = LogisticRegression(C=1.0, max_iter=1000).fit(X, y) # multinomial maxent with a Gaussian prior (L2)
# NLTK: nltk.classify.MaxentClassifier.train(train_toks, algorithm="gis") — feature-function styleUse it when you have heterogeneous, overlapping features (text, events, indicators) and need calibrated class probabilities. In practice, use any multinomial logistic regression solver with L2. Keep GIS for understanding.
- 1. The maxent dual objective is the…
- 2. GIS requires that every (x, y) has…
- 3. A Gaussian prior on λ corresponds to…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Theory
Why entropy?
- Jaynes (1957): entropy measures uncertainty, so maximising it subject to the data adds no information beyond the constraints.
- Shore and Johnson (1980): maximum entropy is the only inference rule consistent with a few natural axioms.
- Large-deviations view: the maxent distribution is the overwhelmingly most likely histogram consistent with the constraints.
Classic maxent distributions:
- a known mean on [0, ∞) gives the exponential distribution;
- a known mean and variance on ℝ gives the Gaussian;
- known feature averages on a finite set give the Gibbs or Boltzmann (softmax) distribution.
Uniqueness. The dual is strictly concave in λ when the features are linearly independent on the support, so the maxent distribution is unique. If a constraint can only be met at the boundary (for example, a feature that always co-occurs with one class), the optimal λ → ∞. That is separation again, and the prior fixes it.
Convergence of GIS. GIS is a bound-optimisation algorithm. Each step maximises a lower bound on the likelihood gain, so it increases monotonically. But its step is scaled by 1/C, and C can be large (many active features), which makes it slow. L-BFGS uses curvature information and needs one to two orders of magnitude fewer iterations (exercise 2: 13 against 294).
Connections:
- CRFs (D3.37) are conditional maxent over structured outputs;
- Boltzmann machines are maxent models over binary vectors with pairwise statistics;
- the exponential families of D1.15 (GLMs) are maxent distributions.
Interview questions.
- Logistic regression and maxent: what is the difference? None in the model. “Maxent” emphasises the derivation from constraints and arbitrary feature functions f(x, y).
- Why does an unregularised maxent model sometimes produce huge weights? A feature perfectly predicts a class in training. Matching its expectation exactly requires an infinite λ.
- 1. The maxent distribution on ℝ with known mean and variance is…
- 2. GIS is slow because its step is scaled by…
- 3. Maxent over structured label sequences gives…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Training a telemetry event classifier
History.
- Jaynes (1957) founded maximum-entropy inference from statistical mechanics.
- Darroch and Ratcliff (1972) introduced GIS.
- Della Pietra, Della Pietra and Lafferty (1997) added feature induction and IIS.
- Berger, Della Pietra and Della Pietra (1996) brought maxent to NLP (translation, tagging).
- Ratnaparkhi (1996) built the maxent part-of-speech tagger.
- Malouf (2002) showed L-BFGS vastly outperforms GIS and IIS.
- Chen and Rosenfeld (2000) introduced Gaussian priors.
Exercise 1. Berger’s example gives p = (0.186, 0.114, 0.314, 0.193, 0.193), with entropy 1.559 and the constraints met to 10⁻⁶. With a slack feature, GIS raises the mean log-likelihood from −1.099 (uniform) to −0.853 monotonically and matches every feature expectation to within 0.002.
Exercise 2: event classifier. Setup: 4 categories, 30 sparse binary indicators, features x ⊗ class.
(A) Training on 1500 events, unregularised: iterations to reach within 10⁻³ of the optimal log-likelihood.
| GIS | Gradient ascent (step 1) | L-BFGS |
|---|---|---|
| 294 | 588 | 13 |
(B) 100 training events: held-out log loss by Gaussian-prior (L2) strength. The true model’s log loss is 0.626.
| L2 strength | 0 | 0.001 | 0.01 | 0.05 | 0.2 |
|---|---|---|---|---|---|
| Held-out log loss | 13.77 | 1.368 | 0.961 | 1.017 | 1.155 |
- Use a quasi-Newton optimiser. L-BFGS needs about 20 times fewer iterations than GIS, which in turn is about twice as fast as plain gradient ascent with a fixed step.
- With little data, the prior is not optional. Without it, rare indicators that happen to separate the training events get huge weights, and the held-out log loss is 13.8, catastrophic. A moderate prior brings it to 0.96. Too strong a prior underfits.
- Even with the best prior, 100 events are far from the true model’s 0.63: the data, not the optimiser, are the limit.
Maximum entropy in AI, robotics and aerospace
- Event and text classification with many overlapping indicator features.
- Inverse reinforcement learning: maximum-entropy IRL infers reward functions from demonstrations of robot or pilot behaviour.
- Maximum-entropy RL: soft actor-critic adds an entropy bonus for robust exploration.
- Probabilistic modelling from limited knowledge: priors and noise models from known moments.
References
- E. T. Jaynes (1957). “Information theory and statistical mechanics.” Physical Review 106(4).
- A. L. Berger, S. A. Della Pietra, V. J. Della Pietra (1996). “A maximum entropy approach to natural language processing.” Computational Linguistics 22(1).
- J. N. Darroch, D. Ratcliff (1972). “Generalized iterative scaling for log-linear models.” Annals of Mathematical Statistics 43(5).
- R. Malouf (2002). “A comparison of algorithms for maximum entropy parameter estimation.” CoNLL.
- S. F. Chen, R. Rosenfeld (2000). “A survey of smoothing techniques for ME models.” IEEE Transactions on Speech and Audio Processing 8(1).