What’s so special about BERT ’s layers? A closer look at the NLP pipeline in monolingual and multilingual models (2020)

Abstract: Peeking into the inner workings of BERT has shown that its layers resemble the classical NLP pipeline, with progressively more complex tasks being concentrated in later layers. To investigate to what extent these results also hold for a language other than English, we probe a Dutch BERT-based model and the multilingual BERT model for Dutch NLP tasks. In addition, through a deeper analysis of part-of-speech tagging, we show that also within a given task, information is spread over different parts of the network and the pipeline might not be as neat as it seems. Each layer has different specialisations, so that it may be more useful to combine information from different layers, instead of selecting a single one based on the best overall performance.

## introduction and background natural language processing is now dominated by transformer-based models @xcite , like bert @xcite , a model trained on predicting masked tokens and relations between sentences. bert's impact is so strong that we already talk about 'bertology' @xcite . in addition to using bert in nlp tasks and end applications, research has also been done on bert, especially to reveal what linguistic information is available in different parts of the model. this is done, e.g., investigating what bert's attention heads might be attending to @xcite , or looking at its internal vector representations using so-called probing (or diagnostic) classifiers @xcite . it has been noted that bert progressively acquires linguistic information roughly in the same the order of the classic language processing pipeline @xcite : surface features are expressed in lower layers, syntactic features more in middle layers and semantic ones in higher layers @xcite . so, for ex-ample, information on part-of-speech appears to be acquired earlier than on coreference. most work dedicated to understanding the inner workings of bert has focused on english, though non-english bert models do exist, in two forms. one is a multilingual model @xcite , which is trained on wikipedia dumps of 104 different languages. the other one is a series of monolingual berts @xcite @xcite @xcite . as expected, also the non-english monolingual bert models achieve state-of-the-art results on a variety of nlp tasks, and mostly outperform the multilingual model on common nlp tasks @xcite . nevertheless, mbert performs surprisingly well on zero-shot pos tagging and named entity recognition (ner), as well as on crosslingual model transfer @xcite . if these results imply that the inner workings of other monolingual berts and of mbert are the same as bert's is not yet known. also not known is how homogeneous layer specialisation is: through general performance of, e.g., pos tagging, we see a peak at a given layer, but we do not know how specialisation actually evolves across the whole model. this work investigates such issues. contributions using probing classifiers for four tasks on six datasets for a monolingual dutch model and for mbert, we observe that (i) these models roughly exhibit the same classic pipeline observed for the original bert, suggesting this is a general feature of bert-based models; (ii) the most informative mbert layers are consistently earlier layers than in monolingual models, indicating an inherent task-independent difference between the two models. through a deeper analysis of pos tagging, we also show that (iii) the picture of a neatly ordered nlp pipeline is not completely correct, since information appears to be more spread across layers than suggested by the performance peak at a given layer. the full source code is publicly available on github foot_0 . ## approach we run two kinds of analyses. the first is aimed at a rather high level comparison of the performance of a monolingual (dutch) bert model (bertje, de vries et al. 2019) and multilingual bert (mbert) on a variety of tasks at different levels of linguistic complexity (pos tagging, dependency parsing, named entity recognition, and coreference resolution; see section 2.2), with attention to what happens at different layers. the second is an in-depth analysis of the performance of bertje and mbert on part-of-speech tagging. the reason behind this is that looking at global performance over a given task does not provide enough information on what is actually learned by different layers of the model within that task. pos tagging lends itself well for this type of layerwise evaluation. first, because it is a low level task for which relatively little real-world knowledge is required. second, because analysis of single tags is straightforward since it is done at a token level. third, because pos tagging contains both easy and difficult cases that depend on surrounding context. some words are more ambiguous than others, and some classes are open whereas others are closed. token ambiguity may for instance be an important factor for differences between a monolingual and a multilingual model since the latter has to deal with more homographs, due to the co-presence of multiple languages. section 2.3 describes how these analyses can be performed in practice using the probes. ## analysis over all tasks first, the weights of the scalar mixing models are compared in order to see which layer combinations are most informative. these weights are tuned solely on the training data so they give no indication about layer importance for unseen data. second, we compare overall prediction scores of the probes on unseen test data for each of the tasks. ## in-depth analysis for pos tagging layer-wise task performance and scalar mixing weights give information about overall information density for a task. for pos tagging, maximum performance and largest scalar mixing weights are assigned to layers 5 to 9 for the pre-trained models, but this does not tell the whole story. indeed, probes can make different types of errors for different layers and models, because the models may clarify or lose information between layers. moreover, different examples and labels within a task may rely on information from different layers. we want to give a more thorough view of what bertje and mbert learn and whether information becomes unidentifiable between layers as well as whether bertje and mbert make the same mistakes. therefore, we evaluate the errors of the udlassy pos predictions with single layer probes. we do this analysis on pos predictions because this task stays closest to the lexical level of em-figure 3 : distributions of pos tags in the full test set as well as the filtered test set. the filtered distribution is not equivalent to the original distribution because some common tags are relatively easy. the following analysis is done on the predictions of the 13 single layer bertje probes and the 13 single layer mbert probes. pos tagging is not difficult for all tokens, so for 85% of the test data all 26 probes predict the correct tag. in order to focus on errors, we perform all analyses using the subset of the tokens that have an incorrect prediction by at least one of the probes. this amounts to 1,720 tokens. the original test data distribution as well as the filtered distribution are shown in figure 3 . note that the filtered data distribution does not correspond to the original distribution since some tags are easier to recognise than others. for instance, proper nouns are over-represented in our analysis set whereas adpositions and punctuation are underrepresented. this is not a problem since we are explicitly interested in the mistakes and difficult cases and not in overall performance. ## conclusion our results show that bertje and mbert exhibit a pipeline-like behaviour along tasks similar to what has previously been shown for english. @xcite observed that the pipeline order is roughly first pos tagging, then named entity recognition, then dependency parsing and coreference resolution. our results suggest that bertje encodes these pipeline tasks in a similar order. scalar mixing weights show that there is not a single layer that contains all important information because the weight curves show peaks and valleys. this suggests that useful task information is distributed between layers. generally, the most informative layers are located early in the second half of the pre-trained models. as an additional note, because we ran the model on different datasets for the same task, we can assess stability across datasets. we observe that pos tagging and dependency parsing results are consistent, suggesting that the probes are sensitive to the task and the embeddings, but not overly sensitive to the specific data that they are trained on. the main task differences between the monolingual bertje model and the multilingual mbert model are that bertje probes make more use of the lexical embedding layer than the mbert probes and the most important layers of bertje are mostly later layers than those of mbert. semantically rich pos tags like nouns and adjectives become harder to identify in later layers (figure 5 ) and confusions mainly happen between semantically rich open categories (figure 6 ). this suggests that semantic content is more important than pos discriminating features for final token predictions. so even if the pos abstraction is not readily present in the lexical layer nor in the final token prediction layer, pos tag information is still found in middle layer generalisations. pos tagging is a part of what the pre-trained models learn, but different tag abstractions are present in different layers. therefore, feature-based use of these models should not use the output of a single best layer. it would be better to combine the outputs of multiple or all layers in order to retrieve all learned information that is relevant for a downstream task. however, actual fine-tuning of pre-trained language models should still be a preferred approach. in sum, our results show that pipeline-like behaviour is present in both a monolingual pre-trained bert-based model as well as a multilingual model even though task-specific information is distributed between layers. we observed this for pos tagging, but it is still unclear how information within tasks is distributed in these models for other tasks. moreover, it would be interesting to investigate alternative probing strategies in order to better disentangle what pertains to the model itself from what is specific to a given probing strategy. lastly, it is an open question how well linguistic properties are embedded within large pre-trained language models for non indo-european languages.