Compositional Generalization with Grounded Language Models (2024)

Abstract: Grounded language models use external sources of information, such as knowledge graphs, to meet some of the general challenges associated with pre-training. By extending previous work on compositional generalization in semantic parsing, we allow for a controlled evaluation of the degree to which these models learn and generalize from patterns in knowledge graphs. We develop a procedure for generating natural language questions paired with knowledge graphs that targets different aspects of compositionality and further avoids grounding the language models in information already encoded implicitly in their weights. We evaluate existing methods for combining language models with knowledge graphs and find them to struggle with generalization to sequences of unseen lengths and to novel combinations of seen base components. While our experimental results provide some insight into the expressive power of these models, we hope our work and released datasets motivate future research on how to better combine language models with structured knowledge representations.

## introduction language models (lms) acquire latent representations of text through their pre-training. one drawback of this paradigm is the implicit encoding of knowledge in a large parameter space, which can lead to factual hallucinations in model outputs. to reduce this effect, there has recently been a widespread interest in what is sometimes referred to as grounded language models, which are lms grounded in external information sources, such as knowledge graphs (kgs). these approaches typically attempt to enable reasoning over kgs by combining the lm outputs with that of a separate graph encoder, such as a graph neural network @xcite @xcite @xcite . it can be difficult to determine to what extent grounded models exhibit any structured reasoning, or what precisely would constitute reasoning in this context, as the information contained in these kgs often targets the same domain as the corpora used for lm pretraining. one example of this is the overlap in information between wikidata, often used as the kg in previous work on grounded lms, and wikipedia, which is a common corpus for pre-training. central to human reasoning is the ability to form novel combinations from seen components, often referred to as compositional generalization. studies on compositionality have a long tradition within many fields of study, such as linguistics @xcite , philosophy @xcite , and cognitive science @xcite , and determining to what degree neural networks capture compositionality is a long-standing research problem in machine learning, with debates going back several decades @xcite . recent studies in nlp have primarily used semantic parsing of synthetic utterances as a testbed for investigating to what extent neural networks combine syntactic elements to form new complex expressions @xcite . one of the most well-known examples of this is from lake and @xcite , who found seq2seq models to struggle both with systematic compositional skills and generalization to longer sequences than seen during training -abilities that are often taken to be central to compositional generalization. some of these shortcomings were recently mitigated using a meta-learning framework (lake and baroni, 2023), but it is still not clear under what circumstances neural networks can consistently demonstrate compositional generalization, or if they can at all @xcite . in this work, we investigate to what extent grounded language models exhibit compositional generalization by combining two orthogonal research directions: compositionality in neural networks and the grounding of lms in kgs. using question answering as a task, we train models to recognize the relation between certain patterns in a synthetic kg and natural language questions. we develop a data generation procedure that targets three aspects of compositionality from @xcite : substitutivity, productivity, and systematicity. in our experiments, we evaluate lms that interact with kgs through the use of a gnn, an approach previously proven effective for tasks such as question answering @xcite @xcite and pre-training @xcite . our work targets two key limitations from the literature: firstly, by extending existing work on compositional generalization to question answering over kgs, we can assess the capabilities of these models for structured reasoning over natural language questions of varying complexities; and secondly, by using a synthetic knowledge graph we do not run the risk of grounding a language model in a knowledge source containing information that already exists implicitly in the models' weights. the contribution of our work is three-fold: i) we provide the first experimental study on the expressive power of grounded lms with respect to compositional generalization ii) we develop a procedure for generating dataset samples that target three theoretically motivated aspects of compositionality, and iii) we release a series of generated datasets using this procedure, together with all code and data related to our experiments, which can be used to benchmark grounded language models in a controlled environment. foot_0 ## compositionality in what follows we discuss three aspects of compositionality that have been established as tests of compositionality in previous work @xcite : substitutivity, systematicity, and productivity. we also describe how we ground these notions to be applicable for our setting, where data consists of both text and kgs. we refer an interested reader to the overview by szabó (2022) for a more extensive introduction to these terms. substitutivity one of the most well-known definitions of compositionality is the principle of compositionality from @xcite : "the meaning of a compound expression is a function of the meanings of its parts and of the way they are syntactically combined". closely related to this principle is the notion of substitutivity, which states that any change to a complex expression that maintains the meaning of individual parts also maintains the meaning of the whole expression. on the one hand, in the context of natural languages, this definition is not without controversy. languages often have elements that do not adhere strictly to such a principle, for example through the use of idioms @xcite . on the other hand, in our setting, we can exploit the observation that if an atomic expression in natural language has a node in a graph as its reference, then we can substitute this reference with a compounded expression referencing the same node without changing the meaning of the whole expression. as the principle of compositionality is not committed to any specific theory of semantics, we can use reference as the qualification for semantic equivalence, a theory sometimes referred to as the compositionality of reference (szabó, 2022). for example, given the kg in figure 1 , we can ask ourselves whether "paper2 was authored by professor2". we can then replace "professor2" with a compounded reference, such as "the supervisor of graduatestudent5", which gives rise to the question: "was paper2 authored by the supervisor of graduatestudent5?" following the compositionality of reference, we do not change the meaning of the overall question, since we still enquire about the same node in the graph, even though we have substituted a 1-hop reference with a 2-hop reference. consequently, by constructing highly compositional questions in natural language, we can test whether or not neural networks can learn the mapping between constituents in text and paths in a graph. productivity closely related to substitutivity, productivity refers to the ability to construct seemingly infinite constructions using a finite capacity. as @xcite point out, this view on the open-endedness of language is typically associated with generative linguistics, and in the context of neural networks, the most direct way of testing for this ability is to test models on generalization to sequences of lengths not seen during training. in our case, we can train models on questions that require reasoning over k-hop paths, for several k, in a graph, and then test on j-hop paths, for various j different from the k's used in training. systematicity one of the most tested properties of compositionality is systematicity, which was popularized as a term by @xcite . systematicity can loosely be described as the ability to combine seen parts and rules to form new combinations, an ability that has a long tradition within linguistics. in the context of neural networks, tests of systematicity typically involve exposing models to a finite set of items and combinations during training and then evaluating the same models on a test set containing the same set of items, but combined in ways not seen during training. lake and baroni (2018) use the example of a person that knows the meaning and usage of words such as "twice," "and," and "again," which upon learning the new verb "to dax" can generalize to new constructions such as "dax twice and then dax again," something they find neural networks to struggle with. recently, there have also been some attempts to formalize and quantify systematic generalization in neural networks @xcite . in our setting, we can use the typed relations of the edges in a graph, such as the one illustrated in figure 1 , to test for systematicity. if a model has seen the relations teaches, has-student, and advisor in numerous 3-hop paths, but never in this order, a display of systematicity would require generalization to this unseen order. ## hops: [teaches, takescourse -, advisor] to create questions from these templates that we label true we can use professor7 and grad-student9 as arguments substituting parameters s and e, respectively, in the 2-hop case, professor7 and professor2 for the 3-hop case, and profes-sor7 and paper2 for the 4-hop case. creating examples labeled as false for these templates then involves sampling two entities to use as s and e that are not connected by the chains of relations, but are similarly connected in the graph as the entities in the positive examples. we describe this negative sampling in the next section. ## modeling for all experiments, each data point includes a natural language question q and a graph g. following previous work on combining language models with kgs @xcite @xcite @xcite @xcite , we use separate encoders for q and g to obtain representations of both modalities. section 4.1 outlines these encoders and section 4.2 how we combine them to produce the final output prediction ŷ ∈ {true, false}. ## previous work there have been numerous works on compositional generalization in neural networks @xcite @xcite @xcite @xcite . most similar to our work is @xcite , which develops a large-scale dataset targeting aspects of compositional generalization using question answering over wikidata. both this work and similar efforts reformulate the problem of integrating the kg to a seq2seq task where the questions are first translated into an intermediate logical form, such as sparql, which can be executed over the kg @xcite . under the same framework, ravishankar et al. (2022) explicitly tests generalization to unseen combinations of relations in a similar fashion to our systematicity test. they too find that the performance tends to drop significantly for this setting. the mapping from natural language to logical form can also use techniques from semantic parsing, a topic where compositionality is of special interest @xcite . our work, however, is the first to target compositionality in a setup where the models learn representations of both text and graphs directly, without any logical form as an intermediate step. in contrast to previous work on grounded language models @xcite @xcite @xcite , our methods can also more precisely quantify the effect of combining lms with gnns, as our sampling procedure ensures that the encoders can not achieve above random performance on their own, a property which we believe is unique to our approach. ## conclusion research on compositional generalization in neural networks has a long history. to the best of our knowledge, we provide the first experimental evaluation of compositional generalization in grounded lms, using question answering over kgs as a task. our results indicate that these models i) require large sample sizes and quickly lose generalization power as the complexity of the compositional structure increases, ii) struggle with extrapolation and interpolation to sequences of lengths not seen during training, and iii) cannot systematically generalize from seen base components to novel compositions given the sample sizes used in our experiments. we show this across a set of model architectures inspired by the literature. our results are in line with previous work on compositional generalization in other domains and for other types of neural architectures. overall, we believe our results show that grounded lms do not display signs of structured reasoning over kgs and that there is still much to be done on the improvement of models that try to exploit external information stored as symbolic objects. this is the case not only for knowledge graphs but also for other types of data representations, such as tabular data. we hope our generation procedure and released datasets can help motivate future efforts at overcoming these challenges.