Can Transformers Process Recursive Nested Constructions, Like Humans? (2022)

Abstract: Recursive processing is considered a hallmark of human linguistic abilities. A recent study evaluated recursive processing in recurrent neural language models (RNN-LMs) and showed that such models perform below chance level on embedded dependencies within nested constructions – a prototypical example of recursion in natural language. Here, we study if state-of-the-art Transformer LMs do any better. We test eight different Transformer LMs on two different types of nested constructions, which differ in whether the embedded (inner) dependency is short or long range. We find that Transformers achieve near-perfect performance on short-range embedded dependencies, significantly better than previous results reported for RNN-LMs and humans. However, on long-range embedded dependencies, Transformers’ performance sharply drops below chance level. Remarkably, the addition of only three words to the embedded dependency caused Transformers to fall from near-perfect to below-chance performance. Taken together, our results reveal how brittle syntactic processing is in Transformers, compared to humans.

## introduction one of the fundamental principles of contemporary linguistics states that language processing requires the ability to deal with nested structures. recursion, a specific type of computation that involves repeatedly applying a function to its own output, is suggested to be at the core of this ability @xcite . the strongest evidence for recursion in human language processing arises from the tree-like nested structure of sentences in natural language, in which phrases of a particular type (i.e. nps) can be embedded in other phrases of that same type (figure 1 ). humans, it is argued, are endowed with a unique competence for recursive processing, which allows them to represent and process such nested tree structures @xcite @xcite . in recent years, neural language models (nlms) have shown tremendous advances on a variety of linguistic tasks, such as next-word prediction, translation or semantic inference. furthermore, evaluations of their syntactic abilities have shown promising results, with similar or even above-human performance on a variety of different tasks @xcite @xcite . however, negative results were recently also presented @xcite . in particular, when it comes to recursive processing, @xcite showed that while recurrent neural network language models (rnn-lms) perform well on long-range dependencies, such as the relationship between keys and are in sentences like "the keys that the man near the cabinet holds, are red" (figure 2 ), they perform below chance on the shorter, embedded dependency (man-holds). humans, instead, perform significantly better on such dependencies, although interestingly, for them too, the shorter inner dependency is more difficult than the long outer one. the study by @xcite illustrates how investigations of neural networks can inspire experiments about human language processing. however, their study focuses on only a single architecture, an rnn-lm with lstm units @xcite , which is currently outperformed on many fronts by the newer transformer models @xcite . in this short paper, our main question is therefore whether transformer models do any better when it comes to processing recursive constructions. we then further explore similarities and differences in performance patterns of rnn and transformer language models. our main results show that when tested on nested constructions with a short-range embedded dependency, transformers outperform rnn-lm across all conditions, with error rates close to zero. however, when the embedded dependency is longrange, their performance dramatically drops to below chance, similarly to the case of rnns. the mere addition of a short prepositional phrase ('near the cabinet' in the example shown in figure 1 ) to the embedded dependency causes model performance to drop from near perfect to below chance level. thus, contrary to what might be expected based on their much improved performance and the fact that they are trained on substantially more data, transformer models share rnns' shortcoming when it comes to recursive, structure-sensitive, processing. last, almost all models made more errors when trying to carry a noun in the singular across dependencies which involved a plural noun, than in the converse situation. interestingly, this bias towards greater interference by plural than by singular is opposite to that reported in italian rnn-lms @xcite , and is akin to the markedness effect reported for humans. ## related work in psycholinguistics, grammatical agreement became a standard method to probe online syntactic processing in humans @xcite , since it is ruled by hierarchical structures rather than by the linear order of words in a sentence. more recently, it has also become a standard way to probe grammatical generalization in nlms @xcite @xcite the keys that the man holds are ... 2018; @xcite @xcite , pointing to both similarities and differences between human and model error patterns. @xcite showed that rnn-lms trained on a large corpus with english sentences develop a number-propagation mechanism for longrange dependencies. the core circuit of this mechanism was found to be extremely sparse, comprising of only a very small number of units. this sparsity of the mechanism suggests that models are not able to process two long-distance dependencies simultaneously, and indeed, this was later confirmed in simulations @xcite . inspired by this finding, @xcite conducted a following experiment with humans, which showed that they, too, make more errors on nested long-range dependencies. however, contrary to lms, their performance was above chance on these constructions. this finding suggests that human recursive processing remains significantly better than that of rnn-lms. recursive processing of nested constructions in rnn-lms was also studied using artificial grammars @xcite @xcite @xcite . recently, @xcite showed that memoryaugmented rnns can capture recursive regularities of dyck languages (also known as "bracket languages"). however, when tested on a simple extension of these languages, rnn-lms failed to generalize to unseen data with a greater nesting depth @xcite . specifically, the models failed also in cases in which the training figure 3 : error rates on nested constructions in english, for the lstm and all causal transformers, for both the main and embedded agreements. conditions are marked by the value of the grammatical number of all nouns in the sentence. for example, condition sp means that the first noun is singular and the second is plural. while error-rates are near zero for short-nested, they are worse than chance-level for one of the incongruent conditions of long-nested, consistently across all models. in this condition (psp), grammatical agreement is with respect to the second noun, which is singular. taken together, previous work suggests that rnn-lms struggle to capture recursive regularities in either natural or artificial data. inspired by this line of work, we focus here on transformer lms: do they show different patterns when it comes to processing recursive structures? do they better approximate human ability for recursion? ## experimental setup we largely follow the experimental setup of @xcite , and we consider two different languages (english and italian) and a different set of models. data we consider two number-agreement tasks (na-tasks): short-nested and long-nested. both tasks contain two subject-verb dependencies; they differ in terms of whether the embedded dependency is shortor long-range. in short-nested, the subject and verb in the nested dependency are adjacent (figure 2a ). they are embedded in a sentence by inserting an object-relative clause to modify the subject of a different sentence. the long-nested task (figure 2b ) uses the same constructions, except that an additional three-word prepositional phrase (e.g., "near the cabinet") is added in the embedded dependency. 1 models we run experiments with all causal transformer-based nlms that are currently compatible with the bigbench framework, available from huggingface foot_1 , and also with two maskedlanguage models (mlms). specifically, we include four gpt-2 models that differed in size: gpt2, gpt2-medium, gpt2-large and gpt-xl @xcite ; and two masked-language models: roberta and roberta-large @xcite . in addition, as a baseline, we conduct an experiment with an english lstm-lm, which was studied in numerous work in the past @xcite . model evaluation following previous work, we evaluated model performance on agreement by comparing the output probabilities for the correct (e.g., 'are') vs. wrong ('is') verb form. for both tasks, we evaluated model performance on agreement for both the embedded and the inner verb, and separately for each task condition (see sm). ## results causal transformers, such as gpt-2, receive word input incrementally, similarly to humans. in contrast, masked language models (mlms), such as roberta @xcite have access to all tokens in the input in parallel. in sections 4.1 and 4.2 we first focus on english causal models, rather than on mlms, due to the similarity in input processing, which makes the human-model comparison more direct. in section 4.3, for completeness, we further report results from mlms. finally, in section 4.4., we report results for another language, namely, italian. ## discussion in this study, we evaluated the recursive abilities of transformer lms on two number-agreement tasks that were previously shown to be exceptionally challenging for lstm language models. our ex-3 note that their performance on an adjacent dependency between a noun and a verb, as in the embedded dependency of short-nested, is relatively good and above chance level, which shows that their overall poor performance is not due to experimental-setup issues, such as tokenization. furthermore, we found that all causal models showed a bias towards plural and therefore err more when the subject of a verb is in the singular. a similar bias was previously observed in italian lstm models @xcite , however, in the opposite direction, with more errors on plural dependencies. we hypothesize that this difference might be due to marking of the verb form, given that in english, the marked form of the verb is singular, whereas in italian, it is plural. related biases were previous reported for humans, a phenomenon known as the markedness effect @xcite . the relation between emerging biases in nlms and humans is an interesting topic for future work. in lstm-lms, the poor performance was predicted by the underlying neural mechanism for grammatical agreement identified in the models @xcite . the fact that transformer models perform similarly poorly on these constructions, both casual and masked-language models, and on the same dependency (inner), raises interesting questions. do transformers use syntactic-processing strategies akin to those emerged in rnn-lms? and what does that tell us about the data that those models are trained on and about the potential processes that humans may use to process such constructions @xcite ? however, currently, the neural mechanisms underlying syntactic processing in transformers are poorly understood @xcite . our findings of below-chance performance by transformer models calls for a further investigation in how these models achieve their earlier found successes on syntactic related tasks, and why they generalise so poorly on constructions which only minimally differ (a single three-word prepositional phrase) from the constructions they process well.