How Do BERT Embeddings Organize Linguistic Knowledge? (2021)

Abstract: Several studies investigated the linguistic information implicitly encoded in Neural Language Models. Most of these works focused on quantifying the amount and type of information available within their internal representations and across their layers. In line with this scenario, we proposed a different study, based on Lasso regression, aimed at understanding how the information encoded by BERT sentence-level representations is arrange within its hidden units. Using a suite of several probing tasks, we showed the existence of a relationship between the implicit knowledge learned by the model and the number of individual units involved in the encodings of this competence. Moreover, we found that it is possible to identify groups of hidden units more relevant for specific linguistic properties.

## introduction the rise of contextualized word representations @xcite has led to significant improvement in several (if not every) nlp tasks. the main drawback of these approaches, despite the outstanding performances, is the lack of interpretability. in fact, high dimensional representations do not allow for any insight of the type of linguistic properties encoded in these models. therefore this implicit knowledge can only be determined a posteriori, by designing tasks that require a specific linguistic skill to be tackled @xcite or by investigating to what extent certain information is encoded within contextualized internal representations, e.g. defining probing classifier trained to predict a variety of language phenomena @xcite @xcite . in line with this latter approach and with recent works aimed at investigating how the information is arranged within neural models representations @xcite @xcite , we proposed an in-depth investigation aimed at understanding how the information encoded by bert is arranged within its internal representation. in particular, we defined two research questions, aimed at: (i) investigating the relationship between the sentence-level linguistic knowledge encoded in a pre-trained version of bert and the number of individual units involved in the encoding of such knowledge; (ii) understanding how these sentence-level properties are organized within the internal representations of bert, identifying groups of units more relevant for specific linguistic tasks. we defined a suite of probing tasks based on a variable selection approach, in order to identify which units in the internal representations of bert are involved in the encoding of similar linguistic properties. specifically, we relied on a wide range of linguistic tasks, which resulted to successfully model different typology of sentence complexity @xcite , from very simple features (such as sentence length) to more complex properties related to the morphosyntactic and syntactic structure of a sentence (such as the distribution of specific dependency relations). the paper is organized as follows. in sec. 2 we present related work, then we describe our approach (sec. 3), with a focus on the model and the data used for the experiments (sec. 3.1) and the set of probing tasks (sec. 3.2). experiments and results are discussed in sec. 4 and 5. to conclude, we summarize the main findings of our work in sec. 6. ## related work in the last few years, a number of recent works have explored the inner mechanism and the linguistic knowledge implicitly encoded in neural language models (nlms) @xcite . the most common approach is based on the development of probes, i.e. supervised models trained to predict simple linguistic properties using the contextual word/sentence embeddings of a pre-trained model as training features @xcite @xcite . these latter studies demonstrated that nlms are able to encode a wide range of linguistic information in a hierarchical manner @xcite @xcite and even to support the extraction of dependency parse trees @xcite . for instance, @xcite quantified differences in the transferability of individual layers between different models, showing that higher layers of rnns (elmo) are more task-specific (less general), while transformer layers (bert) do not exhibit this increase in task-specificity. other works also investigated the importance of individual neurons within models representations @xcite @xcite . @xcite proposed two methods, linguistic correlations analysis and cross-model correlation analysis, to study whether specific dimensions learned by end-to-end neural models are responsible for specific properties. for instance, they showed that open class categories such as verbs and location are much more distributed across the network compared to closed class categories (e.g. coordinating conjunction) and also that the model recognizes a hierarchy of linguistic proprieties and distributes neurons based on it. @xcite , instead, proposed a detailed study of the inner mechanism of number tracking in lstms at single neuron level, showing that long distance number information (from the subject to the verb) is largely managed by two specific units. differently from those latter work, our aim was to combine previous approaches based on probes and on the study on individual units in order to propose an in-depth investigation on the organization of linguistic competence within nlm contextualized representations. ## approach to study how the information used by bert to implicitly encode linguistic properties is arranged within its internal representations, we relied on a variable selection approach based on lasso regression @xcite , which aims at keeping as few non-zero coefficients as possible when solving specific regression tasks. our aim was to identify which weights within sentence-level bert internal representations can be set to zero, in order to understand the relationship between hidden units and linguistic competence and whether the information needed to perform similar linguistic tasks is encoded in similar positions. we relied on a suite of 68 sentence-level probing tasks, each of which corresponds to a specific linguistic feature capturing characteristics of a sentence at different levels of granularity. in particular, we defined a lasso regression model that takes as input layer-wise bert representations for each sentence of a gold standard universal dependencies (ud) @xcite english dataset and predicts the actual value of a given sentence-level feature. lasso regression consists in adding an l 1 penalization to the usual ordinary least square loss. to do so, one of the most relevant parameters is λ, which tunes how relevant the l 1 penalization is for the loss function. we performed a grid search with cross validation for each feature-layer pair, in order to identify the best suited value for λ according to each task. specifically, our goal was to find the most suited value for seeking the best performance when having as few non-zero coefficients as possible. ## linguistic competence and bert units as a first analysis, we investigated the relationship between the implicit linguistic properties encoded in the internal representations of bert and the number of individual units involved in the encoding of these properties. figure 1 and 2 report layerwise r 2 results for all the probing tasks along with the number of non-zero coefficients obtained with the sentence representations computed with the [cls] token and the mean-pooling strategy respectively. as a first remark, we can notice that the mean-pooling method proved to be the best one for almost all the probing features across the 12 layers. moreover, in line with @xcite , we noticed that there is high variability among different tasks, whereas less variation occurs among the model layers. in general, we observe that best scores are related to features belonging to raw text and vocabulary proprieties, such as sentence length and type/token ratio. nevertheless, bert representations implicitly encode information also related to more complex syntactic features, such as the order of the subject (subj pre) or the distribution of several dependency relations (e.g. dep dist det, dep dist punct). interestingly, the knowledge about pos differs when we consider more granular distinctions. for instance, within the broad categories of verbs and nouns, worse predictions were obtained by sub-specific classes of verbs based on tense, person and mood features (see especially past participle, xpos dist vbn). similarly, within the verb predicate structure properties, we observe that lower r 2 scores were obtained by features related to sub-categorization information about verbal predicates, such as the distribution of verbs by arity (verbal arity *). focusing instead on the relationship between r 2 scores and number of non-zero coefficients, we can notice that although best scores are achieved at lower layers (between layers 12 and 8 for both configurations), the highest number of non-zero coefficients occurs instead at layers closer to the output. this is particularly evident for the results achieved using the [cls] token, for which we observe a continuous increase across the 12 layers in the number of units used by the the probing models. for both configurations, features more related to the structure of the whole syntactic tree are those for which less units were set to zero during regression (e.g. max links len, parse depth, n prepositional chains), while properties belonging to word-based properties (i.e. features related to pos and dependency labels) were predicted relying on less units. moreover, we can clearly notice that features related to specific pos and dependency relationships are also those that gained less units through the 12 layers (e. g. xpos dist ., xpos dist aux). on the contrary, features belonging to the structure of the syntactic tree tend to acquire more non-zero units as the output layer is approached. this is particularly evident for the linguistic features predicted using sentence representations computed using the [cls] token (e.g. subj pre, parse depth, n prepositional chains). we believe this is due to the fact that the interdependence between different units in each representation tend to increase across layers, thus making the information less localized especially for those features that belong to the whole structure of the syntactic tree. this is coherent with the fact that using the mean-pooling strategy a higher number of non-zero coefficients was preserved also in the very first input layers, suggesting that this strategy increases the interdependence between each unit and makes the extraction of localized information more complex. in order to focus more closely on the relationship between r 2 scores and non-zero units, we reported in figures 3a and 3b average r 2 scores versus average number of non-zero coefficients, along with the line of best fit, for each layer and according to the [cls] token and to the mean-pooling strategy respectively. interestingly, for both [cls] and mean-pooling representations, r 2 scores tend to improve as the number of non-zero coefficients increases. moreover, when considering sentence representations computed with the [cls] token, this behaviour becomes more pronounced as the output layer is reached. this is in line with what we already noticed, namely that the interdependence between different units tend to increase across layers, especially when taking into account representations extracted without using a mean-pooling strategy. in order to investigate more in depth the behaviour of bert hidden units when solving the probing tasks, we focused more closely at how the different units in the internal representations are kept and lost across subsequent layers. figure 4 reports the average number of non-zero coefficients in a layer that are set to zero in the following one (4a), the average number of zero coefficients in a layer that are set to non-zero in the following one (4b) and the average value of the difference between the number of non-zero coefficients at pairs of consecutive layers (4c). as it can be observed, there is high coherence between each layer and its subsequent one, meaning that the variation in the number of selected coefficient is stable (4c). however, the first two plots also show that there is a higher variation when considering non-zero coeffi-cients in the same positions between pairs of layers. this underlines the fact that the information is not localized within bert's internal representations, since the algorithm shows a degree of freedom in which units can be zeroed and which cannot. in figure 5 we report instead how many times each individual unit in the [cls] (5a) and meanpooling (5b) internal representations has been kept non-zero when solving the 68 probing tasks for all the 12 bert layers (816 regression task). in general, we can observe that the regression tasks performed using sentence-level representations obtained with the mean-pooling strategy tend to use more hidden units with respect to the [cls] ones. it is also interesting to notice that there is a highly irregular unit (number 308) that has been kept different from zero in a number of tasks and layers much higher than the average. this could suggest that this unit is particularly relevant for encoding almost all the linguistic properties devised in our probing tasks. (a) (b) (c) figure 4: in (a) the average number of non-zero coefficients in a layer that are set to zero in the following one (average number of dropped coefficients), in (b) the average number of zero coefficients in a layer that are set to non-zero in the following one (average number of gained coefficients) and in (c) the value of the difference between the number of non-zero coefficients at pairs of consecutive layers (average number of changed coefficients). once we have investigated the relationship between the linguistic knowledge implicitly encoded by bert and the number of individual units involved in it, we verified whether we can identify groups of units particularly relevant for specific probing tasks. to this end, we clustered the 68 probing features according to the weights assigned by the regression models to each bert hidden unit. specifically, we perform hierarchical clustering using correlation distance as distance metric. figure 6 and 7 report the hierarchical clustering obtained with the [cls] and mean-pooling internal representations at layers 12, 8 and 1. we chose layers 12 and 1 in order to study differences of the clustering of linguistic features taking into account the representations that were more distant and more closer to the language modeling task respectively, while layer 8 was chosen since it was the layer after which bert's representations tend to lose their precision in encoding our set of linguistic properties. as a general remark, we can notice that, despite some variations, the linguistic features are organized in a similar manner across the tree layers and for both the configuration. this is to say that, despite the number of non-zero coefficients varies significantly between layers and according to the strategy for extracting the internal representations, the way in which linguistic properties are arranged within bert embeddings is quite consistent. this suggests that there is a coherent organization of linguistic features according to non-zero coefficients that is independent from the layer and the aggregation techniques taken into account. focusing on specific groups of features, we observe that, even if the traditional division with respect to the linguistic annotation levels (see ## conclusions in this paper we proposed an in-depth investigation aimed at understanding how bert embeddings encode and organize linguistic competence. relying on a variable selection approach applied on a suite of 68 probing tasks, we showed the existence of a relationship between the implicit linguistic knowledge encoded by the nlm and the number of individual units involved in the encoding of this knowledge. we found that, according to the strategy for obtaining sentence-level representations, the amount of hidden units devised to encode linguistic properties varies differently across bert layers: while the number of non-zero units used in the mean-pooling strategy remains more or less constant across layers, the [cls] representations show a continuous increase in the number of used coefficients. moreover, we noticed that this behaviour is particularly significant for linguistic properties related to the whole structure of the syntactic tree, while features belonging to pos and dependency tags tend to acquire less non-zero units across layers. finally, we found that it is possible to identify groups of units more relevant for specific linguistic tasks. in particular, we showed that clustering our set of sentence-level properties according to the weights assigned by the regression models to each bert unit we can identify clusters of features referable to the same linguistic phenomena and this, despite some variations, is true for both the configurations and for all the bert layers.