Tokenization Consistency Matters for Generative Models on Extractive NLP Tasks

Kaiser Sun, Peng Qi, Yuhao Zhang, Lan Liu, William Yang Wang, zhiheng huang

Abstract

Generative models have been widely applied to solve extractive tasks, where parts of the input is extracted to form the desired output, and achieved significant success. For example, in extractive question answering (QA), generative models have constantly yielded state-of-the-art results. In this work, we study the issue of tokenization inconsistency that is commonly neglected in training these models. This issue damages the extractive nature of these tasks after the input and output are tokenized inconsistently by the tokenizer, and thus leads to performance drop as well as hallucination. We propose a simple yet effective fix to this issue and conduct a case study on extractive QA. We show that, with consistent tokenization, the model performs better in both in-domain and out-of-domain datasets, with a notable average of +1.7 F1 gain when a BART model is trained on SQuAD and evaluated on 8 QA datasets. Further, the model converges faster, and becomes less likely to generate out-of-context answers. Our results demonstrate the need for increased scrutiny regarding how tokenization is done in extractive tasks and the benefits of consistent tokenization during training.

Introduction: The Tokenization Inconsistency Problem

In extractive tasks like Question Answering (QA), the goal is to pull a specific span of text from a document to answer a query. While generative models (like BART or T5) are excellent at this, they suffer from a subtle but damaging bug: tokenization inconsistency.

Most modern NLP models use Byte-Pair Encoding (BPE), where characters are merged into tokens based on frequency. However, BPE rules are context-sensitive. For example, a string like "1912" might be tokenized as a single unit ['Ġ1912'] when it follows a space in a sentence, but as two units ['19', '12'] when it stands alone as an answer string.

Figure 1: An illustration of tokenization inconsistency where the same text "1912" is tokenized differently in the context versus the answer.

This creates a "paraphrasing" burden. During training, the model is shown one set of tokens in the context but is forced to predict a different sequence of tokens for the answer. This breaks referential integrity, making the task unnecessarily difficult and confusing the model into generating "out-of-context" (OOC) answers—a form of textual hallucination where the model generates text not present in the source.

Methods: Consistent Tokenization Training

The authors propose a straightforward fix called Consistent Tokenization Training.

Instead of tokenizing the input (Context + Question) and the output (Answer string) independently, the consistent approach tokenizes the input context first. Then, instead of tokenizing the answer string separately, the system identifies the start and end character offsets of the answer within the context and "slices" the corresponding token IDs directly from the already-tokenized input. This ensures that the target tokens the model must predict are identical to the tokens it just read in the context. This method is deterministic, requires no changes to the tokenizer itself, and doesn't require expensive pre-training from scratch.

Experimental Setup

The study utilizes the MRQA (Machine Reading Question Answering) benchmark. Training was conducted on in-domain datasets including SQuAD, TriviaQA, and NewsQA. Out-of-domain (OOD) evaluation was performed on NaturalQuestions (NQ), SearchQA, BioASQ, TextbookQA, and DuoRC to test how well the model generalizes when tokenization is handled correctly.

Key Results and Analysis

The implementation of consistent tokenization yielded significant improvements across several metrics:

  • Performance Boost: Using a BART-base model, consistent tokenization led to an average gain of +1.7 F1 across 8 datasets. In some zero-shot OOD scenarios, the gain was as high as +2.0%.
  • Faster Convergence: Models trained with consistent tokens reached lower validation loss much earlier in the training process. By removing the need to learn the "quirks" of the tokenizer, the model spends more time learning the actual task.
  • Reduced Hallucination: The rate of OOC predictions dropped significantly. For instance, on the TextbookQA dataset, the percentage of OOC predictions dropped from roughly 9% to 4% when consistency was enforced.
Figure 3: Learning curves (a) showing faster convergence and bar charts (b) showing reduced out-of-context (OOC) predictions for BART-Consistent compared to the original.

Log-perplexity analysis further showed that the model became significantly more confident in generating the correct gold answers. Essentially, referential integrity allows the model to treat the task as a true extraction rather than a translation between different tokenizations.

Conclusion

This work demonstrates that tokenization consistency is a critical, yet often overlooked, factor in the performance of generative models on extractive tasks. By ensuring that the model predicts the exact same tokens it sees in the input, researchers achieved better accuracy, faster training, and a marked reduction in textual hallucinations. While the study focused on English QA, these findings likely apply to any extractive NLP task where BPE-based tokenization is used.

Summary updated

BibTeX
@inproceedings{sun2023tokenization,
  author = {Kaiser Sun and Peng Qi and Yuhao Zhang and Lan Liu and William Yang Wang and zhiheng huang},
  title = {{Tokenization Consistency Matters for Generative Models on Extractive NLP Tasks}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  url = {https://openreview.net/forum?id=AAYXFyvNbr},
}
Figure