Paper commentary
RoBERTa: A Robustly Optimized BERT Pretraining Approach
- Problem Gains reported for later pretraining methods are hard to attribute, because BERT-style studies differ in training data size, batch size and length of training.
- Method Re-runs BERT pretraining with controlled changes to masking, input packing, batch size, tokenization, data and training length, then combines the changes into RoBERTa.
- Results Reached 88.5 on the GLUE leaderboard with an ensemble of single-task models, and 83.2 RACE test accuracy for a single model.
Why BERT comparisons are hard to read
Pretraining methods such as ELMo, GPT, BERT, XLM and XLNet have produced large gains, but it is often unclear which parts of each method cause them. Compute cost limits how much tuning a group can afford, and the pretraining corpora differ in size from one study to another, which weakens direct comparison.
This study takes BERT as the reference point and re-runs its pretraining while keeping the model architecture fixed. The authors conclude that BERT was undertrained and propose RoBERTa, a retrained recipe that they say can match or exceed the post-BERT methods they compare against.
The recipe has four changes: longer training with bigger batches over more data, removal of the next sentence prediction objective, training on longer sequences, and a masking pattern that changes during training. A new news corpus, CC-NEWS, is also collected, so that the effect of training set size can be controlled.
The BERT pretraining setup being reused
BERT joins two text segments into one sequence, with special tokens marking the start, the boundary between segments and the end. The combined length is kept below T, the parameter that sets the maximum sequence length during training.
Masked language modeling selects 15% of the input tokens; of those, 80% are replaced with the mask token, 10% are left unchanged and 10% are replaced with a random vocabulary token. The loss is a cross-entropy over the masked positions. In the original code the masks were drawn once and reused, although duplicated data meant that the same sentence did not always receive the same mask.
The second objective, next sentence prediction, is a binary task: consecutive sentences form positive pairs and segments from different documents form negative pairs, with both sampled with equal probability. The objective is meant to help tasks such as Natural Language Inference, which require reasoning about the relation between two sentences.
The learning rate warms up over the first 10,000 steps to a peak of 1e-4 and then decays linearly. Training runs for 1,000,000 updates, each on a mini-batch of 256 sequences with a maximum length of 512 tokens.
Reimplementation, corpora and benchmarks
The authors reimplement BERT in FAIRSEQ and keep the original optimization settings, except that the peak learning rate and the number of warmup steps are tuned separately for each setting. They also tune the Adam epsilon term, which they found affects stability, and set beta2 to 0.98 for large-batch training. Sequences are capped at 512 tokens, short sequences are not injected, and only full-length sequences are used.
Training runs with mixed precision on DGX-1 machines with eight 32GB Nvidia V100 GPUs.
Five English corpora totaling over 160GB of uncompressed text are considered, starting from BOOK CORPUS and English WIKIPEDIA at 16GB. CC-NEWS contains 63 million English news articles crawled between September 2016 and February 2019, at 76GB after filtering. OPEN WEBTEXT is 38GB and STORIES is 31GB. Yang et al. report 13GB for the same BERT data after cleaning, which the authors attribute to differences in how the Wikipedia data was cleaned.
GLUE is a collection of nine datasets with training and development splits and a leaderboard that scores private test data. For the replication study, development results are reported after single-task finetuning. SQuAD is evaluated in two versions, V1.1, where every context contains an answer, and V2.0, where some questions are unanswerable.
RACE has more than 28,000 passages and nearly 100,000 questions from Chinese English examinations, and each question has four candidate answers.
Static versus dynamic masking
The original BERT code masked each sequence once during preprocessing, so the model saw a single static mask. To vary the masks, the training data was duplicated 10 times, so each sequence was masked in 10 different ways across 40 epochs, and each individual mask was seen four times.
Dynamic masking generates the masking pattern every time a sequence is fed to the model. The authors expect this to matter more when pretraining runs for more steps or uses larger datasets.
Table 1 compares the published BERT BASE values with the authors' static and dynamic runs, which are medians over five random initializations. On MNLI-m accuracy, static reached 84.3 and dynamic 84.0, against 84.3 published. On SST-2 accuracy, static reached 92.5 and dynamic 92.9, against 92.8 published.
The static-masking reimplementation performs similarly to the original BERT, and dynamic masking is comparable to or slightly better than static masking. The MNLI-m score is slightly lower under dynamic masking. The authors nonetheless adopt dynamic masking for the remaining experiments because of its efficiency benefits.
Input packing and the next sentence prediction loss
The original format packs two segments, drawn from the same document or from different documents, and trains with NSP on top of masked language modeling. Devlin et al. observe that removing NSP degrades QNLI, MNLI and SQuAD 1.1, while more recent work has questioned whether the NSP loss is necessary.
SEGMENT-PAIR+NSP follows the original format, with segments that may each contain several sentences and a total under 512 tokens. SENTENCE-PAIR+NSP uses pairs of single sentences and raises the batch size so that the total token count stays similar. FULL-SENTENCES packs contiguous full sentences up to 512 tokens, may cross document boundaries with an extra separator token, and drops the NSP loss.
DOC-SENTENCES is built like FULL-SENTENCES but stops at document boundaries, so its batch size varies, and it also drops the NSP loss.
Table 2 shows SENTENCE-PAIR+NSP below SEGMENT-PAIR+NSP on every column: SQuAD 1.1/2.0 of 88.7/76.2 against 90.4/78.7, MNLI-m of 82.9 against 84.0, SST-2 of 92.1 against 92.9 and RACE of 63.0 against 64.2. The authors hypothesize that single sentences prevent the model from learning long-range dependencies.
Without NSP, DOC-SENTENCES reached 90.6/79.7 on SQuAD, 84.7 on MNLI-m, 92.7 on SST-2 and 65.6 on RACE, and FULL-SENTENCES reached 90.4/79.1, 84.7, 92.5 and 64.8. Against the 90.4/78.7, 84.0, 92.9 and 64.2 of SEGMENT-PAIR+NSP, removing NSP matches or slightly improves most scores, though SST-2 is slightly lower in both no-NSP rows. The authors suggest the original BERT implementation may have removed only the loss term while keeping the SEGMENT-PAIR input format.
DOC-SENTENCES performs slightly better than FULL-SENTENCES, but its variable batch sizes make comparison with related work harder, so FULL-SENTENCES is used in the remaining experiments.
Large batches at equal compute
Earlier neural machine translation work reports that very large mini-batches can speed optimization and raise end-task scores when the learning rate is increased, and that BERT is also amenable to large-batch training.
Gradient accumulation sums gradients over several mini-batches before each update, so the larger batches can be obtained without large-scale parallel hardware.
Table 3 reports held-out perplexity of 3.99 at batch size 256, 3.68 at 2K and 3.77 at 8K, with learning rates of 1e-4, 7e-4 and 1e-3 tuned for each setting. MNLI-m accuracy is 84.7, 85.2 and 84.6, and SST-2 accuracy is 92.7, 92.9 and 92.8 for the same three settings. Both larger batches give lower perplexity than batch size 256, although 8K is higher than 2K.
The authors use batches of 8K sequences in later experiments because such batches are easier to parallelize across machines.
Byte-level BPE vocabulary
Byte-Pair Encoding is a hybrid of character and word representations that builds subword units by statistical analysis of the training corpus. Vocabularies usually range from 10K to 100K subword units, and unicode characters can take up a large share of that budget when the corpora are large and diverse.
Byte-level BPE uses bytes rather than unicode characters as base units, so a vocabulary of about 50K units can encode any input without unknown tokens. The original BERT used a character-level BPE vocabulary of 30K units learned after heuristic tokenization, whereas the authors use the byte-level vocabulary without extra preprocessing.
Early experiments showed only slight differences, with the byte-level BPE slightly worse on some tasks; the authors judge the universal encoding worth that cost and leave a detailed comparison to future work.
Combining the changes and scaling data and steps
RoBERTa combines dynamic masking, FULL-SENTENCES without NSP, large mini-batches and a larger byte-level BPE vocabulary. The authors also vary the data volume and the number of passes, since XLNet uses nearly 10 times more data than BERT, with a batch eight times larger for half as many steps, so four times as many sequences.
To separate these factors from the training objective, RoBERTa follows the BERT LARGE architecture, with 24 layers, hidden size 1024, 16 attention heads and 355M parameters. It is first pretrained for 100K steps on a corpus comparable to BOOK CORPUS plus WIKIPEDIA, and this pretraining used 1024 V100 GPUs for about one day.
In Table 4, the first RoBERTa row, trained on 16GB with batch size 8K for 100K steps, reaches 93.6/87.3 on SQuAD, 89.0 on MNLI-m and 95.3 on SST-2. The BERT LARGE row, trained on 13GB with batch size 256 for 1M steps, reaches 90.9/81.8, 86.6 and 93.7. The two rows differ in batch size and step count as well as in recipe, so the comparison bundles several changes.
Adding the 160GB of text with the same 8K batches and 100K steps gives 94.0/87.7, 89.3 and 95.6. Training to 300K steps gives 94.4/88.7, 90.0 and 96.1, and 500K steps gives 94.6/89.4, 90.2 and 96.4. XLNet LARGE, trained on 13GB with batch size 256 for 1M steps, reaches 94.0/87.8, 88.4 and 94.4, and with 126GB at batch size 2K for 500K steps reaches 94.5/88.8, 89.8 and 95.6.
The 300K and 500K step models outperform XLNet LARGE across most tasks.
GLUE: development and leaderboard results
The reported development value is the median over five random initializations, without ensembling. For the test leaderboard, the authors use ensembles of five to seven single-task models per task, starting RTE, STS and MRPC from the MNLI single-task model.
In Table 5, RoBERTa's development scores are 90.2/90.2 on MNLI, 94.7 on QNLI, 92.2 on QQP, 86.6 on RTE, 96.4 on SST, 90.9 on MRPC, 68.0 on CoLA, 92.4 on STS and 91.3 on WNLI. Where BERT LARGE and XLNet LARGE report values, RoBERTa is higher; for example BERT LARGE scores 70.4 on RTE and 60.6 on CoLA, and XLNet LARGE scores 83.8 and 63.6. RoBERTa uses the same masked language modeling objective and architecture as BERT LARGE, which the authors say raises questions about the weight of architecture and objective compared with dataset size and training time.
On the test leaderboard, the RoBERTa ensemble reaches an average of 88.5, against 88.4 for XLNet and 87.6 for MT-DNN, as of July 25, 2019.
For QNLI the test submission uses a pairwise ranking formulation, while the development results use pure classification for comparability with BERT. For WNLI the authors use the reformatted SuperGLUE data, a margin ranking loss and spaCy-generated candidate noun phrases, but this formulation can only use the positive training examples, which excludes over half of the provided training examples.
SQuAD without additional data
Unlike BERT and XLNet, RoBERTa is finetuned only on the provided SQuAD training data, and it uses a single learning rate for all layers where XLNet uses layer-wise rates. V1.1 uses the same span prediction as BERT, while V2.0 adds a binary classifier for answerability whose loss is summed with the span loss, and span predictions are made only for pairs classified as answerable.
RACE as multiple-choice classification
RACE has longer contexts than other popular reading comprehension datasets, and a large share of its questions require reasoning. Each candidate answer is concatenated with the question and passage, each sequence is encoded, and the resulting [CLS] representations pass through a fully connected layer that predicts the correct answer.
On the RACE test set, the single RoBERTa model reaches 83.2 accuracy, with 86.5 on middle school questions and 81.3 on high school questions. XLNet LARGE reaches 81.7, with 85.4 and 80.2, and BERT LARGE reaches 72.0, with 76.6 and 70.1, as reported in the cited prior work and listed as of July 25, 2019.
Position among pretraining methods
Pretraining has used language modeling, machine translation and masked language modeling objectives, and many recent methods finetune a model for each end task after pretraining it. Newer methods add multi-task finetuning, entity embeddings, span prediction or variants of autoregressive pretraining, and performance is typically improved by bigger models trained on more data.
The authors' goal is to replicate, simplify and tune BERT training so that it serves as a reference point for comparing these methods.
Limitations
Architectural changes, including larger architectures, were not studied and are left to future work. Data size and diversity were increased together in the main experiments, so their separate contributions were not isolated.
Some cross-paper comparisons differ in data, since the BERT corpus is reported at 13GB by Yang et al. and the RoBERTa rows in Table 4 use 16GB with batch size 8K.
The WNLI formulation uses only positive examples and excludes over half of the provided training examples.
Leaderboard results rely on ensembles of single-task models and on task-specific formulations for QNLI and WNLI, so they are not direct single-model comparisons.
Paper info
- Authors
- Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, Veselin Stoyanov
- Venue
- arXiv · Preprint
- First published
- 2019-7-26
- Added
- 2026-10-20
- Updated
- 2019-7-26
- Version
- v1
- arXiv
- 1907.11692
- Category
- cs.CL
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, Veselin Stoyanov (2019). RoBERTa: A Robustly Optimized BERT Pretraining Approach. arXiv:1907.11692v1. https://arxiv.org/abs/1907.11692v1
BibTeX
@misc{liu2019roberta,
title = {{RoBERTa: A Robustly Optimized BERT Pretraining Approach}},
author = {Yinhan Liu and Myle Ott and Naman Goyal and Jingfei Du and Mandar Joshi and Danqi Chen and Omer Levy and Mike Lewis and Luke Zettlemoyer and Veselin Stoyanov},
year = {2019},
eprint = {1907.11692},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1907.11692v1}
}