What Makes My Model Perplexed? A Linguistic Investigation on Neural Language Models Perplexity (2021)

Abstract: This paper presents an investigation aimed at studying how the linguistic structure of a sentence affects the perplexity of two of the most popular Neural Language Models (NLMs), BERT and GPT-2. We first compare the sentence-level likelihood computed with BERT and the GPT-2’s perplexity showing that the two metrics are correlated. In addition, we exploit linguistic features capturing a wide set of morpho-syntactic and syntactic phenomena showing how they contribute to predict the perplexity of the two NLMs.

## introduction and motivation perplexity is one of the most standard metrics to assess the quality of a language model. it is also used in different scenarios, such as to classify formal and colloquial tweets @xcite , to detect the boundaries between varieties belonging to the same language family @xcite , to identify speech samples produced by subjects with cognitive and/or language diseases e.g. dementia, @xcite or to assess whether it matches various human behavioural measures, such as gaze duration during reading @xcite . with the recent success gained by neural language models (nlms) across a variety of nlp tasks, the notion of perplexity has started being investigated also to dig into issues related to the interpretability of contextual word representations, with the aim of understanding whether there is a relationship between this metric and the grammatical abilities implicitly encoded by a nlm @xcite @xcite . in this context, @xcite and @xcite observed a dissociation between the perplexity of a nlm and its performance on targeted syntactic assessments probing the model's ability to encode a range of subtle syntactic phenomena. these findings seem to be valid for models tested across languages @xcite . in this paper, we address this scenario but from a different perspective. rather than studying the relation between the nlm's perplexity and its linguistic competences assessed on sentences undergoing controlled syntactic modifications, we focus on sentences representative of real usage. our purpose indeed is to understand which linguistic phenomena of the input sentence may make perplexed a nlm and whether they can effectively predict the assigned perplexity score. to have a in-depth understanding of the relation between linguistic structure and perplexity, we rely on a wide spectrum of linguistic features modeling a variety of phenomena, specifically morpho-syntactic and syntactic ones. as we also intend to evaluate the possible influence of the nlm architecture on this relation, in all our experiments we consider two of the most popular nlms, a traditional unidirectional one, i.e. gpt-2 @xcite , and a bidirectional model such as bert @xcite . contributions in this paper: (i) we showed that a sentence-level likelihood computed by masking each word sequentially for the bert model has a robust correlation with gpt-2's perplexity scores; ## our approach we defined two sets of experiments. the first consists in investigating the relationship between bert and gpt-2 sentence-level perplexity (ppl) scores. to do so, we first computed bert and gpt-2 ppl scores for sentences contained in the english universal dependencies (ud) treebank @xcite and we assessed their corre-lation. in the second set of experiments, we studied whether a simple regression model that takes as input a wide range of linguistic features automatically extracted from each ud sentence is able to predict the two nlms sentence-level perplexities. to understand which linguistic phenomena contribute to the prediction of bert and gpt-2 ppls, and how these features differ between them, we performed an in-depth investigation training the regression model with one feature at a time. ## a linguistic investigation on perplexity as a first step, we assessed whether there is a relationship between the perplexity of a traditional nlm and of a masked nlm. we thus calculated bert and gpt-2 perplexity scores for each ud sentence and measured the correlation between them. since ppl scores are highly affected by the length of the input sequence, we computed ρ correlation coefficients also considering groups of sentences with fixed length. specifically, we relied on spearman correlation because we were interested in measuring how the variations in perplexity scores relate each other, rather than focusing on the actual ppl values. results are reported in a more in-depth analysis of these results shows that the distribution of the morpho-syntactic characteristics of a sentence (pos) and of the syntactic dependency relations (syntacticdep) are the two most predictive sources of linguistic information. as figure 1 reports, this holds for the two nlm models and it remains constant throughout all the groups of sentences with fixed lengths. interestingly, if we consider the whole set of sentences, the effect of the morpho-syntactic information on the prediction of gpt-2's perplexity is exactly the same of that of the whole set of linguistic features. for some sentence lengths @xcite @xcite the scores obtained using only this type of information outperform even those obtained considering the whole set of features. note that this last remark is true also in the prediction of bert's perplexity. as expected the other most predictive group is the one (rawtext) that includes the length of sentence. ## conclusion in this paper we proposed an investigation of the linguistic phenomena characterizing the perplexity of a undirectional and a bidirectional neural language model, gpt-2 and bert. we first reported robust correlations between gpt-2's perplexity and the sentence-level likelihood computed with bert. this is a quite prominent result, especially considering that these two metrics are differently computed as a consequence of the two nlms architectures. interestingly, we found the effectiveness of linguistic features modelling a wide set of morphosyntactic and syntactic phenomena in predicting the perplexity of the two nlms, especially for shorter sentences. despite similar trends, we observed some differences between the two nlms both at the level of regression accuracy and in the rankings of the features exploited in the prediction of perplexity. gpt-2's perplexity is better captured by the considered features and it resulted to be more affected by lexical parts-of-speech and features capturing the vocabulary richness of a sentence. on the contrary, bert's perplexity seems to be best predicted by syntactic features highly sensitive to sentence length.