Large language models (LLMs) are often steered using two primary methods: fine-tuning, which is computationally expensive, and prompt engineering, which is often unreliable. A growing body of research suggests a third way: Logit Arithmetic. By performing simple mathematical operations on the probability distributions of different model states at inference time, we can precisely steer text generation without ever updating a model's weights.
The Intuition of Distributional Subtraction
At each step of text generation, a language model produces a "logit" for every word in its vocabulary, representing the raw score of how likely that word is to come next. Usually, we just pick the highest score.
Contrastive decoding changes this by looking at the difference between two or more distributions. If we want a model to be less toxic, we don't just ask it to be "nice." Instead, we calculate the difference between a standard model's predictions and the predictions of a "toxic" model. By subtracting the toxic model's logits, we effectively suppress the tokens that a toxic persona would likely choose, leaving behind the "clean" alternatives.
This approach acts as a high-pass filter for concepts. It removes the generic or undesirable "noise" to reveal the specific "signal" we want the model to follow.
Experts and Anti-Experts
One of the foundational frameworks for this is DExperts, introduced by Alisa Liu, Maarten Sap, and colleagues in DExperts: Decoding-Time Controlled Text Generation with Experts and Anti-Experts.
In this setup, a large "base" model is combined with two smaller models:
- The Expert: A model trained on desirable data (e.g., polite text).
- The Anti-Expert: A model trained on undesirable data (e.g., toxic text).
By boosting the expert's logits and penalizing the anti-expert's logits, the base model is steered toward the desired attribute. This contrastive approach is often more precise than using a positive expert alone because the anti-expert identifies and "cancels out" subtle negative patterns that the base model might otherwise generate.
Classifier-Free Guidance for Language
While DExperts uses separate models, researchers have found that you can achieve similar results using a single model with different prompts. This is known as Classifier-Free Guidance (CFG), a technique originally popularized in image generation models like Stable Diffusion.
Guillaume Sanchez, Stella Biderman, and their team demonstrated in Stay on topic with Classifier-Free Guidance that LLMs can be steered by contrasting a "conditioned" prompt (the actual instruction) against an "unconditioned" or "negative" prompt (like an empty string or a generic persona).
By amplifying the difference between these two states, the model is forced to pay more attention to the specific constraints of the prompt. This allows smaller models to significantly outperform much larger ones on reasoning and coding tasks simply by "dialing up" their adherence to the instructions.
Formalizing Model Arithmetic
The idea of treating model outputs as mathematical components is formalized in the Model Arithmetic framework by Jasper Dekoninck, Marc Fischer, and Martin Vechev in Controlled Text Generation via Language Model Arithmetic.
They treat the log-probability distributions of different models or prompts as vectors that can be added or subtracted. This allows for complex steering, such as:
- De-biasing: Subtracting a distribution conditioned on a specific bias.
- Blending: Adding distributions from two different styles to create a hybrid output.
- Multi-objective control: Balancing multiple goals simultaneously, such as being both helpful and concise.
This mathematical pathway provides a predictable, training-free way to control LLM behavior. As shown by Tingchen Fu and Rui Yan in their work on Multi-objective Contrastive Alignment, these methods can even resolve conflicting objectives—like helpfulness versus harmlessness—at the moment the text is being generated.
Overcoming the Helpful Assistant Trap
A common problem with modern LLMs is that they are often "too helpful." Because they are fine-tuned to be polite assistants, they may struggle to adopt specific personas or refuse certain requests if the system prompt isn't strong enough.
Yijiang River Dong and Tiancheng Hu address this in Steer Model beyond Assistant: Controlling System Prompt Strength via Contrastive Decoding. By contrasting the target system prompt against a "default assistant" prompt, they can amplify the signal of the desired persona. This allows users to "dial up" the strength of a system prompt at inference time, making the model far more effective at following strict constraints or staying in character.