Text Infilling

Wanrong Zhu, Zhiting Hu, Eric P. Xing

Introduction

Text generation has traditionally focused on left-to-right sequence creation or translation. However, many real-world applications require text infilling: the ability to complete sentences or paragraphs where portions are missing. This task is essential for restoring damaged historical documents, assisting writers with templates (e.g., "The [blank] was [blank] because [blank]"), or editing existing prose.

Existing research often treats infilling as a constrained problem, assuming single-word blanks or fixed positions. This paper addresses "unconstrained" scenarios where multiple blanks of unknown lengths exist at random positions, requiring a model that can dynamically determine how much text is needed to fill each gap.

Proposed Method: Segment-Aware Self-Attention

The authors propose a self-attention model based on the Transformer architecture. The key innovation is Segment-Aware Position Encoding, which allows the model to handle blanks of unknown lengths without losing track of global structure.

In a standard Transformer, absolute position embeddings indicate a word's fixed position in a sequence. For infilling, this is insufficient because the length of missing segments is unknown during the initial encoding. The proposed 2D position index uses:

  1. Segment ID: Identifies which part of the template the token belongs to (e.g., Segment 0 for the first known text, Segment 1 for the first blank).
  2. Offset ID: The position of the token within that specific segment.
The architecture of the self-attention model featuring segment-aware position encoding.

The model generates tokens for a blank auto-regressively until it produces a special <End-of-Blank> token, at which point it moves to the next segment. This architecture allows every generated token to "attend" to the entire template simultaneously, ensuring the generated "patch" fits the global context.

Experimental Evaluation

The researchers evaluated their models on three distinct datasets to test different infilling scenarios:

  • Yelp Review Corpus: Used for random masking experiments (30%, 40%, and 50% of tokens removed) to test general robustness.
  • Grimm’s Fairy Tales: Used for "Long Content Infilling" and "Preposition Infilling."
  • NBA Reports: Used to simulate news generation where specific entities (player names, scores) are provided as anchors.

Key Results

The self-attention model consistently outperformed attentional seq2seq and GAN-based baselines across all metrics, including Perplexity (PPL), BLEU scores, and human evaluation.

Quantitative comparison of models on the Yelp dataset across different numbers of blanks and metrics.

As shown in the results for the Yelp dataset, the self-attention model achieved a Perplexity of 38.304 for single-blank scenarios, significantly lower than the 107.480 achieved by the seq2seq baseline. Lower perplexity indicates the model is much more certain and accurate in its predictions. Furthermore, human annotators preferred the self-attention model’s generations, noting they were more "meaningful and fluent."

Discussion and Conclusion

A major finding was the "patch" problem: while RNNs and GANs often produce grammatically correct isolated segments, they frequently fail to integrate smoothly into the surrounding sentence (e.g., producing phrases like "I live at a ten times"). The self-attention model's ability to maintain bidirectional context through segment-aware encoding effectively mitigates this issue.

While this model represents a strong baseline, text infilling remains an open-ended challenge. Future work may involve leveraging larger pre-trained models and exploring more complex masking strategies to better mimic human writing and editing processes.

Summary updated

BibTeX
@misc{zhu2019text,
  author = {Wanrong Zhu and Zhiting Hu and Eric P. Xing},
  title = {{Text Infilling}},
  year = {2019},
  eprint = {1901.00158},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1901.00158},
}
Figure