Can BERT eat R u C o LA ? Topological Data Analysis to Explain (2023)

Abstract: This paper investigates how Transformer language models (LMs) fine-tuned for acceptability classification capture linguistic features. Our approach is based on best practices of topological data analysis (TDA) in NLP: we construct directed attention graphs from attention matrices, derive topological features from them and feed them to linear classifiers. We introduce two novel features, chordality and the matching number, and show that TDA-based classifiers outperform fine-tuning baselines. We experiment with two datasets, CoLA and RuCoLA, in English and Russian, which are typologically different languages. On top of that, we propose several black-box introspection techniques aimed at detecting changes in the attention mode of the LM’s during fine-tuning, defining the LM’s prediction confidences, and associating individual heads with fine-grained grammar phenomena. Our results contribute to understanding the behaviour of monolingual LMs in the acceptability classification task, provide insights into the functional roles of attention heads, and highlight the advantages of TDA-based approaches for analyzing LMs.We release the code and the experimental results for further uptake.

## introduction language modelling with transformer @xcite has become a standard approach to acceptability judgements, providing results on par with the human baseline @xcite . the pre-trained encoders and bert, in particular, were proven to have an advantage over other models, especially when judging the acceptability of sentences with long-distance dependencies @xcite . research examining linguistic knowledge of bert-based language models (lms) revealed that: (1) individual attention heads can store syntax, semantics or both kinds of linguistic information @xcite , (2) vertical, diagonal and block attention patterns could frequently repeat across the layers @xcite , and (3) fine-tuning affects the linguistic features encoding tending to lose some of the pre-trained model knowledge @xcite . however, less attention has been paid to examining the grammatical knowledge of lms in languages other than english. the existing work devoted to the cross-lingual probing showed that grammatical knowledge of transformer lms is adapted to the downstream language; in the case of russian, the interpretation of results cannot be easily explained @xcite . however, lms are more insensitive towards granular perturbations when processing texts in languages with free word order, such as russian @xcite . in this paper, we probe the linguistic features captured by the transformer lms, fine-tuned for acceptability classification in russian. following recent advances in acceptability classification, we use the russian corpus of linguistic acceptability (rucola) @xcite , covering tense and word order violations, errors in the construction of subordinate clauses and indefinite pronoun usage, and other related grammatical phenomena. we provide an example of an unacceptable sentence from rucola with a morphological violation in the pronoun usage: a possessive reflexive pronoun 'svoj' (oneself's/own) instead of the 3rd person pronoun. ## methodology we follow @xcite and treat the la task as a supervised classification problem. we finetune transformer lms to approximate the function that maps an input sentence to a target class: acceptable or unacceptable. ## conclusion in this paper, we adopt and improve methods for acceptability classification by using best practices from topological data analysis (tda). we show-case the developed methods in two typologically different languages by using the datasets in english and russian, cola and rucola, respectively. in particular, we introduce two novel features, chordality and the matching number, and compare the performance of tda-based classifiers to fine-tuning. tda-based classifiers boost the performance of pre-trained language models. tda-based classifiers have advantages over lm fine-tuning because they are more interpretable and help to introspect the inner workings of lms. to this end, we introduce a tda feature-based distance measure to detect changes in the attention mode of lms during fine-tuning. this distance measure is sensitive even to small changes occurring at the bottom layers of lms that are not detected by the widespread jensen-shannon divergence. what is more important, we show how tda features reveal the functional roles of attention heads. we compare heads that contribute to making correct and incorrect predictions based on their importance. this way we discover heads that store information about word order, word derivation, and complex semantic phenomena in unacceptable sentences and heads that attend to acceptable sentences. given the sentence, we evaluate the prediction confidence based on the contribution of the features. we determine the set of sentences in which lms are less confident and find that those sentences usually consist of multiple clauses and frequently include named entities. finally, we find a distinct pattern that is frequently present in the attention maps of unacceptable sentences in english and russian. we hope that our results shed light on the performance of lms in russian and english and help understanding their fine-tuning dynamics and the functional roles of attention heads. we are excited to see the adoption of tda by nlp practitioners to other languages and downstream problems.