Tokenization Consistency Matters for Generative Models on Extractive NLP Tasks (2023)

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 pretrained sequence-to-sequence (seq2seq) models have achieved remarkable success in a wide range of tasks @xcite . as an important component of the models, tokenizer is frequently discussed, including different tokenization methods and the model's robustness to different tokenization @xcite . in our work, we identify an issue of tokenization consistency that affects the performance of seq2seq models. specifically, when a seq2seq task has extractive nature, i.e., parts of the output text are extracted from the input text, the desired output could be tokenized differently from how it is tokenized in the input, leading to tokenization inconsistency during model training. for example, in extractive question answering (qa), which takes a context-question pair as input and outputs a span of context as answer, the answer might be tokenized differently from the span in the context (figure 1 ). different variants of inconsistent tokenization have been found in several previous works in other tasks such as semantic parsing, open-domain question answering @xcite @xcite , but important issues like this are often deemed not analysis-worthy, and no universal solution nor in-depth analysis have been presented. this seemingly minor difference in tokenization alters referential integrity and can result in a notable impact on model performance during inference. we use extractive qa as a case study and propose a simple and effective approach to mitigate this issue -extracting the tokenized answer from the context for training. we discover that, when fine-tuning with consistently tokenized instances, the model 1) achieves better in-domain and out-of-domain performance (+0.9% f 1 in-domain and +2.0 % zero-shot out-of-domain), 2) converges faster during training, and 3) is less likely to generate out-of-context output (i.e. less likely to hallucinate textually). with our findings, we would like to note that inconsistent tokenization can affect any tasks that can be cast as seq2seq tasks with an extractive nature beyond qa and call on researchers and practitioners to consider applying the consistent tokenization technique during training. ## related work byte-pair-encoding (bpe) @xcite , language-model-based segmentation @xcite , and their variants @xcite are commonly used as the tokenizers for nlp models due to their simplicity and universality. recent research has identified these tokenization approaches as sources of poor model generalization. for example, bpe has been shown to produce less ideal morphological segmentation @xcite , and the same text can be tokenized differently when different bpe rules are applied @xcite . existing approaches either modify model training by using stochastic inputs or by modifying how bpe segmentation is done to improve model robustness and generalization @xcite @xcite . in contrast, we propose a simple and deterministic approach that does not rely on altering the segmentation approach in any way, so that the original training strategy can be preserved. besides generic approaches, researchers have also investigated domain-specific approaches to improve segmentation on specific texts @xcite @xcite . @xcite and @xcite propose approaches that aim at overcoming the inconsistency of tokenizing numbers and enhancing the model's numerical reasoning ability. @xcite use "space-joined tokens" to resolve many string-matching anomalies after tokenization that lead to unfair evaluation in semantic parsing. we instead look at inconsistency from a more general perspective by making our method applicable to any tasks with an extractive nature. in addition to subword segmentation methods, another line of research focuses on character-and byte-level modeling as procedures that are free of tokens @xcite @xcite . while tokenizationfree methods show potential to surpass subword segmentation approaches, we remain focused on the consistency issue of subword tokenizations, as most prevalent state-of-the-art models rely on subword tokenizations @xcite . ## consistent tokenization: what it is and how to achieve it consistent tokenization consider a seq2seq task, which takes text @xmath0, ..., x n ) as input, and outputs @xmath1, ..., y m ). when the task is extractive, there exists two sets of indices, i and j , such that x @xmath2. in the example of figure 1 , x is the context-question pair, @xmath3, and let tokenization be a function t that maps text into a sequences of token ids. suppose x @xmath4. here, i ′ denotes the set of indices that maps to the x i in the tokenized input, while j ′ denotes the position of y j in the tokenized output. note that t (x) i ′ = t (y) j ′ is not always true: in figure 1 , x i is mapped to the ids of " ġ1912", while y j is mapped to the ids of "19" and "12", because there is no preceding space in y j . we call it inconsistent tokenization when t (x) i ′ ̸ = t (y) j ′ . analogously, tokenization is consistent when t (x) i ′ = t (y) j ′ . inconsistent tokenization could emerge due to the existence of preceding space, numbers, or punctuation when using the vanilla bpe tokenizer. sentencepiece tokenizers are less subject to inconsistency because one of the underlying reasons, preceding space, is mitigated by the combined implementation of vanilla bpe and unigram. consistent tokenization training when the input and output are tokenized inconsistently, the task can no longer be solved by simply extracting the output from the input token ids, but requires an additional step from the model to "paraphrase" the input ids into the output token ids that do not exist in the input ids. therefore, learning with inconsistently tokenized instances becomes an inherent predicament for model compared to learning with their consistently tokenized counterparts. instead of tokenizing output in situ, we propose to retrieve t (y) j ′ from t (x) i ′ such that the tokenization is always consistent among all x, y pairs. compared to proposing a new tokenization method that is immunized to inconsistency, this is a simple yet effective fix that every researcher can implement without any non-trivial effort and without the need to pretrain the model again. ## case study: extractive qa with generative models in this work, we use extractive qa as a representative for extractive tasks. extractive qa is an ideal candidate for studying the effect of consistent tokenization, since its output is always a substring of the input. recent work has demonstrated that applying generative models to this task leads to great performance gains @xcite @xcite and greater potential to unify different input formats @xcite . ## findings we run model training over each of the squad, triviaqa and newsqa training sets, and report evaluation results on their corresponding dev sets in consistent tokenization training improves indomain qa performance. overall, we observe statistically significant improvement in f 1 with the consistent variants on all of squad, triviaqa and newsqa, with in-domain performance gains of 1.0, 1.1 and 0.6 for the three datasets, respectively (marked by shaded cells). a similar observation is made with the em results. one potential explanation for the improvement is that, the task becomes inherently simpler with consistent tokenization. we hypothesize that consistent tokenization allows the model to extract answers from the context instead of also needing to learn to paraphrase the answer into something that does not exist in the context, as we mentioned in section 3. we will validate this hypothesis when we examine the convergence speed of the models with or without consistent tokenization during training. consistent tokenization also improves zero-shot qa performance on out-of-domain datasets. we also examine zero-shot model performance on unseen domains in training with consistent tokenization leads to faster model convergence, and improved model confidence on the gold answer. we present the training curves of models fine-tuned on squad in figure 2a , and include training curves for other datasets in appendix e. across all the datasets, the consistent models converge faster than the original ones. this corroborates our hypothesis that solving extractive qa by simply extracting answers at the token level can make the task easier. to further validate this, we also examine the log perplexity of the gold answer for each instance, and compare the distributional difference between consistent and original models (shown in figure 5 , appendix f). we see that the overall distribution of log perplexity difference leans to the negative side, suggesting that the model is more confident in generating gold answers when tokenization consistency is enforced during training. training with consistent tokenization leads to less textual hallucination. an important angle to look at generative models is hallucination. it is worth noting that while the general meaning of hallucination, or more precisely factual hallucination, refers to the problem when a model produces factual content that is either inconsistent with or ungrounded to the input. in the context of extractive qa, we instead refer to a more specific definition of textual hallucination, where the qa model produces out-of-context answer sequence that does not align with any given span of text in the input. we show the percentage of instances that models generate out-of-context answers on different datasets in figure 2b . an example of such out-of-context answers can be found in appendix h. we find that when trained with consistent tokenization, the model is less likely to textually hallucinate. we conjecture that this is because with inconsistently tokenized training data, the model is undesirably exposed to a many context-answer pairs that are not directly aligned at the token level. this misalignment between the tokenized answer and its inconsistent form in the tokenized context possibly leads to the higher hallucination rate. ## conclusion we identify and address the issue of tokenization consistency in extractive tasks. we find that consistent tokenization improves model training on in-domain performance, convergence speed, out-ofdomain generalization, and textual hallucination. it is worth noting that inconsistent tokenization may affect any extractive tasks. using these findings, we suggest to apply consistent tokenization to inputs and outputs whenever researchers or practitioners are tackling extractive tasks.