Conditional generation + calibration: classifier-free guidance, ECE / temperature scaling - #50
Merged
Merged
Conversation
Ẽ_w(x|y) = (1+w)E(x|y) − w E(x), composed from a ClassifierEnergy (both branches from one net, logits computed once). An nn.Module so samplers freeze the classifier. Validated: exact formula, guided sampling recovers the conditional mean, and guidance monotonically suppresses the wrong mode.
…re scaling) eval.expected_calibration_error / reliability_curve / temperature_scale (Guo et al. 2017). Validated: hand-binned ECE=0.1 exact, perfectly-calibrated→0, temperature scaling recovers the true T and cuts NLL/ECE.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Conditional generation + trustworthy classifiers (E3)
Two additions that make JEM classifiers steerable and honest.
GuidedEnergy(+ClassifierEnergy.guide) — classifier-free guidanceẼ_w(x|y) = (1+w)E(x|y) − w E(x), composed from aClassifierEnergy(both branches from one net,logitscomputed once; annn.Moduleso samplers freeze the classifier). Validated: the CFG formula is exact; guided sampling recovers the conditional mean; and guidance monotonically suppresses the wrong mode on overlapping classes (0.93 → 0.99 → 1.00 as w=0,2,6). Examplejem_guidance.py.eval.expected_calibration_error(hand-binned ECE = 0.10 exact; perfectly-calibrated → 0),reliability_curve, andtemperature_scale(recovers the true T≈3, cutting NLL 1.80→1.30 and ECE 0.28→0.01 on over-confident logits).Honest note (documented): large guidance weights can make the guided energy non-normalizable — the demo keeps
wmodest and samples with MALA.Lands under unreleased 0.15.0.
Verification
ruff + format + mypy clean; targeted tests pass; example runs on CPU.
🤖 Generated with Claude Code