Gedi (generative Discriminator)

GeDi (Generative Discriminator) is the controllable generation technique that uses class-conditional language models as discriminators to guide text generation toward or away from specified attributes — developed by Salesforce Research as a method to steer any language model's output in real-time by using smaller "guide" models that score candidate tokens for their alignment with desired properties like topic relevance, safety, or sentiment.

What Is GeDi?

  • Definition: A generation-time control method that uses class-conditional language models (trained on attribute-labeled text) to compute per-token guidance signals that steer a base model's generation.
  • Core Innovation: Treats small fine-tuned language models as Bayesian classifiers that score each candidate next token for its alignment with desired attributes.
  • Key Advantage: Works with any frozen base model — no base model modification needed, attribute control is applied purely at decoding time.
  • Publication: Krause et al. (2021), Salesforce Research.

Why GeDi Matters

  • Plug-and-Play Control: Add attribute control to any base model without retraining or fine-tuning it.
  • Real-Time Steering: Guidance is computed per-token during generation, enabling dynamic control.
  • Multi-Attribute: Multiple GeDi guides can be combined for simultaneous control over multiple attributes.
  • Detoxification: Particularly effective at steering generation away from toxic content while maintaining fluency.
  • Efficiency: Guide models are small (124M parameters), adding minimal computational overhead.

How GeDi Works

Training: Train small class-conditional LMs on text labeled by attribute (e.g., "toxic" vs. "non-toxic"). Each class-conditional model learns language patterns specific to that attribute.

Inference: At each generation step:
1. Compute next-token probabilities from the base model.
2. Compute next-token probabilities from the desired-class guide model.
3. Compute next-token probabilities from the anti-class guide model.
4. Use Bayes' rule to weight base model probabilities toward desired class.

Guidance Strength: A control parameter adjusts how strongly the guide influences base model generation — from subtle bias to strong enforcement.

Applications

ApplicationDesired ClassAnti-ClassEffect
DetoxificationNon-toxicToxicSafe generation
Topic ControlOn-topicOff-topicRelevant content
SentimentPositiveNegativeUpbeat text
FormalityFormalInformalProfessional tone

Comparison with Alternatives

MethodBase Model ChangeControl GranularityOverhead
GeDiNone (frozen)Per-tokenSmall guide model
PPLMGradient updates during generationPer-stepBackpropagation per step
RLHFFull fine-tuningGlobal behaviorTraining cost
PromptingNoneInstructions onlyNo overhead

GeDi is an elegant solution for real-time attribute control in text generation — proving that small, specialized guide models can effectively steer any base model's output through Bayesian per-token weighting without requiring base model modification.

Take gedi (generative discriminator) further

Ask the copilot about this term, or have our engineers assess it against your process.