kefirski.me
NeurIPSPaper 1720229 min read

Classifiers are Better Experts for Controllable Text Generation

An off-the-shelf classifier can steer a frozen language model at sampling time, beating specialist detoxification systems without fine-tuning or companion language models.

Steering a model you refuse to retrain

A language model is controllable when we can sample from p(xc)=ip(xix<i,c)p(x\mid c)=\prod_i p(x_i\mid x_{<i},c) for a condition cc we care about: a sentiment, a topic, the absence of toxicity. Retraining a conditional model for every new cc is the brute-force answer, and CTRL-style training is exactly that. We wanted the opposite: take a frozen model and bolt the condition on at sampling time.

Bayes gives the recipe in one line: reweight each candidate token as p(xix<i,c)p(xix<i)p(cxi)αp(x_i\mid x_{<i},c)\propto p(x_i\mid x_{<i})\,p(c\mid x_{\le i})^{\alpha}, where the exponent α\alpha sets how loudly the classifier speaks. The catch is cost. Scoring p(cxi)p(c\mid x_{\le i}) means running the classifier once per candidate token, and a GPT-2 vocabulary offers tens of thousands of candidates at every step.

Around that bottleneck the field grew workarounds. GeDi and DExperts distill the condition into small conditional language models that score the whole vocabulary in one pass, but those models must themselves be trained. PPLM instead nudges hidden states by gradient ascent at each step, which is slow and temperamental. Meanwhile, when we wrote this, Hugging Face hosted roughly ten thousand ready-made text classifiers and only about two dozen conditional language models. That asymmetry is the motivation: we asked whether the plain classifier is enough.

Classify only the tokens that could win

One observation unlocks it: sampling strategies throw almost every token away. If we sample from the top kk after reweighting, a token buried deep in p(xix<i)p(x_i\mid x_{<i}) cannot claw its way back with any realistic classifier score, so classifying it is wasted work. CAIF therefore scores only the jj most probable candidates, with k<jVk<j\ll|V|; across all our experiments j=100j=100 was enough.

One CAIF step, end to end

Sampling mechanism
The frozen model proposes, the classifier vets only the hundred candidates that could actually be sampled, and the weighted scores reshape the final top-k choice. Nothing is trained, and no second language model appears anywhere in the loop.

Concretely, at each step the frozen model proposes its distribution, we keep the top jj candidates, append each one to the context, ask the classifier for p(cxi)p(c\mid x_{\le i}), add αlogp(cxi)\alpha\log p(c\mid x_{\le i}) to the token logits, and sample from the resulting top kk. Guidance becomes a drop-in replacement for the sampling loop.

Point the exponent the right way

For detoxification the classifier outputs a toxicity probability, and there are two ways to hold it against a token. The route earlier systems defaulted to weights tokens by (1p(cxi))α(1-p(c\mid x_{\le i}))^{\alpha} with α1\alpha\ge 1, the inverse-probability score. We found the restriction to positive exponents unnecessary: weighting by p(cxi)αp(c\mid x_{\le i})^{\alpha} with α<0\alpha<0 is equally valid and behaves very differently.

The difference lives in the curve. The negative-α\alpha score logx-\log x starts punishing the moment toxicity probability xx rises above noise, while log(1x)\log(1-x) barely moves until xx approaches one half. Head to head on a thousand prompts, negative α\alpha detoxified significantly better while keeping lower perplexity, so every later experiment uses it.

Two ways to spend the same classifier output

score added to token logits
negative α: −log x (ours)inverse probability: log(1−x)
Two ways to spend the same classifier output At exponent magnitude one, the negative-alpha score falls sharply as soon as the toxicity probability leaves zero, while the inverse-probability score stays nearly flat below one half. The sharp curve is what stops a toxic continuation early rather than after the fact. negative α: −log x (ours): undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined inverse probability: log(1−x): undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined; undefined, undefined -3.2-1.601.63.2 0.10.30.50.70.9 negative α: −log x (ours)inverse probability: log(1−x) toxicity probability x from the classifier score added to token logits
At exponent magnitude one, the negative-alpha score falls sharply as soon as the toxicity probability leaves zero, while the inverse-probability score stays nearly flat below one half. The sharp curve is what stops a toxic continuation early rather than after the fact.

One classifier against three specialist systems

Our main test follows the DExperts protocol: ten thousand non-toxic prompts from RealToxicityPrompts, twenty-five continuations each, GPT-2 Large as the base model. CAIF is guided by an off-the-shelf toxic-bert classifier with α=5\alpha=-5 and judged by a different, independently trained offensive-language classifier, with perplexity measured under GPT-2 XL, so no model grades its own homework.

Perplexity against toxic-sample probability

toxic sample probability, percent
specialist and baseline samplersCAIF, one free-form classifier
Perplexity against toxic-sample probability Lower-left dominates both axes. Every specialist system pays perplexity for its control; CAIF reaches the lowest toxic-sample probability, 3.3 percent, and the best perplexity, 15.0, using nothing but a frozen LM and a public classifier. specialist and baseline samplers: GPT-2, PPL 25.5, 43.1%; PPLM, PPL 32.6, 40.0%; GeDi, PPL 60.0, 11.2%; DExperts, PPL 32.4, 7.5%; DExperts top-k, PPL 20.2, 6.4% CAIF, one free-form classifier: CAIF, PPL 15.0, 3.3% 0122436481025405570 GPT-2specialist and baseline samplers: GPT-2, PPL 25.5, 43.1%PPLMspecialist and baseline samplers: PPLM, PPL 32.6, 40.0%GeDispecialist and baseline samplers: GeDi, PPL 60.0, 11.2%DExpertsspecialist and baseline samplers: DExperts, PPL 32.4, 7.5%DExperts top-kspecialist and baseline samplers: DExperts top-k, PPL 20.2, 6.4%CAIFCAIF, one free-form classifier: CAIF, PPL 15.0, 3.3% perplexity of continuations, lower is better toxic sample probability, percent
Lower-left dominates both axes. Every specialist system pays perplexity for its control; CAIF reaches the lowest toxic-sample probability, 3.3 percent, and the best perplexity, 15.0, using nothing but a frozen LM and a public classifier.

The result is not a tradeoff but a dominance. We reach the lowest toxic-sample probability, 3.3 percent against 6.4 for the strongest DExperts variant and 11.2 for GeDi, and simultaneously the lowest perplexity, 15.0, where every specialist pays fluency for control. Binned by prompt toxicity, we beat DExperts on every bin below 0.75; on the most hostile prompts DExperts edges ahead on toxicity only by giving up far more perplexity.

Toxicity avoidance, all metrics

SamplingPPLMean tox.Max tox.Tox. prob.Dist-1
GPT-2, no steering25.518.247.543.157.9
PPLM32.617.745.940.058.4
GeDi60.013.732.211.261.5
DExperts32.413.929.77.558.0
DExperts, top-k20.213.327.96.452.9
CAIF, ours15.012.026.13.351.5
Ten thousand non-toxic prompts, twenty-five continuations each. Lower is better everywhere except Dist-1, which counts distinct unigrams. Our one concession is a slightly lower Dist-1 from top-k sampling; dist-2 and dist-3 stay level with the baselines at 81.2 and 84.1.

Sentiment control tells the same story. On both neutral and negative prompts from OpenWebText, guiding with a public sentiment classifier produced more positive continuations at lower perplexity than PPLM, GeDi, and DExperts, with the same recipe and no retraining. The honest fine print is the distinctness column above: top-kk sampling repeats slightly more unigrams than the top-pp baselines.

Guide only where the model hesitates

Guiding every step still costs jj classifier calls per token, so we asked when the calls actually matter. A periodic criterion guides every pp-th step and is obviously blind: with period two, a toxic token is free to appear on every unguided step. The entropy criterion is the interesting one. When the model's next-token entropy is low, the continuation is nearly forced, so we skip the classifier; we intervene only above a threshold ee, where the text can still fork.

Three ways to spend the classifier budget

Guidance criteria
Plain CAIF pays a classifier call on every step. A period-2 schedule halves the cost but guides on a blind grid. The entropy criterion spends the same five calls where the model is uncertain. Guided positions here are illustrative; the budget equivalence comes from the measured entropy distribution.

The empirical entropy distribution lets us match budgets exactly: a threshold of 3.2 guides about half the steps, like period two, and 5.0 guides about a fifth. At equal budget the entropy criterion wins on both perplexity and toxicity, and on sentiment control entropy-3.2 matched or beat plain CAIF while paying for half the classifier calls.

Speed is the one axis where distilled systems keep an edge. A free-form classifier re-reads the whole prefix, so each call grows quadratically with length, while GeDi and DExperts cache their way to linear cost; we measured CAIF faster up to twenty generated tokens, comparable to fifty, and slower beyond. For pipelines that otherwise sample many candidates and filter afterward, trading raw speed for far fewer rejected samples is the better bargain.

Controllable generation never needed a second language model: a plain classifier, pointed at the few tokens that matter, steers further at lower cost.