joint energy-based models
**JEM** (Joint Energy-Based Models) is an **approach that reinterprets a standard classifier as an energy-based model** — the logit outputs of a classification network define an energy function $E(x) = - ext{LogSumExp}(f_ heta(x))$, enabling simultaneous discriminative classification and generative modeling from a single network.
**How JEM Works**
- **Classifier**: A standard neural network produces class logits $f_ heta(x) = [f_1(x), ldots, f_K(x)]$.
- **Energy**: $E(x) = - ext{LogSumExp}_{y}(f_y(x))$ — the negative log-sum-exp of logits defines the energy.
- **Classification**: $p(y|x) = ext{softmax}(f_ heta(x))$ — standard discriminative classification.
- **Generation**: $p(x) propto exp(-E(x))$ — sample using SGLD (Stochastic Gradient Langevin Dynamics).
**Why It Matters**
- **Dual Use**: One model does both classification AND generation — no separate generative model needed.
- **Calibration**: JEM-trained classifiers are better calibrated than standard classifiers.
- **OOD Detection**: The energy function naturally detects out-of-distribution inputs (high energy = OOD).
**JEM** is **the classifier that generates** — reinterpreting any classifier as a generative energy model for free.