mT5: A massively multilingual pre-trained text-to-text transformer
Linting Xue, Noah Constant, Adam Roberts, Mihir Kale, Rami Al-Rfou, Aditya Siddhant, Aditya Barua, Colin Raffel
Introduction
Current natural language processing (NLP) pipelines often make use of transfer learning, where a model is pre-trained on a data-rich task before being fine-tuned on a downstream task of interest (Ruder et al., 2019). The success of this paradigm is partially thanks to the release of parameter checkpoints for pre-trained models. These checkpoints allow members of the NLP community to quickly attain strong performance on many tasks without needing to perform expensive pre-training themselves. As one example, the pre-trained checkpoints for the ‘‘Text-to-Text Transfer Transformer’’ (T5) model released by Raffel et al. (2020) have been used to achieve state-of-the-art results on many benchmarks (Khashabi et al., 2020; Roberts et al., 2020; Kale, 2020; Izacard and Grave, 2020; Nogueira et al., 2020; Narang et al., 2020, etc.).
Unfortunately, many of these language models were pre-trained solely on English-language text. This significantly limits their use given that roughly 80% of the world population does not speak English (Crystal, 2008). One way the community has addressed this English-centricity has been to release dozens of models, each pre-trained on a single non-English language (Carmo et al., 2020; de Vries et al., 2019; Le et al., 2020; Martin et al., 2020; Delobelle et al., 2020; Malmsten et al., 2020; Nguyen and Tuan Nguyen, 2020; Polignano et al., 2019, etc.). A more general solution is to produce multilingual models that have been pre-trained on a mixture of many languages. Popular models of this type are mBERT (Devlin, 2018), mBART (Liu et al., 2020a), and XLM-R (Conneau et al., 2020), which are multilingual variants of BERT (Devlin et al., 2019), BART (Lewis et al., 2020b), and RoBERTa (Liu et al., 2019), respectively.
In this paper, we continue this tradition by releasing mT5, a multilingual variant of T5. Our goal with mT5 is to produce a massively multilingual model that deviates as little as possible from the recipe used to create T5. As such, mT5 inherits all of the benefits of T5 (described in section 2), such as its general-purpose text-to-text format, its design based on insights from a large-scale empirical study, and its scale. To train mT5, we introduce a multilingual variant of the C4 dataset called mC4. mC4 comprises natural text in languages drawn from the public Common Crawl web scrape. To validate the performance of mT5, we include results on several benchmark datasets, showing state-of-the-art results in many cases. Finally, we characterize a problematic behavior of pre-trained generative multilingual language models in the zero-shot setting, where they erroneously translate part of their prediction into the wrong language. To address this ‘‘accidental translation’’, we describe a simple procedure that involves mixing in unlabeled pre-training data during fine-tuning and demonstrate that it dramatically alleviates this issue. We release our pre-trained models and code so that the community can leverage our work.1
Background on T5 and C4
In this section, we provide a short overview of T5 and the C4 pre-training dataset. Further details are available in Raffel et al. (2020).
T5 is a pre-trained language model whose primary distinction is its use of a unified ‘‘text-to-text’’ format for all text-based NLP problems. This approach is natural for generative tasks (such as machine translation or abstractive summarization) where the task format requires the model to generate text conditioned on some input. It is more unusual for classification tasks, where T5 is trained to output the literal text of the label (e.g. ‘‘positive’’ or ‘‘negative’’ for sentiment analysis) instead of a class index. The primary advantage of this approach is that it allows the use of exactly the same training objective (teacher-forced maximum-likelihood) for every task, which in practice means that a single set of hyperparameters can be used for effective fine-tuning on any downstream task. Similar unifying frameworks were proposed by Keskar et al. (2019) and McCann et al. (2018). Given the sequence-to-sequence structure of this task format, T5 uses a basic encoder-decoder Transformer architecture as originally proposed by Vaswani et al. (2017). T5 is pre-trained on a masked language modeling ‘‘span-corruption’’ objective, where consecutive spans of input tokens are replaced with a mask token and the model is trained to reconstruct the masked-out tokens.
An additional distinguishing factor of T5 is its scale, with pre-trained model sizes available from 60 million to 11 billion parameters. These models were pre-trained on around 1 trillion tokens of data. Unlabeled data comes from the C4 dataset, which is a collection of about 750GB of English-language text sourced from the public Common Crawl web scrape. C4 includes heuristics to extract only natural language (as opposed to boilerplate and other gibberish) in addition to extensive deduplication. The pre-training objective, model architecture, scaling strategy, and many other design choices for T5 were chosen based on a large-scale empirical study described in detail in Raffel et al. (2020).
mC4 and mT5
Our goal in this paper is to create a massively multilingual model that follows T5’s recipe as closely as possible. Towards this end, we develop an extended version of the C4 pre-training dataset that covers languages and introduce changes to T5 to better suit this multilinguality.
The C4 dataset was explicitly designed to be English only: any page that was not given a probability of at least of being English by langdetecthttps://pypi.org/project/langdetect/ was discarded. In contrast, for mC4 we use cld3https://github.com/google/cld3 to identify over languages. Since some of these languages are relatively scarce on the internet, we make use of all of the monthly web scrapes released so far by Common Crawl. This is dramatically more source data than was used for C4, for which the April 2019 web scrape alone was enough to provide plenty of English-language data.
An important heuristic filtering step in C4 was the removal of lines that did not end in an English terminal punctuation mark. Since many languages do not use English terminal punctuation marks, we instead apply a ‘‘line length filter’’ that requires pages to contain at least three lines of text with 200 or more characters. Otherwise, we follow C4’s filtering by deduplicating lines across documents and removing pages containing bad words.https://github.com/LDNOOBW/ Finally, we detect each page’s primary language using cld3 and remove those with a confidence below 70%.
After these filters are applied, we group the remaining pages by language and include in the corpus all languages with 10,000 or more pages. This produces text in 107 ‘‘languages’’ as defined by cld3. However, we note that six of these are just script variants of the same spoken language (e.g. ru is Russian in Cyrillic script and ru-Latn is Russian in Latin script). A histogram of the page counts for each language is shown in fig. 1. Detailed dataset statistics including per-language token counts are shown in the appendix.
2 mT5
A major factor in pre-training multilingual models is how to sample data from each language. Ultimately, this choice is a zero-sum game: If low-resource languages are sampled too often, the model may overfit; if high-resource languages are not trained on enough, the model will underfit. We therefore take the approach used in (Devlin, 2018; Conneau et al., 2020; Arivazhagan et al., 2019) and boost lower-resource languages by sampling examples according to the probability , where is the probability of sampling text from a given language during pre-training and is the number of examples in the language. The hyperparameter (typically with ) allows us to control how much to ‘‘boost’’ the probability of training on low-resource languages. Values used by prior work include for mBERT (Devlin, 2018), for XLM-R (Conneau et al., 2020), and for MMNMT (Arivazhagan et al., 2019). We tried all three of these values (ablation results in section 4.2) and found to give a reasonable compromise between performance on high- and low-resource languages.
The fact that our model covers over languages necessitates a larger vocabulary. Following XLM-R (Conneau et al., 2018), we increase the vocabulary size to wordpieces. As in T5, we use SentencePiece (Kudo and Richardson, 2018; Kudo, 2018) models trained with the language sampling rates used during pre-training. To accommodate languages with large character sets like Chinese, we use a character coverage of and enable SentencePiece’s ‘‘byte-fallback’’ feature to ensure that any string can be uniquely encoded.
3 Comparison to related models
To contextualize our new model, we provide a brief comparison with existing massively multilingual pre-trained language models. For brevity, we focus on models that support more than a few dozen languages. Table 1 gives a high-level comparison of mT5 to the most similar models.
mBERT (Devlin, 2018) is a multilingual version of BERT (Devlin et al., 2019). Similar to our approach with mT5, mBERT follows the BERT recipe as closely as possible (same architecture, objective, etc.). The primary difference is the training set: Instead of training on English Wikipedia and the Toronto Books Corpus, mBERT is trained on up to languages from Wikipedia. XLM (Conneau and Lample, 2019) is also based on BERT but applies improved methods for pre-training multilingual language models including explicitly cross-lingual pre-training objectives. Many pre-trained versions of XLM have been released; the most massively-multilingual variant was trained on languages from Wikipedia. XLM-R (Conneau et al., 2020) is an improved version of XLM based on the RoBERTa model (Liu et al., 2019). XLM-R is trained with a cross-lingual masked language modeling objective on data in languages from Common Crawl. To improve the pre-training data quality, pages from Common Crawl were filtered by an n-gram language model trained on Wikipedia (Wenzek et al., 2020). mBART (Liu et al., 2020a) is a multilingual encoder-decoder model that is based on BART (Lewis et al., 2020b). mBART is trained with a combination of span masking and sentence shuffling objectives on a subset of languages from the same data as XLM-R. MARGE (Lewis et al., 2020a) is a multilingual encoder-decoder model that is trained to reconstruct a document in one language by retrieving documents in other languages. It uses data in languages from Wikipedia and CC-News (Liu et al., 2019).
Experiments
To validate the performance of mT5, we evaluate our models on 6 tasks from the xtreme multilingual benchmark (Hu et al., 2020): the XNLI (Conneau et al., 2018) entailment task covering languages; the XQuAD (Artetxe et al., 2020), MLQA (Lewis et al., 2019), and TyDi QA (Clark et al., 2020) reading comprehension benchmarks with , , and languages respectively; the Named Entity Recognition (NER) dataset of WikiAnn (Pan et al., 2017) restricted to the languages from xtreme (Hu et al., 2020), and the PAWS-X (Yang et al., 2019) paraphrase identification dataset with languages. We cast all tasks into the text-to-text format, i.e. generating the label text (XNLI and PAWS-X), entity tags and labels (WikiAnn NER), or answer (XQuAD, MLQA, and TyDi QA) directly in a generative fashion. For NER, if there are multiple entities, then they are concatenated in the order they appear, and if there are no entities then the target text is ‘‘None’’. We consider three variants of these tasks: (1) ‘‘zero-shot’’, where the model is fine-tuned only on English data, (2) ‘‘translate-train’’, adding machine translations from English into each target language, and (3) ‘‘in-language multitask’’, training on gold data in all target languages. For brevity, we refer to Hu et al. (2020) for further details on these benchmarks.
Following the original T5 recipe, we consider five model sizes: Small (M parameters), Base (M), Large (B), XL (B), and XXL (B). The increase in parameter counts compared to the corresponding T5 model variants comes from the larger vocabulary used in mT5. Note that, because mT5 is an encoder-decoder model, it has roughly twice as many parameters as correspondingly-sized encoder-only models such as XLM-R. For example, the ‘‘Large’’ variant of XLM-R has million parameters whereas mT5-Large has around billion. However, the computational cost for text classification is roughly the same: In both cases, the model processes a length- input sequence with an encoder of approximately equal size. In an encoder-only model like XLM-R, the encoder processes one additional "CLS"token, which is used to generate the representation for classification. In mT5, the decoder typically produces two additional tokens: the class label and an end-of-sequence token. Since the decoder has the same architecture (ignoring encoder-decoder attention) as the encoder, the computational cost of classification with mT5 typically amounts to the cost of processing tokens compared to for an encoder-only model. However, encoder-decoder architectures have the additional benefit of being applicable to generative tasks like abstractive summarization or dialog.
We pre-train our mT5 model variants for million steps on batches of length- input sequences, corresponding to roughly trillion input tokens total. This is the same amount of pre-training as T5 and about as much as XLM-R.
We use the same inverse square-root learning rate schedule used by T5 during pre-training, with the learning rate set to 1\big{/}\sqrt{\max(n,k)} where is the current training iteration and is the number of warm-up steps. Following the T5.1.1 recipe, we do not apply dropout during pre-training. We use the same self-supervised objective as T5, with % of tokens masked and an average noise span length of . We ablate some of these experimental details in section 4.2.
For fine-tuning, we use a constant learning rate of and dropout rate of for all tasks. We use batch size for most tasks but increased this up to in a few cases based on performance on the validation set. For early stopping, we save checkpoints every steps and choose the checkpoint with the highest validation performance.
Table 2 presents our main results, with per-language breakdowns for each task given in the appendix. Our largest model mT5-XXL exceeds state-of-the-art on all classification and QA tasks and is near SOTA on NER (69.2 vs. 70.1). Note that unlike our model, InfoXLM (Chi et al., 2020) and VECO (Luo et al., 2020) benefit from parallel training data, while X-STILTs (Phang et al., 2020) leverages labeled data from tasks similar to the target task. Overall, our results highlight the importance of model capacity in cross-lingual representation learning and suggest that scaling up a simple pre-training recipe can be a viable alternative to more complex techniques relying on LM filtering, parallel data, or intermediate tasks.
In the ‘‘translate-train’’ setting, we exceed state-of-the-art on all xtreme classification and QA tasks. For these tasks, we fine-tune on the combination of the labeled English data and machine translations thereof.We use the translation data provided by Hu et al. (2020) throughout. On the PAWS-X task, Filter used translation data from the original task instead. Switching to this data would improve our scores slightly (mT5-XXL 91.5 92.0). This allows direct comparison with both Filter (Fang et al., 2020) as well as the XLM-R baseline of Fang et al. (2020). Note that this setup differs from xtreme ‘‘translate-train’’ (Hu et al., 2020), which excludes English.
Figure 2 shows that model capacity is key to improving performance on variants of the TyDi QA GoldP task in the absence of ‘‘gold’’ multilingual data: For the smallest model, training on gold datasets (in-language multitask) achieves dramatically better performance than using weakly supervised data (translate-train) or English-only data (zero-shot), whereas the gap between these three settings is much smaller for the largest model. For our two largest models, zero-shot and translate-train performance is nearly the same, showing that machine translations of the monolingual dataset bring diminishing returns as model capacity increases. Overall, these trends point to the possibility of avoiding the costly step of annotating data in more than one language when using large models.
Massively multilingual models have been observed to underperform on a given language when compared to a similarly-sized ‘‘dedicated’’ model trained specifically for that language (Arivazhagan et al., 2019). To quantify this effect, we compare the performance of mT5 and T5 when fine-tuned on the SQuAD reading comprehension benchmark (Rajpurkar et al., 2016). The results are shown in table 3, with results for T5 reproduced from Raffel et al. (2020). While the Small and Base mT5 models fall short of their English T5 counterparts, we find that the larger models close the gap. This suggests there may be a turning point past which the model has enough capacity to effectively learn languages without significant interference effects.
2 Ablation
We run six ablations, modifying various settings, using our Large model as a baseline: (i) increase dropout to in hopes of mitigating overfitting on low-resource languages, (ii) decrease sequence length to (as was used in T5), (iii) increase the average noise span length in the pre-training objective to since we observe fewer characters per token than T5, (iv) adjust the language sampling exponent to {, } as used in MMNMT (Arivazhagan et al., 2019) and mBERT (Devlin, 2018), respectively, (v) turn off the ‘‘line length filter’’ in the mC4 data pipeline, and (vi) supplement mC4 with Wikipedia dataWe use the 2020 Wikipedia data from TensorFlow Datasets, selecting the same languages as mBERT. https://www.tensorflow.org/datasets/catalog/wikipedia from 103 languages.
The effect of these ablations on XNLI zero-shot accuracy is shown in table 4. In each case, the average XNLI score is lower than the mT5-Large baseline, justifying our chosen settings. The line length filter provides a point boost, corroborating the findings of Conneau et al. (2020) and Raffel et al. (2020) that filtering low-quality pages from Common Crawl is valuable. Increasing the language sampling exponent to has the expected effect of improving performance in high-resource languages (e.g. Russian ), while hurting low-resource languages (e.g. Swahili ), with the average effect being negative. Conversely, lowering to boosts one tail language slightly (Urdu ) but is harmful elsewhere. Detailed per-language metrics on XNLI and the results of our ablations on zero-shot XQuAD are provided in the appendix, showing similar trends.
Zero-shot generation
Since mT5 is a generative model, it can output arbitrary text predictions in a free form fashion. This is in contrast to ‘‘encoder-only’’ models like mBERT and XLM(-R) that make a prediction by either extracting it from the input or producing a class label. We found that the lack of constraints during prediction caused mT5 to sometimes have trouble generating a well-formed prediction in a language unseen during fine-tuning. Focusing on XQuAD zero-shot, we find that many of these errors are due to ‘‘accidental translation’’ into the fine-tuning language (English). In this section, we characterize this behavior and demonstrate that it can be counteracted by mixing a small amount of our multilingual pre-training task into the fine-tuning stage.
In using a generative model for span selection (as in extractive QA tasks), we hope the model learns to generate ‘‘legal’’ spans that are substrings of the provided context. However, unlike encoder-based models like BERT, this is not a hard constraint of the model. Notably, T5 learns to always output legal spans on SQuAD, suggesting this is not a major issue for generative models in simple cases.
A more challenging case for generative models is zero-shot cross-lingual span selection. Here, a pre-trained multilingual model is fine-tuned on English but tested on other languages. We want the model to generate legal non-English predictions despite having only seen English targets in fine-tuning.
In practice, while mT5 achieves SOTA on the zero-shot variants of XQuAD, MLQA and TyDi QA, illegal predictions are still a problem. For example, on zero-shot XQuAD, a non-trivial portion of mT5 mistakes are in fact illegal spans, for all model sizes (cf. fig. 4 ‘‘Baseline’’). Through inspection, we find these illegal predictions mainly fall into three categories: (i) normalization, (ii) grammatical adjustment, and (iii) accidental translation. Table 5 provides examples of each type.
Normalization indicates predictions that would be legal, except that ‘‘equivalent’’ Unicode characters have been substituted, so a legal span may be recovered through Unicode NFKC normalization. This is particularly common in Thai, Chinese and Hindi, where most mT5-XXL illegal predictions are resolved by normalization, as seen in fig. 3(b).
Grammatical adjustment involves minor morphological changes to the original text. We frequently observe these adjustments when the target span cannot stand as a well-formed answer on its own. For example, mT5-XXL’s Arabic and Russian predictions in the middle rows of table 5 are judged by native speakers as correct and grammatical answers to the posed XQuAD questions, while the gold targets are judged as ungrammatical answers. This type of illegal prediction is most common in languages with extensive grammatical case marking, such as Russian, Turkish and German.
Accidental translation involves the model translating part or all of a contextual span into English (the language of all fine-tuning data). On the one hand, it is remarkable that mT5 performs ‘‘spontaneous’’ translation despite never seeing parallel training data. On the other, as practitioners we would ideally be able to control this behavior.
We observe accidental translation across all model sizes and all XQuAD languages. The problem is most prevalent in mT5-Small and mT5-Base, where from manual inspection, half or more of the illegal predictions within each language exhibit accidental translation, with many of the illegal predictions coming from Greek and Russian, as shown in fig. 3(a). While we do observe full phrase translations, a more common occurrence is partial translation, where the model outputs a token or two of English before reverting to the correct target language. The transition may even occur mid-word, as in the prediction ‘‘chlorопласт’’, where the first half of the target ‘‘хлоропласт’’ (Russian: chloroplast) has been translated to English.
2 Preventing accidental translation
The most direct solution to avoiding accidental translation on span selection tasks would be to modify our inference procedure. As is common practice with encoder-based models, we could devise a task-specific fine-tuning mechanism that restricts the model to perform ranking over legal spans, removing the possibility of illegal predictions entirely. While this would likely improve our zero-shot metrics, it is unsatisfying for two reasons: First, it implies taking a step backward from the general text-to-text interface, as different tasks would demand different types of inference. Second, this solution won’t extend to more ‘‘open-ended’’ zero-shot generative tasks like summarization, where the legal output space can’t be easily delimited.
For these reasons, we consider a more general solution that remains within the text-to-text framework and can apply to all zero-shot generation tasks. Our motivating intuition is that the reason the model outputs English when given a non-English test input is that it has never observed a non-English target during fine-tuning. As English-only fine-tuning proceeds, the model’s assigned likelihood of non-English tokens presumably decreases, eventually reaching the point where English becomes the most likely answer to any question.
To prevent the model from ‘‘forgetting’’ how to generate other languages, we use a strategy inspired by domain/task-adaptive pre-training Howard and Ruder (2018); Gururangan et al. (2020): We simply mix in our unsupervised multilingual pre-training task during fine-tuning. A similar approach was explored by Liu et al. (2020b). We use the same mC4 task definition as in pre-training, with two adjustments: First, we remove all ‘‘sentinel’’ tokens (corresponding to non-masked spans in the input text) from the target sequence, as otherwise we observe occasional sentinels in downstream predictions. Second, we reduce the language sampling parameter from to . This produces a near-uniform distribution of languages, encouraging the model to treat all languages as equally likely.Alternatively, one could mix in unlabeled data only for a single language at a time. However, we believe this is contrary to the spirit of multilingual models and zero-shot evaluation.
With these changes, we mix a small amount of our unsupervised task (covering 101 languages) into XQuAD fine-tuning, at a ratio of just :. Figure 4 shows the results on XQuAD zero-shot error rates. The addition of even this small amount of multilingual data has a marked effect on the mT5-Small and mT5-Base models (where accidental translation was most rampant), reducing the illegal prediction rates by more than (relative), and contributing to an overall reduction in errors.
Conclusion
In this paper, we introduced mT5 and mC4: massively multilingual variants of the T5 model and C4 dataset. We demonstrated that the T5 recipe is straightforwardly applicable to the multilingual setting, and achieved strong performance on a diverse set of benchmarks. We also characterized illegal predictions that can occur in zero-shot evaluation of multilingual pre-trained generative models, and described a simple technique to avoid this issue. We release all code and pre-trained datasets used in this paper to facilitate future work on multilingual language understanding.https://goo.gle/mt5-code
We thank Melvin Johnson for tips on the translate-train procedure for xtreme and Itai Rolnick for help with infrastructure.