On the evolution of syntactic information encoded by BERT ’s contextualized representations (2021)

Abstract: The adaptation of pretrained language models to solve supervised tasks has become a baseline in NLP, and many recent works have focused on studying how linguistic information is encoded in the pretrained sentence representations. Among other information, it has been shown that entire syntax trees are implicitly embedded in the geometry of such models. As these models are often fine-tuned, it becomes increasingly important to understand how the encoded knowledge evolves along the fine-tuning. In this paper, we analyze the evolution of the embedded syntax trees along the fine-tuning process of BERT for six different tasks, covering all levels of the linguistic structure. Experimental results show that the encoded syntactic information is forgotten (PoS tagging), reinforced (dependency and constituency parsing) or preserved (semantics-related tasks) in different ways along the fine-tuning process depending on the task.

## introduction adapting unsupervised pretrained language models (lms) to solve supervised tasks has become a widely spread practice in nlp, with models such as elmo @xcite and, most notably, bert @xcite , achieving state-of-the-art results in many well-known natural language understanding benchmarks like glue @xcite and squad @xcite . several studies investigate what the lms learn, how and where the learned knowledge is represented and what the best methods to improve it are; cf., e.g., @xcite . there is evidence that, among other information (such as, e.g., pos, syntactic chunks and roles @xcite @xcite , morphology in general @xcite , or sentence length @xcite ) bert deep models' vector geometry implicitly embeds entire syntax trees @xcite . however, rather little is understood about how these representations change when fine-tuned to solve downstream tasks @xcite . in this work, we aim to understand how syntax trees implicitly embedded in the geometry of deep models evolve along the fine-tuning process of bert on different supervised tasks, and shed some light on the importance of the syntactic information for those tasks. intuitively, we expect morpho-syntactic tasks to clearly reinforce the encoded syntactic information, while tasks that are not explicitly syntactic in nature should maintain it in case they benefit from syntax @xcite and lose it if they do not. in order to cover the three main levels of the linguistic description (morphology, syntax and semantics), we select six different tasks: pos tagging, constituency parsing, syntactic dependency parsing, semantic role labeling (srl), question answering (qa) and paraphrase identification. the first three inherently deal with (morpho-)syntactic information while the latter three, which traditionally draw upon the output of syntactic parsing @xcite @xcite , deal with higher level, semantic information. almost all of our experiments are on english corpora; one is on multilingual dependency parsing. ## related work bert has become the default baseline in nlp, and consequently, numerous studies analyze its linguistic capabilities in general @xcite , and its syntactic capabilities in particular (linzen and baroni, 2020). even if syntactic information is distributed across all layers @xcite , bert captures most phrase-level information in the lower layers, followed by surface features, syntactic features and semantic features in the intermediate and top layers @xcite @xcite . the syntactic structure captured by bert adheres to that of the universal dependencies @xcite ; different syntactic and semantic relations are captured by self-attention patterns @xcite @xcite , and it has been shown that full dependency trees can be decoded from single attention heads @xcite . bert performs remarkably well on subject-verb agreement @xcite , and is able to do full parsing relying only on pretraining architectures and no decoding @xcite , surpassing existing sequence labeling parsers on the penn treebank dataset @xcite and on the end-to-end universal dependencies corpus for english @xcite . it can generally also distinguish good from bad completions and robustly retrieves noun hypernyms, but shows insensitivity to the contextual impacts of negation @xcite . different supervised probing models have been used to test for the presence of a wide range of linguistic phenomena in the bert model @xcite @xcite @xcite . hewitt and manning (2019)'s structural probe shows that entire syntax trees are embedded implicitly in bert's vector geometry. extending their work, @xcite show that multilingual bert recovers syntactic tree distances in languages other than english and learns representations of syntactic dependency labels. regarding how fine-tuning affects the representations of bert, @xcite found a significant divergence between the final representations of models fine-tuned on different tasks when using the structural probe of @xcite , while @xcite concluded that fine-tuning is conservative and does not lead to catastrophic forgetting of linguistic phenomenawhich our experiments do not confirm. however, we find that the encoded syntactic information is forgotten, reinforced or preserved differently along the fine-tuning process depending on the task. ## experimental setup we study the evolution of the syntactic structures discovered during pretraining along the fine-tuning of bert-base (cased) @xcite foot_0 on six different tasks, drawing upon the structural probe of @xcite . 2 we fine-tune the whole model on each task outlined below for 3 epochs, with a learning rate of 5e -5 , saving 10 evenly-spaced checkpoints per epoch. the output of the last layer is used as input representation for the classification components of each task. to mitigate the variance in performance induced by weight initialization and training data order @xcite , we repeat this process 5 times per task with different random seeds and average results. pos tagging. we fine-tune bert with a linear layer on top of the hidden-states output for token classification. 3 dataset: universal dependencies corpus for english (ud 2.5 en @xcite ). ## evolution of syntax trees hewitt and manning (2019)'s structural probe evaluates how well syntax trees are embedded in a linear transformation of the network representation space, performing two different evaluations: i) tree distance evaluation, in which squared l2 distance encodes the distance between words in the parse tree, and ii) tree depth evaluation, in which squared l2 norm encodes the depth of the parse tree. using their probe, hewitt and manning show that the 7th layer of bert-base is the layer that encodes more syntactic information. therefore, to analyze the evolution of the encoded syntax trees, we train the probes on the 7th layer of the different checkpoint models generated along the fine-tuning process of each task. foot_4 ## conclusions we show that fine-tuning is not always a conservative process. rather, the syntactic information initially encoded in the models is forgotten (pos tagging), reinforced (parsing) or preserved (semanticsrelated tasks) in different (sometimes unexpected) ways along the fine-tuning, depending on the task. thus, we expected that morpho-syntactic tasks clearly reinforce syntactic information. however, pos tagging forgets it, which, on the other side, can also be justified linguistically (cf. section 4.1). in contrast, tasks closer to semantics mostly preserve the syntactic knowledge initially encoded. this interesting observation reinforces recent findings that models benefit from explicitly injecting syntactic information for such tasks @xcite . overall, we observed that morpho-syntactic tasks experiment substantial changes in the initial phases, while semantic-related tasks maintain a more stable trend, highlighting the importance of syntactic information in tasks that are not explicitly syntactic in nature @xcite . these observations lead to some interesting insights, but also to further questions; for instance: can we find a specific set of probes covering different linguistic phenomena to be used as a pretraining stopping criteria? would this lead to an improvement in the encoding of the linguistic information on pretrained models? pos tagging reaches a 0.95 accuracy in only two checkpoints, ending up with a 0.97 on the last checkpoint (figure 5a ). it shows a loss of accuracy for the four probing metrics all along the fine-tuning process, especially noticeable for uuas (figure 5b ) and root % (figure 5d ), suggesting that syntactic information is of less relevance to pos tagging than could be intuitively assumed. the loss is less pronounced on depth-related metrics, maybe due to the fact that the root of the sentence usually corresponds to the verb, which may also help in identifying the pos of surrounding words. dependency parsing with ptb sd shows a steep learning curve (figure 6a ), reaching a performance of 0.90 las on the third checkpoint, up to a final 0.94. all four probing metrics show an important improvement in the first fine-tuning step (figures 6b , 6c , 6d and 6e), which is preserved along the rest of the process. as the task heavily relies on syntactic information, this improvement intuitively makes sense. compared to the result of the other dependency parsing experiments, this one show bigger improvements because the probing is trained on the same dataset. dependency parsing with en ud ewt shows a shallower learning curve than other experiments (figure 7a ), as the dataset is significantly smaller than the multilingual and ptb and therefore the models see less examples per checkpoint, ending up with a high performance of 0.9. after an initial drop (probably due to the dataset size, as mentioned before), the probing metrics show a big improvement in the first fine-tuning steps, preserved along the rest of the process (figures 7b , 7c , 7d and 7e). as the task heavily relies on syntactic information, this improvement intuitively makes sense. multilingual dependency parsing shows a steeper learning curve than dependency parsing with en ud ewt, as it is trained with a larger dataset (figure 8a ), reaching a performance of 0.87 in las. all four probing metrics show a big improvement in the first fine-tuning step, preserved along the rest of the process (figures 8b , 8c , 8d and 8e). as the task heavily relies on syntactic information, this improvement intuitively makes sense. question answering fine-tuning quickly reaches an f1 score of 0.73 on the first step, which is further improved to 0.88 in the last checkpoint (figure 10a ). all four probing metrics show a clear loss trend (figures 10b, 10c, 10d and 10e). the loss is specially noticeable for uuas and root %, and more stable for the spearman correlations, suggesting that even if there is a loss of information it does not impact the distance and depth orderings. paraphrase identification fine-tuning starts with an f1 score of 0.81 on the first step that is further improved to 0.90 in the last checkpoint (figure 11a ). regarding accuracy, after reaching 0.69 on the first checkpoint it follows a shallower curve to a final 0.86 (figure 11b ). all four probing metrics follow a loss trend (figures 11c , 11d , 11e and 11f). the loss is specially noticeable for uuas and root %, and more stable for the spearman correlations, suggesting that even if there is a loss of information it does not impact the distance and depth orderings. semantic role labeling fine-tuning follows a steep curve for f1, quickly reaching an f1 score of 0.71 on the first step that is further improved to 0.82 in the last checkpoint (figure 12a ). all four probing metrics follow a loss trend (figures 12b , 12c , 12d and 12e). the loss is specially noticeable for uuas, which initially loses around 12 uuas points, and more stable for the spearman correlations, suggesting that even if there is a loss of information it does not impact the distance and depth orderings.