Probing for Constituency Structure in Neural Language Models (2022)

Abstract: In this paper, we investigate to which extent contextual neural language models (LMs) implicitly learn syntactic structure. More concretely, we focus on constituent structure as represented in the Penn Treebank (PTB). Using standard probing techniques based on diagnostic classifiers, we assess the accuracy of representing constituents of different categories within the neuron activations of a LM such as RoBERTa. In order to make sure that our probe focuses on syntactic knowledge and not on implicit semantic generalizations, we also experiment on a PTB version that is obtained by randomly replacing constituents with each other while keeping syntactic structure, i.e., a semantically ill-formed but syntactically well-formed version of the PTB. We find that 4 pretrained transfomer LMs obtain high performance on our probing tasks even on manipulated data, suggesting that semantic and syntactic knowledge in their representations can be separated and that constituency information is in fact learned by the LM. Moreover, we show that a complete constituency tree can be linearly separated from LM representations.

## introduction over the last years, neural language models (lms), such as bert @xcite , xlnet @xcite , roberta @xcite , and distilbert @xcite , have delivered unmatched results in multiple key natural language processing (nlp) benchmarks @xcite . despite the impressive performance, the black-box nature of these models makes it difficult to ascertain whether they implicitly learn to encode linguistic structures, such as constituency or dependency trees. there has been a considerable amount of research conducted on questioning which types of linguistic structure are learned by lms @xcite @xcite . the motivation behind asking this question is two-fold. on the one hand, we want to better understand how pre-trained lms solve certain nlp tasks, i.e., how their input features and neuron activations contribute to a specific classification success. a second motivation is an interest in distributional evidence for linguistic theory. that is, we are interested in assessing which types of linguistic categories emerge when training a contextual language model, i.e., when training a model only on unlabeled text. the research in this paper is primarily motivated by this second aspect, focusing on syntactic structure, more concretely on constituency structure. we investigate, for instance, for pairs of tokens in a sentence whether a lm implicitly learns which constituent (np, vp, . . . ) the two tokens belong to as their lowest common ancestor (lca). we use english penn treebank data @xcite to conduct experiments. a number of studies have probed lms for dependency structure @xcite and constituency structure @xcite . we probe constituency structure for the following reasons. in contrast to dependency structure, it can be richer concerning the represented abstract syntactic information, since it directly assigns categories to groups of tokens. on the other hand, not all dependency labels are represented in a standard constituency structure; but they can be incorporated as extensions of the corresponding non-terminal nodes (see, e.g., the ptb label np-sbj in app. a.1). to quantify the gain that we get from probing constituency rather than dependency trees, we compare the unlabeled bracketings in the syntactic trees in both formalisms on the ptb @xcite , where an unlabeled bracketing is the yield of a subtree. we find that while 97% of the bracketings in a dependency tree are also present in a constituency tree, only 54% of the bracketings in the constituency tree are present in the dependency tree. this shows that constituent trees can contain much more fine-grained hierarchical information than dependency trees. a further reason for focusing on constituency structure is that this is the type of structure most linguistic theories use. we use diagnostic classifiers @xcite and perform model-level, layer-level and neuron-level analyses. most work on diagnostic classifiers performs mean pool over representations when probing for a relationship between two words @xcite . we empirically show that mean pool results in lossy representation, and we recommend concatenation of representations as a better way to probe for relations between words. a difficulty when probing a lm for whether certain categories are learned is that we cannot be sure that the lm does not learn a different category instead that is also predictive for the category we are interested in. more concretely, when probing for syntax, one should make sure that it is not semantics that one finds and considers to be syntax (since semantic relations influence syntactic structure). this point was also observed by @xcite and, more recently, hall @xcite . therefore, before probing the lm for syntactic relations, we manipulate our data by replacing a subset of tokens with other tokens that appear in similar syntactic contexts, thereby obtaining nonsensical text that still has a reasonable syntactic structure. we then conduct a series of experiments that show that even for these nonsensical sentences, contextual lms implicitly represent constituency structure. lastly, we questioned whether a full syntactic tree can be reconstructed using the linear probe. we achieve a labeled f1 score of 82.6% for roberta when probing on the non-manipulated dataset in comparison to 51.4% with a random representation baseline. the contributions of our work are as follows: the rest of the paper is structured as follows. the next section introduces related work. we define our linguistic probing tasks in sec. 3. sec. 4 introduces our experimental methodology. sec. 5, 6, and 7 discuss our experiments and their results, and sec. 8 concludes. a common line of work on interpreting models use a probing classifier to gauge the amount of linguistic knowledge learned in the representation @xcite @xcite . an ample body of research exists on probing the sub-sentential structure of contextualized word embeddings. @xcite probed neural networks to see to what extent span representations capture phrasal syntax. @xcite devised a set of edge probing tasks to get new insights on what is encoded by contextualized word embeddings, focusing on the relationship between spans rather than individual words. this enables them to go beyond sequence labeling problems to syntactic constituency, dependencies, entity labels, and semantic role labeling. their results on syntactic constituency are in line with our findings. the major difference is that we employ simpler probes while achieving similar results. moreover, we separate the effect of semantics using corrupted data and we reconstruct full constituent trees using our probing setup. most recently, @xcite propose a parameter-free probing technique to analyze lms via perturbed masking. their approach is based on accessing the impact that one word has on predicting another word within a sequence in the masked language model task. they have also shown that lms can capture syntactic information with their self-attention layers being capable of surprisingly effective learning. @xcite demonstrated, by using a structural probe, that it is possible to find a linear transformation of the space of the lm's activation vectors under which the distance between contextualized word vectors corresponds to the distance between the respective words in the dependency tree. in a similar vein, @xcite introduced another structural probe, poincaré probe and have shown that syntactic trees can be better reconstructed from the intermediate representation of bert in a hyperbolic subspace. syntactic and semantic knowledge @xcite and hall @xcite recently argued that the work on probing syntax does not fully separate the effect of semantics while probing syntax. both modify datasets such that the sentences become semantically nonsensical while remaining syntactically well-formed in order to assess, based on this data, whether a lm represents syntactic information. @xcite modify treebanks in four languages by replacing content words with other content words that have matching pos and morphological features. they focus on the question if agreement information in the nonce sentences can be recovered from rnn language models trained on regular data. hall maudslay and cotterell (2021) replaced words with pseudowords in a dependency treebank, and quantified how much the pseudowords affect the performance of syntactic dependency probes. we followed a similar setup to separate out the effect of syntax from semantics. in contrast to hall maudslay and cotterell (2021), we replace words with other words (not pseudowords) that occur in a similar syntactic context but are different semantically. this way, the lm has seen most or all words from the semantically nonsensical sentences in pretraining and has learned their syntactic properties. fine-grained lm analysis @xcite used a unified diagnostic classifier approach to perform analyses at various granularity levels, extending @xcite . we follow their approach and perform model-level, layer-level and neuron-level analyses @xcite . we additionally extend their approach by proposing an improved way to probe representations of two words. previous work has mainly used a bilinear probe to investigate syntax. we select a linear model for our experiments. selecting a weak model ensures that the representations learn the linguistic property, and the probe is not relying on the strength of the classification model used. ## diagnostic tasks and constituency trees in this section, we define three classification tasks that are aimed at making different properties of constituency structure explicit. more specifically, the goal of these tasks is to make explicit if and how the lms encode syntactic categories, such as s, np, vp, pp. the first task, lowest common ancestor prediction, focuses on constituents that span large portions of the sentence. the second task, chunking, focuses on constituents with smaller spans. the third task focuses on complete syntactic trees. lowest common ancestor (lca) prediction let @xmath0, . . . , w n be a sentence. given combined representations of two tokens w i , w j with @xmath1, predict the label of their lowest common ancestor in the constituency tree. lca prediction is a multiclass classification task with 28 target classes (for the ptb). in the example in fig. 1 , luxury and maker have the lca np: the lowest node dominating both words has label np (ignoring the function tag sbj). the task also predicts lca of two identical tokens. in this case, the lowest phrasal node above the token is the target label (for example, vp is the target label for sold). chunking for each token w i , predict whether it is the beginning of a phrase (b), inside a phrase (i), the end of a phrase (e) or if the token constitutes a single-token phrase (s). a token can be part of more than one phrase, and in this case we consider the shortest possible phrase only. for example, 1,214 in depth of the lca of (w i , w i+1 ) in the tree, relative to the depth of (w i-1 , w i ). third, if the first token is a single-word constituent, and the label of the internal tree node directly above w i . (tokens in multiword constituents make @xmath2.). for the first two classifications, see fig. 1 . we build separate linear classifiers for each of these tasks and use their predictions to reconstruct full constituent trees. we conduct a linguistic correlation analysis, as proposed by @xcite . this consists in augmenting the linear classifier with elastic net regularization @xcite . the classifier is then trained by minimizing the loss function in eq. 1: for chunking, the label distribution is relatively balanced. for lca prediction, we remove all function tags to keep the number of target labels small. most of the token pairs have a relatively large distance in the constituent tree, and their lca is a node very high in the tree (typically with a label for some kind of sentence, such as s or sbar). in addition, some phrase labels are less frequent than others (see app. a.4). we train and evaluate on the standard ptb training/development split. ## results for lca prediction and chunking we experimented using four pretrained models. due to the limited space and the consistency of results, we reported the analysis for the roberta model only in most of the cases. the complete re ## reconstructing full parse trees with the insights gained in the previous section, we test if full constituency trees can be linearly separated from lm representations. for this, we train 3 linear classifiers that take as input the concatenated representations of two adjacent tokens and predict the three labels described in sec. 3. the classifiers for this task take as input not the full lm representation from all layers, but instead the concatenations of every third layer for the 12-layer lms, and every second layer for the 6-layer lm. this way, the input dimensionality of the classifier is restricted, but the probe can use information from different parts of the lm. the probe is trained (evaluated) on all 38k (5.5k) sentences of the training (development) split of the ptb. we find that the constituency trees reconstructed from different lms are of high quality (tab. 3, app. a.9). we achieve a labeled f1 score of 82.6 on the non-manipulated dataset for roberta (80.5 for xlnet, 80.4 for bert) which is 31 points better than the random bert baseline. this outperforms the result from @xcite for bert by 2.2 points. they also use a linear classifier, but their classifier receives as input only the final layer representation of bert for the first token in the token pair. when comparing trees reconstructed from different lms against each other, we find however that they are quite different. for example, comparing the sentence-level f scores for trees reconstructed from xlnet to those from roberta yields a pearson correlation of 0.52 only (compared to 0.64 for distilbert and bert, see app. a.10 for the full comparison). this shows that different syntactic properties are linearly separable from the represen-2 all models are more accurate in lca prediction when the two tokens are more distant, see app. a.6. large distance between tokens correlates with lca nodes close to the root of the syntactic tree, where the lca often has label s. roberta ∆ random orig. 82.6 31.2 .33/orig. 80.9 31.3 .33/.33 77.8 31.7 .67/orig. 78.3 30.4 .67/.67 72.8 28.1 ## conclusions our experiments have shown that different pretrained lms encode fine-grained linguistic information that is also present in constituency trees. more specifically, lms are able to identify properties of different types of constituents, such as s, np, vp, pp. good results on the chunking task show that the classifiers are able to combine knowledge about the kind of constituents that a token is part of, and knowledge of the position of a token in the constituent. using the sequence labeling tasks presented in @xcite , we have shown that full constituency trees are linearly separable from four different pretrained lms with high quality -even for semantically nonsensical data. in line with @xcite , we observe a moderate performance drop between performance on the original and nonce dataset. the performance drop is smaller than in hall maudslay and @xcite . who use english pseudowords which the lm has probably never encountered. we use english words whose syntactic and semantic properties are already well-established inside the lm. in future work, we plan to extend this syntactic probing approach to other languages and other syntactic annotation schemes (for instance @xcite .