Text Infilling — Cloze Completion

Machine Learning
Introduced by
Wilson L. Taylor (cloze procedure, 1953); modern span infilling by Zhu et al. (2019)
Year
1953 (cloze); 2019 (neural span infilling)
Type
NLP conditional text generation task

What does it do?

Text infilling is a conditional text-generation task in which a model fills masked words, phrases, or spans in a passage using the surrounding context.

Its conceptual ancestor is the cloze procedure, which Wilson L. Taylor introduced in 1953 as a readability measure. Zhu, Zeng and Huang (2019) study neural text infilling in an arXiv preprint, and the approach is used for data augmentation, writing assistance, and language-model evaluation.

The intuition behind the method

Imagine reading a sentence with a blank where a word should be. A human reader fills the gap by drawing on what comes before and after it. Text infilling trains a machine to do the same: given the left context, the right context, or both, the model ranks candidate words or generates a span that fits coherently into the surrounding text. The task ranges from filling a single masked word, as in cloze tests and masked language models, to generating longer missing sentences or paragraphs. Two model families cover this range. For single-token gaps, a masked bidirectional encoder such as BERT ranks candidate tokens from the vocabulary. For longer spans, a sequence-to-sequence model such as T5 or BART generates a variable-length fill conditioned on the full passage, which makes the task conditional generation. Masked language modeling, the pretraining objective used for BERT, is closely related but is not the same task: it trains a model, whereas infilling applies a trained model to fill gaps in a given text.

History

The conceptual ancestor of text infilling is the cloze procedure, published by Wilson L. Taylor in 1953 as a new tool for measuring readability. Taylor's article compared cloze results with those of two readability formulas across pilot studies and experiments. The masked-prediction idea returned in neural NLP as the masked language modeling objective used to pretrain BERT. Zhu, Zeng and Huang (2019) study text infilling in an arXiv preprint (arXiv:1901.00158).

When to use it

Choose text infilling when the text contains explicit gap positions, or when such gaps can be defined, and the goal is to produce plausible fills that must agree with the text on both sides. Typical uses are generating varied training examples, suggesting completions in an editor, building cloze items, and probing a language model's fill accuracy on held-out masked passages. Use a pretrained model suited to the corpus language and domain: a bidirectional encoder such as BERT is adequate for single-token gaps, while multi-token spans call for a sequence-to-sequence model such as T5 or BART. Do not use it when the mask positions are unknown, since the method cannot discover gaps by itself, when the infilled content must be factually verified and no checking step is planned, or when the corpus is in a language or domain the model was not trained on.

Limitations and considerations

  • A large pretrained language model is preferred; without one, prediction quality degrades substantially.
  • Span-level infilling can produce fluent but factually incorrect completions, especially when world knowledge is required.
  • The method requires mask positions to be defined in advance; it cannot discover what is missing from a text autonomously.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Leverages bidirectional context — unlike left-to-right generation, the model sees both sides of a gap and produces more coherent fills.
  • Flexible task scope: a single masked token up to entire missing paragraphs can be predicted within the same framework.
  • Dual utility as both a downstream application (writing assistance, data augmentation) and a diagnostic probe for evaluating language model quality.

Applications

  • Data augmentation: generating varied paraphrases or alternative phrasings to expand a training corpus.
  • Writing assistance: suggesting coherent completions for incomplete sentences or paragraphs in editors and authoring tools.
  • Readability and language assessment: generating cloze tests for measuring reading comprehension or second-language proficiency.
  • Language model evaluation: probing whether a model has captured syntactic and semantic constraints by measuring its fill accuracy on held-out masked passages.

How it works

How it works

1

One or more positions in the source text are designated as targets. The masking strategy sets the difficulty and the use case: a single-token mask suits readability assessment and masked language model pretraining, while contiguous span masking tests deeper language understanding and is used for data augmentation or writing assistance.

2

The masked text is fed to a language model: either a bidirectional encoder such as BERT for single-token prediction, or a sequence-to-sequence model such as T5 or BART for span-level infilling. The model builds a contextual representation of the whole passage, including the tokens on both sides of each mask.

3

For each masked position, the model assigns a probability distribution over the vocabulary (single-token case) or generates a token sequence (span case). The highest-probability token, or the beam-decoded sequence, is returned as the infilled text. Optional post-processing, such as checking part-of-speech agreement or length limits, can be applied to the output.

4

Filled outputs are assessed against a reference or by human judgment. Rank-1 accuracy for token infilling is the share of masked positions where the highest-ranked predicted token equals the reference token. BLEU and ROUGE compare a predicted span with a reference span by n-gram overlap: BLEU is based on n-gram precision with a brevity penalty, and ROUGE is based on n-gram recall. Perplexity is the exponential of the mean negative log-likelihood per token under a separate language model, so lower values indicate more fluent text. Human evaluation checks fluency and coherence, especially when the infilled spans are long or the context is ambiguous.

Common pitfalls

  • Using a model trained on a different language or domain than the target corpus produces poor infills; always match the model to the corpus language.
  • Evaluating only with automated metrics such as BLEU can understate or overstate quality when several valid fills exist; supplement them with human fluency judgments.
  • For multi-token spans, a single-token masked model such as BERT is not appropriate; use a sequence-to-sequence model such as T5 or BART instead.
  • Treating results from a small evaluation set as representative: with few masked positions, accuracy and BLEU estimates vary widely, so report the number of masked positions with every score and check that conclusions hold across several held-out passages.

Frequently asked questions

What is the difference between text infilling and text generation?

Text generation predicts what comes after a prefix (left to right). Text infilling predicts content that fits inside an existing passage, using both the left and right surrounding context. This two-sided constraint makes infilling harder, but it produces more coherent results when the surrounding text is fixed.

Can I use BERT for span infilling?

BERT predicts one masked token at a time and is designed for single-token cloze tasks. For filling spans of multiple tokens, use a sequence-to-sequence model such as T5 or BART, which can generate variable-length outputs conditioned on the full passage.

How do I evaluate the quality of infilled text?

For single-token fills, accuracy at rank 1 against a reference token is the standard metric. For spans, BLEU and ROUGE compare the predicted fill with a reference, while perplexity measures fluency under a separate language model. Because multiple valid fills often exist, human judgments of fluency and coherence are a valuable complement to automated scores.

Does text infilling require labelled data?

Applying infilling to new text requires no labelled data, only a pretrained language model and a source text with defined mask positions. Labelled data (texts with known correct fills) is needed for evaluation, or for fine-tuning a model on a specific domain.

Related methods

Sources

  1. Taylor, W.L. (1953). Cloze Procedure: A New Tool for Measuring Readability. Journalism Quarterly, 30(4), 415-433.

    Open publication reference
  2. Zhu, C., Zeng, M., & Huang, X. (2019). Text Infilling. arXiv:1901.00158.

    Open publication reference