Skip to content

Conditional generation + calibration: classifier-free guidance, ECE / temperature scaling - #50

Merged
davidkhjo merged 3 commits into
mainfrom
guidance-calibration
Aug 20, 2026
Merged

davidkhjo merged 3 commits into
mainfrom
guidance-calibration

Conversation

@davidkhjo

Copy link
Copy Markdown
Owner

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 a ClassifierEnergy (both branches from one net, logits computed once; an nn.Module so 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). Example jem_guidance.py.
  • Calibration metricseval.expected_calibration_error (hand-binned ECE = 0.10 exact; perfectly-calibrated → 0), reliability_curve, and temperature_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 w modest 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

Ẽ_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.
@davidkhjo
davidkhjo merged commit 78438d7 into main Aug 20, 2026
5 checks passed
@davidkhjo davidkhjo mentioned this pull request Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant