TL;DR
This paper introduces Locate&Edit (L&E), a novel method for controlled text generation that edits outputs from large language models (LLMs) using energy-based models. L&E efficiently and faithfully enforces constraints by first locating problematic text spans and then editing them, offering a flexible solution compatible with black-box LLMs and preserving the original generation's semantics.
What Problem Does This Paper Address?
The increasing adoption of LLMs in real-world applications necessitates ensuring their outputs adhere to various constraints, such as non-toxicity, logical consistency, and task-specific requirements. While prompting is a common method for steering LLMs, it's often brittle and lacks fine-grained control. More advanced controlled text generation (CTG) techniques often require access to internal model components (like weights or logits), making them incompatible with popular API-based LLMs. Furthermore, many existing CTG methods regenerate entire outputs, which can introduce new violations or significantly alter the original generation, hindering semantic preservation and making human oversight difficult. This paper addresses the need for a CTG method that is compatible with black-box LLMs, efficient, faithful to the original generation, and capable of enforcing constraints effectively.
Methods
The core of Locate&Edit (L&E) lies in its two-stage approach:
- Error Localization: L&E uses energy-based models (EBMs) to identify spans within an LLM-generated text that are most relevant to constraint violations. These EBMs are trained to assign an energy score to text segments, where lower energy indicates better compatibility with a constraint. The localization can be done at the token or instance level, using methods like gradient norms or attention weights.
- Span Editing: Once problematic spans are identified, L&E edits them. The paper proposes two variants:
- LASER-LLM EDIT: An LLM is instructed to edit the localized spans.
- LASER-EBM EDIT: The same EBM used for localization is also used to guide the editing process, often involving a masked language model (MLM) to propose candidate tokens and an energy-based reranking mechanism.
This approach is designed to be compatible with black-box LLMs as it only requires their text outputs. It also prioritizes semantic preservation by selectively modifying only the identified constraint-relevant spans, leaving the rest of the text unchanged. The method is iterative, allowing for repeated application until constraints are satisfied.
Datasets
The paper utilizes several datasets for evaluation:
- TOXICSPANS: For toxic span detection.
- INCONSISTENTSPANS: For inconsistent span detection.
- Set-LConVQA: For set-consistency enforcement, consisting of question-answer pairs.
- Set-SNLI: For set-consistency enforcement, consisting of sentences.
The paper also mentions using subsets of the Jigsaw Unintended Bias in Toxicity Classification dataset, SNLI, MNLI, and ANLI for training energy-based models.
Key Insights and Ideas
- Energy-based models are powerful localizers: Task-specific, lightweight EBMs can localize error spans as effectively as, or even better than, much larger LLMs, while being significantly faster. This suggests a more reliable and efficient alternative for error localization.
- Localization is key for faithful editing: Providing localized error spans to an LLM editor significantly improves its ability to enforce constraints, especially when multiple constraints are involved. This is more effective than unlocalized editing.
- Separating constraint modeling from generation is beneficial: L&E's modular approach allows for effective constraint enforcement even for novel or domain-specific constraints without requiring LLM fine-tuning.
- Fine-grained energy models enhance control: Regression-based EBMs that predict continuous energy values offer more nuanced control over constraint satisfaction compared to binary classifiers.
Key Results
- Competitive Localization: Task-specific EBMs achieved localization performance on par with or exceeding strong LLM baselines across various tasks, with orders of magnitude less execution time.
- Improved Controllability: LASER-LLM EDIT and LASER-EBM EDIT consistently outperformed baselines in constraint satisfaction across toxicity avoidance, contradiction avoidance, and set-consistency enforcement tasks. LASER-EBM EDIT, in particular, achieved the strongest control.
- Efficiency and Fluency Trade-off: LASER-LLM EDIT offered faster inference and more fluent outputs, while LASER-EBM EDIT provided stronger controllability at the cost of speed and fluency. LLM smoothing was used to improve the fluency of LASER-EBM EDIT.
- Multi-constraint Effectiveness: LASER-EDIT demonstrated strong performance in enforcing multiple constraints simultaneously, significantly outperforming baselines in joint non-toxicity and logical consistency control.
- Semantic Preservation: L&E achieved superior semantic preservation of base LLM generations and operated efficiently due to its targeted editing approach.
Limitations and Future Work
- EBM Dependence: The performance of L&E relies on the accuracy and robustness of the task-specific EBMs. Performance might degrade on texts exceeding the EBM training length range or under distribution shifts.
- In-domain vs. Out-of-domain Evaluation: While some experiments indirectly check out-of-domain robustness, a systematic in-domain versus out-of-domain evaluation is left for future work.
- Language Generalization: All experiments were conducted in English, and extending the approach to other languages is a promising direction.
- Potential Misuse: The paper acknowledges that the method could be misused to enforce harmful constraints, emphasizing the need for ethical oversight and safeguards. Modifying user-generated content without consent is also a concern.
- Future Work: The authors suggest exploring systematic in-domain versus out-of-domain evaluation and extending the approach to other languages.
Summary updated