Skip to content

feat(lm): perplexity + batchnorm, fix NNLM_X init, auto-close workflow#123

Merged
slegroux merged 1 commit into
mainfrom
feat/lm-perplexity-batchnorm-autoclose
Jun 17, 2026
Merged

feat(lm): perplexity + batchnorm, fix NNLM_X init, auto-close workflow#123
slegroux merged 1 commit into
mainfrom
feat/lm-perplexity-batchnorm-autoclose

Conversation

@slegroux

Copy link
Copy Markdown
Owner

Resolves #64, #16, #42.

#64 — perplexity computation for LMs

  • Add reusable, exported perplexity(logits, targets, ignore_index=-100) = exp(mean cross-entropy).
  • Log val/perplexity and test/perplexity per-epoch in NNLM_X.
  • Bonus fix: NNLM_X.__init__ forwarded args to Classifier positionally in the wrong order (nnet received the int num_classes), so NNLM_X could not be instantiated at all — and its notebook cell (not #| notest) was failing CI. Now passes keyword args.

#16 — batchnorm (+ optims) for the MLP LM

  • Add batch_norm: bool = False to NNLM/NNLMConfig → inserts nn.BatchNorm1d after the hidden linear (nn.Identity when off → fully backward compatible). Surfaced in config/text/model/nnlm.yaml.
  • sample() now calls self.eval() so BatchNorm uses running stats on single-token contexts.
  • Optimizer/scheduler were already configurable via the hydra partials in NNLM_X (now actually usable thanks to the init fix).

#42 — auto-close linked issues on PR merge

  • New .github/workflows/close-linked-issues.yaml: on merged PRs, parse closing keywords (close/fix/resolve + #N) and close those issues with a comment. Extends GitHub's native behavior, which only fires when merging into the default branch, to any base branch.

Verification

  • nbdev_test models.lm.ipynb → Success (runs the previously-broken NNLM_X instantiation cell + a new perplexity assertion).
  • perplexity: uniform logits over V → exactly V; near-perfect → ~1.0.
  • Full Lightning train→val→test loop logs test/perplexity ≈ exp(test/loss).
  • nbdev_export reproduces nimrod/models/lm.py identically (numeric cell markers preserved).

🤖 Generated with Claude Code

…kflow

models.lm:
- add reusable `perplexity(logits, targets)` = exp(mean cross-entropy) and
  log val/test perplexity per-epoch in NNLM_X (closes #64)
- add optional BatchNorm1d on the NNLM hidden layer via `batch_norm` flag on
  NNLM/NNLMConfig (default off = backward compatible); sample() now eval()s so
  BN uses running stats on single-token contexts (closes #16)
- fix NNLM_X.__init__: it forwarded args to Classifier positionally in the
  wrong order (nnet got the int num_classes), so NNLM_X could not be
  instantiated at all and its notebook test cell was failing CI; now passes
  keyword args
- surface batch_norm in config/text/model/nnlm.yaml

CI:
- add close-linked-issues workflow: on merged PRs, close issues referenced by
  closing keywords on any base branch (GitHub only does this for the default
  branch) (closes #42)

Verified: nbdev_test models.lm.ipynb passes; perplexity(uniform, V)=V and ~1.0
for near-perfect; full Lightning train/val/test logs test/perplexity=exp(loss).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@slegroux
slegroux merged commit f325892 into main Jun 17, 2026
2 checks passed
@slegroux
slegroux deleted the feat/lm-perplexity-batchnorm-autoclose branch June 17, 2026 00:13
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.

perplexity computation for LMs

1 participant