Northeastern University · CS 7150 · Fall 2026
How a language model is trained on a reward instead of on text to imitate. The first piece uses a three-token model you can watch roll its dice; the REINFORCE-to-GRPO and DPO pieces use one model small enough to see whole: four tokens, three steps, 64 possible completions, with every next-token distribution on screen. Everything trains live in the browser, and because the model is so small, the quantities a real run can only estimate (expected reward, KL, the optimal policy itself) are computed exactly and drawn alongside. Shorter pieces on a line of responses, a line of scores and a walk through a sentence explain the optimum they aim at, why it acts on every token, and the model of human preferences behind DPO.
A bare language model, three tokens long, that you can watch roll its dice, with its probabilities shown at each step. Train it on text, then take the text away and keep only a score: the same update, applied to the model’s own samples, each weighted by its reward. That weight is everything a reward adds. Twelve runs of each show that weighting by 1 wanders with no direction while weighting by reward climbs. A fourth step shows what a KL-regularized objective actually aims at: the base model multiplied by a preference factor, over all 27 completions.
Open the explainer →Maximizing reward minus β times a KL penalty has a closed form: the reference model multiplied by ereward/β and renormalized. On a one-dimensional space of responses, slide β from “stay put” to “collapse onto the reward”, drag two responses to see their odds change by exactly egap/β with the normalizer cancelling, view it in log scale where reward is simply added, and watch reward hacking appear as the KL budget grows.
Open the explainer →Reward only the ending, and the optimum still bends every token: each candidate’s logit gets the log of a soft value, the expected reward-to-go. Computed exactly on three tiny generators: a story that must end happy, a line of verse with ten syllables, and code whose brackets must balance. Compare the RL optimum with naive classifier guidance, which applies the exponent after averaging instead of before, and see exactly where they differ.
Open the explainer →REINFORCE as fine-tuning on the model’s own samples, weighted by reward; a baseline that leaves the gradient unbiased and cuts its noise; and GRPO, which uses the group of samples as its own baseline. All three train side by side toward the KL-regularized optimum, drawn as a dashed target. Add a constant to every reward to see plain REINFORCE lose its way, and find the groups that teach GRPO nothing.
Open the explainer →A person prefers A with probability σ(rA−rB). Why only score gaps matter (add a constant to both and nothing changes), where the sigmoid comes from (noisy judgments, with Gumbel noise giving it exactly), and how a reward model recovers the scores from votes by logistic regression.
Open the explainer →Invert the optimum and the policy becomes a reward model, which turns preference learning into logistic regression on pairs. DPO and GRPO race to the same target: watch which completions the pairs pin down, the implicit reward each one ends up with, and DPO overfitting its pairs until more data or online resampling rescues it.
Open the explainer →