Overview
GeDi (pronounced "Jedi") introduces a highly efficient method for controlling the output of large language models (LLMs) using small "generative discriminators." By applying Bayes' rule to class-conditional language models, GeDi steers text generation toward specific topics or away from toxicity. Notably, it operates up to 30x faster than previous state-of-the-art methods and demonstrates zero-shot capabilities for new attributes.
Introduction: The Challenge of Controllable Generation
While Large Language Models (LLMs) like GPT-3 exhibit remarkable capabilities, they are often characterized as "stochastic parrots" that mirror the unfiltered internet, including its toxicity, bias, and negativity. Controlling these models is a significant technical hurdle.
Existing "Plug and Play" methods, such as PPLM, require computationally expensive gradient updates for every generated word, rendering them impractical for real-time use. Conversely, methods like CTRL necessitate training the entire model from scratch with specific "control codes," which can limit output diversity and prevent the easy "detoxification" of pre-existing models. GeDi addresses these limitations by providing a decoding guide that is both effective and computationally efficient.
Methodology: Generative Discriminator Guidance
The core innovation of GeDi is the use of Class-Conditional Language Models (CC-LMs) as generative discriminators.
Traditional discriminators are "non-generative." To determine if a word is "positive," one would typically append it to the sentence and perform a full forward pass for every token in the vocabulary—a massive bottleneck. GeDi bypasses this by utilizing Bayes' rule to run two parallel forward passes at each step:
- One conditioned on the desired attribute (e.g.,
<positive>). - One conditioned on an anti-control code (e.g.,
<negative>).
By comparing these distributions, GeDi computes a classification likelihood for every possible next token simultaneously. This contrastive approach allows the model to cancel out domain-specific biases (e.g., movie review jargon) and focus strictly on the target attribute. The final output is a "weighted decoding" where the base LM's probabilities are shifted by the GeDi's classification scores.
Experimental Setup
The researchers evaluated GeDi using several standard benchmarks:
- IMDb Movie Reviews: For sentiment control training.
- Jigsaw Toxic Comment Classification: For detoxification training.
- AG News: A 4-topic dataset used to test multi-class and zero-shot topic control.
- RealToxicityPrompts: The primary benchmark for measuring toxicity reduction in GPT-2 and GPT-3.
- BookCorpus: Used to evaluate linguistic fluency and "book-like" quality.
Results and Discussion
GeDi demonstrates significant improvements over existing baselines in both speed and control efficacy.
Efficiency and Speed
A primary advantage of GeDi is its operational speed. It adds only a small, constant overhead to the base model's generation time, making it significantly more viable for production environments than gradient-based methods.
Control and Detoxification
- Detoxification: GeDi markedly reduced toxicity in both GPT-2 and GPT-3. Human evaluations showed that GeDi-guided GPT-3 was rated as toxic only 21% of the time, compared to 57% for the vanilla model, without sacrificing fluency.
- Sentiment Control: GeDi outperformed CTRL and PPLM in generating text with specific sentiments while maintaining a "book-like" quality.
- Zero-Shot Generalization: Since GeDi is a pre-trained LM, it possesses inherent knowledge of various topics. Training on just three topics allowed GeDi to steer generation toward a fourth, unseen topic simply by using that keyword as a control code.
- API Compatibility: GeDi can control "black box" models like GPT-3 via API because it only requires output probabilities, not internal gradients.
Conclusion and Future Work
GeDi represents a major advancement in controllable text generation. While it faces challenges such as vocabulary mapping between different tokenizers and API constraints (e.g., being limited to the top 100 tokens from GPT-3), its generative-discriminative framework offers a path toward unified models that excel at both generation and classification. Future work may focus on tighter integration between the guide and the base model to further enhance controllability.
Summary updated