Structural generalization is hard for sequence-to-sequence models (2022)

Abstract: Sequence-to-sequence (seq2seq) models have been successful across many NLP tasks,including ones that require predicting linguistic structure. However, recent work on compositional generalization has shown that seq2seq models achieve very low accuracy in generalizing to linguistic structures that were not seen in training. We present new evidence that this is a general limitation of seq2seq models that is present not just in semantic parsing, but also in syntactic parsing and in text-to-text tasks, and that this limitation can often be overcome by neurosymbolic models that have linguistic knowledge built in. We further report on some experiments that give initial answers on the reasons for these limitations.

## introduction humans are able to understand and produce linguistic structures they have never observed before @xcite @xcite . from limited, finite observations, they generalize at an early age to an infinite variety of novel structures using recursion. they can also assign meaning to these, using the principle of compositionality. this ability to generalize to unseen structures is important for nlp systems in low-resource settings, such as underresourced languages or projects with a limited annotation budget, where a user can easily use structures that had no annotations in training. over the past few years, large pretrained sequence-to-sequence (seq2seq) models, such as bart @xcite and t5 @xcite , have brought tremendous progress to many nlp tasks. this includes linguistically complex tasks such as broad-coverage semantic parsing, where e.g. a lightly modified bart set a new state of the art on amr parsing @xcite . however, there have been some concerns that seq2seq models may have difficulties with com-positional generalization, a class of tasks in semantic parsing where the training data is structurally impoverished in comparison to the test data @xcite . we focus on the cogs dataset of @xcite because some of its generalization types specifically target structural generalization, i.e. the ability to generalize to unseen structures. in this paper, we make two contributions. first, we offer evidence that structural generalization is systematically hard for seq2seq models. on the semantic parsing task of cogs, seq2seq models don't fail on compositional generalization as a whole, but specifically on the three cogs generalization types that require generalizing to unseen linguistic structures, achieving accuracies below 10%. this is true both for bart and t5 and for seq2seq models that were specifically developed for cogs. what's more, bart and t5 fail similarly on syntax and even pos tagging variants of cogs (introduced in this paper), indicating that they do not only struggle with compositional generalization in semantics, but with structural generalization more generally. structure-aware models, such as the compositional semantic parsers of @xcite and @xcite and the neural berkeley parser @xcite , achieve perfect accuracy on these tasks. second, we conduct a series of experiments to investigate what makes structural generalization so hard for seq2seq models. it is not because the encoder loses structurally relevant information: one can train a probe to predict cogs syntax from bart encodings, in line with earlier work @xcite ; but the decoder does not learn to use it for structural generalization. we find further that the decoder does not even learn to generalize semantically when the input is enriched with syntactic structure. finally, it is not merely because the cogs tasks require the mapping of language into symbolic representations. we introduce a new text-to-text variant of cogs called qa-cogs, where questions about cogs sentences must be answered in english. we find that t5 performs well on structural generalization with the original cogs sentences, but all models still struggle with a harder text-to-text task involving structural disambiguation. the code 1 and datasets 2 are available online. ## related work the recent interest in compositional generalization has raised concerns about limitations of seq2seq models. for instance, the scan dataset (lake and baroni, 2018) requires a model to translate natural-language instructions into symbolic action sequences; it has multiple splits in which the test data contains new combinations of commands or instructions that are systematically longer than in training. the pcfg dataset @xcite builds upon scan and adds instructions with recursive structure. the cfq dataset @xcite ) maps questions to sparql queries, and splits the data according to a measure of compositional complexity (mcd). in all of these papers, simple seq2seq models based on lstms and transformers were shown to perform poorly when the test data was more complex than the training data. since then, followup research has shown that both generic transformer-based models @xcite , general-purpose pretrained models @xcite , and seq2seq models that are specialized for the task can achieve 1 https://github.com/coli-saar/ seq2seq-on-cogs 2 https://github.com/coli-saar/ syntax-cogs higher accuracies than the ones reported in the papers introducing the datasets. nonetheless, there is a sense that despite the best efforts of the community, pure seq2seq models are hitting a ceiling on compositional generalization tasks. in this paper, we shed some light on the issue by (a) clarifying that seq2seq models do not struggle with compositional generalization per se, but with structural generalization, and (b) demonstrating that this type of generalization remains hard for seq2seq models even after heavy pretraining. this is in contrast to most previous research, which has avoided pretraining and focused on length or mcd as the primary source of difficulty. our data includes instances where the structure, but not the length differs between training and testing, and therefore allows us to differentiate between the two. the importance of structure to compositional generalization is also recognized by @xcite . the difficulty of structural generalization for neural models has also been studied in more targeted ways. for instance, @xcite show empirically that lstm-based seq2seq models cannot learn to close the brackets of dyck languages, and @xcite proves that transformers cannot learn to distinguish well-bracketed dyck expressions. @xcite find empirically that seq2seq models struggle to learn the structural operations necessary to rewrite declarative english sentences into questions, whereas tree-based models work better. ## structural generalization in cogs cogs @xcite is a synthetic semantic parsing dataset in which english sen-5049 s np noah vp v ate np np the cake pp on the @xmath0. 1 for some examples). it distinguishes 21 generalization types, each of which requires generalizing from training instances to test instances in a particular systematic and linguistically-informed way. cogs was designed to measure compositional generalization, the ability of a semantic parser to assign correct meaning representations to out-of-distribution sentences. unlike scan and cfq, it includes generalization types with unbounded recursion and separates them cleanly from other generalization types, both of which are crucial for the experiments reported here. most generalization types in cogs are lexical: they recombine known grammatical structures with words that were not observed in these particular structures in training. an example is the generalization type "subject to object" (fig. 1a ), in which a noun ("hedgehog") is only seen as a subject in training, whereas it is only used as on object at test time. the syntactic structure at test time was already observed in training; only the words change. by contrast, structural generalization involves generalizing to linguistic structures that were not seen in training (cf. fig. 1b , c ). examples are the generalization types "pp recursion", where training instances contain prepositional phrases of depth up to two and generalization instances have pps of depth 3-12; and "object pp to subject pp", where pps modify only objects in training and only subjects at test time. these structural changes are illustrated in fig. 2 . structural generalization requires learning about recursion and compositionality, and is thus a more thorough test of human-like language use, whereas lexical generalization amounts to smart template filling. in this paper, we investigate how well structural generalization can be solved by different classes of model architectures: seq2seq models and structure-aware models. we define a model as "structure-aware" if it is explicitly designed to encode linguistic knowledge beyond the fact that sentences are sequences of tokens. this captures a large class of models that can be as "deep" as a compositional semantic parser or as "shallow" as a pos tagger that requires that each input token gets exactly one pos tag. ## structural generalization is hard for seq2seq we begin with some evidence that structural generalization in cogs is hard for seq2seq models, while structure-aware models learn it quite easily. we first collect some results on the original semantic parsing task of cogs, extending it with numbers for bart and t5. we then transform cogs into a corpus for syntactic parsing and pos tagging and investigate the ability of bart and t5 to generalize structurally on these tasks. ## text-to-text structural generalization we will now turn our attention to a novel textto-text variant of cogs. the difficulty of structural generalization for seq2seq models has been primarily studied on tasks where sentences must be mapped into symbolic representations of some kind, such as the semantic and syntactic representations in section 4. but although pretrained seq2seq models like bart and t5 achieve excellent accuracy on broad-coverage semantic parsing tasks, one might argue that they were originally designed for tasks where the output sequence is natural language as well, and thus should be evaluated on such tasks. we therefore propose a new dataset, qa-cogs, which presents structural generalization examples based on cogs sentences in a question-answering format. given a context sentence and a question sentence as input, the goal is to output the correct answer, which should be a consecutive span of tokens in the context sentence. the dataset consists of two sections: qa-cogs-base directly asks questions about cogs sentences (section 6.1), whereas qa-cogs-disamb combines cogs sentences in novel coordinating structures (section 6.2). following the original cogs design, each section consists of four subsets: training set, development set, in-distribution test set, and out-of-distribution generalization set. ## conclusion we have presented evidence that structural generalization is hard for seq2seq models, both on semantic and syntactic parsing (cogs and syntax-cogs) and on some text-to-text tasks (qa-cogsdisamb). in many of these cases, structure-aware models generalize successfully where seq2seq models struggle. unlike earlier work, we have shown that this effect persists when the seq2seq models can be pretrained. we have then presented a number of experiments to help pinpoint the cause of this limitation. we found that the bart encoder still provides structural information, but the decoder does not use it to generalize -both in the parsing tasks and in the probing tasks on the original splits, and not even when the input is enriched with syntactic information. we further found that when the decoder's task is simple enough, as in qa-cogs-base, seq2seq models learn to generalize structurally as well as structure-aware models. in improving the ability of seq2seq models to generalize structurally, it seems promising to focus on the decoder, especially by including structure-aware elements.