Analyzing the Domain Robustness of Pretrained Language Models, Layer by Layer (2021)

Abstract: The robustness of pretrained language models(PLMs) is generally measured using performance drops on two or more domains. However, we do not yet understand the inherent robustness achieved by contributions from different layers of a PLM. We systematically analyze the robustness of these representations layer by layer from two perspectives. First, we measure the robustness of representations by using domain divergence between two domains. We find that i) Domain variance increases from the lower to the upper layers for vanilla PLMs; ii) Models continuously pretrained on domain-specific data (DAPT)(Gururangan et al., 2020) exhibit more variance than their pretrained PLM counterparts; and that iii) Distilled models (e.g., DistilBERT) also show greater domain variance. Second, we investigate the robustness of representations by analyzing the encoded syntactic and semantic information using diagnostic probes. We find that similar layers have similar amounts of linguistic information for data from an unseen domain.

## introduction pretrained language models (plms) have improved the downstream performance of many natural language understanding tasks on standard data @xcite . 1 recent works attest to the surprising out-of-the-box robustness of plms on out-of-distribution tasks @xcite @xcite . these works measure robustness in terms of the performance invariance of plms on end tasks like natural language inference @xcite , sentiment analysis @xcite , question answering @xcite , among others. however, they do not investigate the domain invariance of plm representations from different layers when presented with data from distinct domains. studying the invariance of plm representations has been useful in advancing methods for unsupervised domain adaptation. for example, in building domain adaptation models that explicitly reduce the divergence between layers of a neural network @xcite , for data selection @xcite et cetera. given the importance of plms, a glass-box study of the internal robustness of plm representations is overdue. we thus study these representations, dissecting them layer by layer, to uncover their internal contributions in domain adaptation. firstly, we use the tools of domain divergence and domain invariance, without subscribing to the performance of a model on any end task. the theory of domain adaptation @xcite , shows that reducing h-divergence between two domains results in higher performance in the target domain. many works have since adopted this concept for domain adaptation in nlp @xcite . the aim is to learn representations that are invariant to the domain, while also being discriminative of a particular task. other divergence measures such as maximum mean discrepancy (mmd) @xcite , correlational alignment (coral), central moment discrepancy (cmd) @xcite , have been subsequently defined and used @xcite . however, our community does not yet understand the inherent domain-invariance of plm representations, particularly across different layers. we ask key questions concerning domain invariance of plm representations and find surpris-ing results. first, we consider vanilla plm representations (e.g., bert) which are trained on standard data like wikipedia and books @xcite . we ask: do they exhibit domain invariance when presented with non-standard data like twitter and biomedical text? ( §3), and are lower layers of plms general and invariant compared to higher layers? to answer these, we measure the domain divergence of plm representations considering standard and non-standard data. we find that the lower layers of plms are more domain invariant compared to the upper layers ( §3.2). we find that it is similar in spirit to computer vision models where lower layers of the neural network learn gabor filters and extract edges irrespective of the image and are more transferable across tasks compared to the upper layers @xcite . while plms improve the performance of tasks on standard data, @xcite improve on domain-specific tasks by continuing to pretrain roberta on domain-specific data (dapt). we thus also ask: what happens to the domain invariance of dapt models? we find that compared to pretrained roberta, the divergence of dapt at a given layer either remains the same or increases, providing evidence of their specialization to a domain ( §3.3). lastly, given that standard plms have high training cost, we also consider the distilled model distilbert @xcite . what happens to the domain invariance in distilled model representations? we find that such representations produce more domainspecific representations across layers ( §3.4). we further analyze the robustness of representations from the perspective of the encoded syntactic and semantic information across domains ( §4). do contextualized word-level representations encode similar syntactic and semantic information even for unseen domains? we experiment with zeroshot probes where the probes are trained on standard data only. we consider syntactic tasks like pos and ner and a semantic task -coreference resolution and find that the probes indicate similar layers encode similar amount of information, even on non-standard data. in summary, our contributions are as follows: ## experimental setup the majority of current plms like bert @xcite are transformer @xcite based models. as such we focus on the representations from different transformers. they are unsupervisedly pretrained using masked language-modeling and next sentence prediction objectives, over large amounts of english standard data such as the books corpus @xcite and wikipedia articles. we consider varitaion in size: two differently sized versions of the bert model, bert base uncased -a 12 layer model and bert large uncased -a 24 layer model, both trained on lower-cased text, for comparing matters of size in representations. next, to analyze whether training with larger data scale aids in robustness, we consider roberta @xcite , which is similar to bert, but trained on a magnitude larger standard data. further, we check the effect of distillation on domaininvariance and hence, consider distilbert @xcite . finally, training of models on domain-specific data is known to increase their performance on domain-specific tasks. to analyze the effect of continued fine-tuning on invariance, we consider roberta pretrained on non-standard biomedical @xcite , and twitter @xcite domain data. we refer to this as dapt-biomed and dapt-tweet, respectively. for our experiments, we use the models hosted on the huggingface-transformer library @xcite . divergence measures. we consider three different divergence measures that are widely used in the unsupervised domain adaptation literature. correlation alignment (coral) measures the difference between covariance of features -a second-order moment. @xcite reduce the distributional distance between features for unsupervised domain adaptation (uda) in computer vision models. in contrast to coral, central moment discrepancy (cmd) considers higher-order moments of random variables to measure the distributional difference between features, and has been used in both nlp @xcite and multimodal uda @xcite . finally we consider another popular measure of measuring divergence -maximum mean discrepancy @xcite . specifically, we consider the multi-kernel gaussian variate (mk-mmd-gaussian), which ensures that the statistical two sample test for the difference in distributions have high power and low test error @xcite . we chose these measures because of their popularity, relevance and inexpensive calculations, and provide their technical details in appendix a. ## how domain-invariant are plm representations? most of the current techniques in unsupervised domain adaptation explicitly reduce the divergence between different layer representations during training @xcite . a common posthoc analysis from such works shows the reduction of domain invariance at different layers. however, they do not pay much heed to the domaininvariance of representations that already exist in such models prior to domain-adapted training. thus, we use domain divergence measures to investigate whether domain-invariance is an inherent property of pretrained transformer models, by the virtue of large-scale self-supervised learning. ## robustness of linguistic information how much linguistic information do representations from pretrained language models still encode for data from a different domain? here, we evaluate the robustness of representations in bert-base-uncased. do word-level representations from plms encode similar levels of linguistic knowledge irrespective of the domain? ## limitations our analysis using probes for different domains is intended to be an initial exploration of this topic. we inherit all the limitations of the probing classifiers highlighted by recent works @xcite @xcite . since probing trains shallow models, there exists a possibility that the performance confounds with the models learning the task rather than being diagnostic about the linguistic power of representations. it also does not indicate that the model uses this information effectively @xcite which requires further analysis. we also consider only one target domain -twitter -and analyze bert-base-uncased for our probes. the availability and varying characteristics of the dataset across domains dictates our choice. for example, compared to standard coreference, biomedical text exhibits co-referring terms across sentences in long documents. concerning the robustness of linguistic information stored in representations, @xcite analyze the syntactic and semantic information preserved by plms, both before and after fine-tuning the models on task-specific data. similarly, @xcite analyze the role of different layers in transfer learning on end tasks. different from their study, we are interested in the intrinsic invariance of the plm representations under data from different domains. ## conclusion we consider domain robustness from the perspective of domain-invariance of pretrained language model (plm) representations. we observe that the lower layers of plms are generally domaininvariant. we also find that domain variance increases on continuously pretrained (dapt) models and distilled models (distilbert). we have seen that roberta is robust, possibly by virtue of training with more data. domain adaptation methods using it should be careful in assessing the empirical benefits of their methods. as distillation becomes a mainstay method in nlp for retaining accuracy and saving training and inference costs on large models, considering distillation techniques to retain domain invariance and broadly applicable linguistic properties is of interest to the community. considering the inherent domain-invariance of plm representations at various layers is possibly useful in understanding their performance on out of domain distribution data @xcite and for domain adaptation in general. for example, since we understand that the lower layers of bert are domain-invariant compared to higher layers, we can freeze them during domain adaptation @xcite or drop them to make the models smaller and more efficient @xcite . in the future, we will incorporate this information for domain adaptation of models. we used edge probes @xcite ) to identify the linguistic information in representations of data from different domains. one has to note that edge probes consider span representations for probing and not the representations of the entire sentence. to answer is there any correlation between domain-invariance of a sentence and the amount of linguistic information contained in them?, we should consider sentence-level probes, similar to @xcite ) but, we are restricted by the lack of sentence-level probing data for different domains. we believe that this is a ripe area for future work.