Plug-and-Play Attribute-Aware Text Infilling via A New Attention Mechanism and Two-Level Positional Encoding

Dongyuan Li, Kotaro Funakoshi, Manabu OkumuraJournal of Natural Language Processing 2023

Abstract

Text infilling aims to restore incomplete texts by filling in blanks and has attracted increasing attention recently because of its wide application in ancient text restoration, conversation generation, and text rewriting. However, attribute-aware text infilling is yet to be explored, and existing methods seldom focus on the infilling length of each blank or the number and location of the blanks. In this study, we propose a plug-and-play Attribute-aware Text Infilling method using a Pre-trained language model (A-TIP) that contains a text-infilling component and a plug-and-play discriminator. Specifically, we first designed a unified text-infilling component with modified attention mechanisms and intra- and inter-blank positional encoding to better perceive the number of blanks and the infilling length for each blank. We then propose a plug-and-play discriminator to guide generation and improve attribute relevance without decreasing text fluency. Finally, automatic and human evaluations on three open-source datasets indicate that, compared to all the baselines, A-TIP achieves state-of-the-art performance.

Introduction

Text infilling—the task of predicting missing words or spans in a sentence—is a cornerstone of modern NLP, vital for applications ranging from AI-powered writing assistants to the restoration of ancient manuscripts. Despite its utility, current infilling models often struggle with "attribute awareness." They may produce fluent text that nonetheless ignores specific constraints like sentiment, topic, or domain knowledge. Furthermore, controlling the precise number and length of filled spans remains a significant challenge for existing architectures.

Figure 3: Application of text infilling to ancient manuscript restoration, demonstrating the complexity of the task and the model's ability to handle multiple blanks.

The A-TIP Framework

To address these limitations, researchers have introduced A-TIP (Attribute-aware Text Infilling via Pre-trained Language Model). A-TIP is designed as a "plug-and-play" system, allowing for attribute-specific generation without the need for expensive retraining of the underlying language model.

Unified Text-Infilling Component

The core of A-TIP is built upon a pre-trained GPT-2 model, enhanced with a modified attention mechanism and a novel Two-Level Positional Encoding scheme. Unlike standard encodings, A-TIP tracks two distinct dimensions:

  1. Intra-blank encoding: Monitors the sequence of words generated within a specific blank.
  2. Inter-blank encoding: Identifies the position of the original [Mask] token relative to the entire sentence.

This dual-tracking allows the model to accurately perceive the structure of missing segments and generate spans of variable lengths that fit contextually.

Figure 4: The A-TIP architecture, illustrating the two-level positional encoding (Intra and Inter) and the plug-and-play discriminator mechanism used to guide attribute-aware generation.

Plug-and-Play Discriminator

Attribute control is managed by a lightweight linear discriminator. During inference, this component shifts the model's output distribution toward a desired attribute (e.g., positive sentiment) by calculating gradients. To maintain fluency, A-TIP employs KL divergence to ensure the modified distribution remains close to the base language model's original output. An "attribute gain" threshold further ensures that guidance is only applied when it significantly improves attribute relevance without compromising grammar.

Experimental Evaluation

A-TIP was evaluated across three diverse datasets: SST-5 (sentiment), Abstracts (domain knowledge), and ROCStories (topic-aware).

Key Results

  • Fluency and Diversity: A-TIP achieved the lowest Perplexity (PPL) scores and highest "Dist-n" scores compared to six major baselines (including BERT and RoBERTa), indicating the generation of more natural and varied text.
  • Attribute Accuracy: In sentiment and domain tasks, A-TIP showed significant improvements, such as an 8% accuracy boost over the best baseline on the SST-5 dataset.
  • Human Preference: Human judges consistently rated A-TIP higher for both fluency and attribute relevance, confirming its effectiveness in real-world scenarios.

Conclusion

A-TIP represents a significant step forward in controllable text generation. By separating positional awareness from attribute guidance, it achieves state-of-the-art performance in text infilling while remaining computationally efficient and adaptable to new domains. Future work will focus on integrating A-TIP into writing assistance tools and developing more challenging benchmarks for attribute-aware restoration.

Summary updated

BibTeX
@article{li2023plug,
  author = {Dongyuan Li and Kotaro Funakoshi and Manabu Okumura},
  title = {{Plug-and-Play Attribute-Aware Text Infilling via A New Attention Mechanism and Two-Level Positional Encoding}},
  journal = {Journal of Natural Language Processing},
  year = {2023},
  doi = {10.5715/jnlp.30.1011},
}
Figure