Introduction
Text infilling is the task of restoring missing segments in a text sequence, a capability vital for applications ranging from ancient manuscript restoration to creative writing assistance. While modern language models excel at generating fluent completions based on bidirectional context, they typically lack the ability to steer the generated content toward specific attributes, such as a particular sentiment or a specialized domain of knowledge.
Standard models are often "attribute-blind," requiring extensive fine-tuning to adapt to new styles or topics. Furthermore, they struggle with structural constraints, such as determining the appropriate length of the filled-in text. This paper introduces A-TIP (Attribute-aware Text Infilling via Pre-trained language model), a framework designed to provide fine-grained control over text infilling without sacrificing linguistic quality.
Methodology
The A-TIP framework consists of two primary components: a unified infilling model and a plug-and-play attribute controller.
1. Unified Text Infilling Model
A-TIP leverages a pre-trained GPT-2 architecture, modified to handle the infilling task. The input is formatted by concatenating the corrupted text (containing [Mask] tokens) with the target answers (separated by [Answer] tokens). To manage this structure, the authors implement two key innovations:
- Modified Attention Mechanism: Tokens in the context can attend bidirectionally to all other context tokens, while the generated answer tokens are restricted to auto-regressive attention (attending only to previous tokens).
- Two-Level Positional Encoding: Each token is assigned an "inter-blank" position (its location in the overall sentence) and an "intra-blank" position (its location within a specific gap). This allows the model to dynamically determine the length of each filled segment.
2. Plug-and-Play Attribute Controller
To avoid the cost of retraining for every new attribute, A-TIP uses a lightweight linear discriminator. During the generation process, this discriminator calculates gradients that shift the language model's hidden states toward the target attribute. To maintain fluency, a threshold-based "Gain" strategy is employed: the model only modifies a word choice if the attribute relevance boost exceeds a specific threshold $\delta$, otherwise defaulting to the base model's most likely (and usually most grammatical) token.
Experimental Setup
The model was evaluated across three diverse datasets to prove its versatility:
- SST-5: For sentiment-controlled infilling (5 classes).
- Abstracts: For domain-specific infilling (8 scientific domains like CS and Math).
- ROCStories: For topic-controlled infilling (13 topics extracted via topic modeling).
Results and Discussion
A-TIP demonstrates superior performance over competitive baselines such as BERT, RoBERTa, and ILM. On the SST-5 dataset, A-TIP achieved an attribute classification accuracy of 0.386, significantly outperforming the best baseline (ILM at 0.305). Crucially, this gain in control did not come at the expense of fluency; A-TIP maintained a lower perplexity (42.21) than ILM (48.14).
Human evaluations further validated these findings. Annotators rated A-TIP highest in both fluency (4.476/5) and attribute relevance (4.320/5) across all test sets. The plug-and-play nature of the discriminator also ensures efficiency, requiring minimal additional computation compared to standard decoding.
Conclusion
A-TIP provides a flexible and efficient solution for controlled text infilling. By decoupling the infilling task from attribute control through a plug-and-play discriminator and a specialized attention mechanism, it enables users to steer text generation toward desired sentiments or topics while preserving high linguistic quality. Future work will explore the integration of A-TIP into interactive writing tools to assist authors in real-time stylistic adjustments.
Summary updated