Pretrained Transformers Improve Out-of-Distribution Robustness (2020)

Abstract: Although pretrained Transformers such as BERT achieve high accuracy on in-distribution examples, do they generalize to new distributions? We systematically measure out-of-distribution (OOD) generalization for seven NLP datasets by constructing a new robustness benchmark with realistic distribution shifts. We measure the generalization of previous models including bag-of-words models, ConvNets, and LSTMs, and we show that pretrained Transformers’ performance declines are substantially smaller. Pretrained transformers are also more effective at detecting anomalous or OOD examples, while many previous models are frequently worse than chance. We examine which factors affect robustness, finding that larger models are not necessarily more robust, distillation can be harmful, and more diverse pretraining data can enhance robustness. Finally, we show where future work can improve OOD robustness.

## introduction the train and test distributions are often not identically distributed. such train-test mismatches occur because evaluation datasets rarely characterize the entire distribution @xcite , and the test distribution typically drifts over time @xcite . chasing an evolving data distribution is costly, and even if the training data does not become stale, models will still encounter unexpected situations at test time. accordingly, models must generalize to ood examples whenever possible, and when ood examples do not belong to any known class, models must detect them in order to abstain or trigger a conservative fallback policy @xcite . most evaluation in natural language processing (nlp) assumes the train and test examples are in-dependent and identically distributed (iid). in the iid setting, large pretrained transformer models can attain near human-level performance on numerous tasks @xcite . however, high iid accuracy does not necessarily translate to ood robustness for image classifiers @xcite , and pretrained transformers may embody this same fragility. moreover, pretrained transformers can rely heavily on spurious cues and annotation artifacts @xcite which out-of-distribution examples are less likely to include, so their ood robustness remains uncertain. in this work, we systematically study the ood robustness of various nlp models, such as word embeddings averages, lstms, pretrained transformers, and more. we decompose ood robustness into a model's ability to (1) generalize and to (2) detect ood examples @xcite . to measure ood generalization, we create a new evaluation benchmark that tests robustness to shifts in writing style, topic, and vocabulary, and spans the tasks of sentiment analysis, textual entailment, question answering, and semantic similarity. we create ood test sets by splitting datasets with their metadata or by pairing similar datasets together (section 2). using our ood generalization benchmark, we show that pretrained transformers are considerably more robust to ood examples than traditional nlp models (section 3). we show that the performance of an lstm semantic similarity model declines by over 35% on ood examples, while a roberta model's performance slightly increases. moreover, we demonstrate that while pretraining larger models does not seem to improve ood generalization, pretraining models on diverse data does improve ood generalization. to measure ood detection performance, we turn classifiers into anomaly detectors by using their prediction confidences as anomaly scores @xcite . we show that many non-pretrained nlp models are often near or worse than random chance at ood detection. in contrast, pretrained transformers are far more capable at ood detection. overall, our results highlight that while there is room for future robustness improvements, pretrained transformers are already moderately robust. ## out-of-distribution generalization in this section, we evaluate ood generalization of numerous nlp models on seven datasets and provide some upshots. a subset of results are in figures 1 and 2 . full results are in the appendix. pretrained transformers are more robust. in our experiments, pretrained transformers often have smaller generalization gaps from iid data to ood data than traditional nlp models. for instance, figure 1 shows that the lstm model declined by over 35%, while roberta's generalization performance in fact increases. for amazon, mnli, and yelp, we find that pretrained b e r t b a s e b e r t l a r g e a l b e r t b a s e a l b e r t l a r g e a l b e r t x l a r g e a l b e r t x x l a r g e 0 2 4 6 8 10 sst-2 accuracy -imdb accuracy (%) sst-2 model size vs. accuracy drop figure 3: the iid/ood generalization gap is not improved with larger models, unlike in computer vision. bert models do not reduce the generalization gap. however, in keeping with results from vision @xcite , we find that model distillation can reduce robustness, as evident in our distilbert results in figure 2 . this highlights that testing model compression methods for bert @xcite @xcite on only in-distribution examples gives a limited account of model generalization, and such narrow evaluation may mask downstream costs. ## out-of-distribution detection since ood robustness requires evaluating both ood generalization and ood detection, we now turn to the latter. without access to an outlier dataset @xcite , the state-ofthe-art ood detection technique is to use the model's prediction confidence to separate in-and out-of-distribution examples @xcite . specifically, we assign an example x the anomaly score -max y p(y | x), the negative prediction confidence, to perform ood detection. we train models on sst-2, record the model's confidence values on sst-2 test examples, and then record the model's confidence values on ood examples from five other datasets. for our ood examples, we use validation examples from 20 newsgroups (20 ng) @xcite , the english source side of english-german wmt16 and english-german multi30k @xcite , and concatenations of the premise and hypothesis for rte @xcite and snli @xcite . these examples are only used during ood evaluation not training. for evaluation, we follow past work @xcite and report the false alarm rate at 95% recall (far95). the far95 is the probability that an in-distribution example raises a false alarm, assuming that 95% of all out-of-distribution exam-ples are detected. hence a lower far95 is better. partial results are in figure 4 , and full results are in the appendix. ## conclusion we created an expansive benchmark across several nlp tasks to evaluate out-of-distribution robustness. to accomplish this, we carefully restructured and matched previous datasets to induce numerous realistic distribution shifts. we first showed that pretrained transformers generalize to ood examples far better than previous models, so that the iid/ood generalization gap is often markedly reduced. we then showed that pretrained transformers detect ood examples surprisingly well. overall, our extensive evaluation shows that while pretrained transformers are moderately robust, there remains room for future research on robustness.