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.

heading: 1 Introduction
text: 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 (GNN; Lin et al., 2019; Zhang et al., 2022; Sun et al., 2022; Yasunaga et al., 2022; Yu et al., 2022). 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 (Partee et al., 1995), philosophy (Pagin and Westerståhl, 2010), and cognitive science (Churchland, 1990), and determining to what degree neural networks capture compositionality is a long-standing research problem in machine learning, with debates going back several decades (Fodor and Pylyshyn, 1988; Smolensky, 1987). 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 (Hosseini et al., 2022). One of the most well-known examples of this is from Lake and Baroni (2018), 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 (Dziri et al., 2024).
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.
3447
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 Hupkes et al. (2020): 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 (Lin et al., 2019; Zhang et al., 2022; Sun et al., 2022) and pre-training (Yasunaga et al., 2022).
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.1

heading: 2 Compositionality
text: In what follows we discuss three aspects of compositionality that have been established as tests of compositionality in previous work (Hupkes et al., 2020): 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 Partee et al. (1995): “The meaning of a compound expression is a function of the
1https://github.com/ltgoslo/ text-graph-generalization
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 (Dankers et al., 2022a). 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 Hupkes et al. (2020) 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 Fodor and Pylyshyn (1988). 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 (Keysers et al., 2020; Ram et al., 2023). 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, HASSTUDENT, and ADVISOR in numerous 3-hop paths, but never in this order, a display of systematicity would require generalization to this unseen order.

heading: 3 Dataset Generation

heading: 3.1 Overview
text: To target the compositional abilities specified above, we generate several datasets consisting of
pairs of KGs and yes/no questions in natural language, all of which are about the information in these graphs. This section explains the properties of these datasets and how they are created.
A KG over a set T of types and a set R of relations is a directed labeled multi-graph (V,L, E) with nodes V , called entities in this context, set L of node labelings, each of which is of the form (v, t) where v is an entity in V and t a type in T , and set E of edges, each of which is of the form (v, r, v′), where v and v′ are entities from V , and r is a relation from R. In this work, we only concentrate on graphs from the Lehigh University Benchmark (LUBM; Guo et al., 2005), which is a synthetic KG benchmark popular for evaluating various aspects of knowledge graph repositories. In particular, we exploit LUBM’s KG generator of customizable and repeatable synthetic data, which can produce KGs of a user-specified size describing a fictitious university domain and committing to a realistic ontology over sets TLUBM and RLUBM of university-related types and relations. We generate several graphs with an average number of 685 entities, each labeled by a single type, and 4 949 edges, each labeled by a single relation.2
Each of the natural language questions targets two entities in the corresponding generated LUBM graph G and a chain of relations from RLUBM and inverses of such relations that is to hold between these entities. In particular, for a number of hops (i.e., chain length) k, the questions are semimanually created by first mapping each unique khop combination (i.e., chain of length k) of relations from a selected subset of RLUBM and their inverses to a natural language template with two parameters, and then substituting these parameters by two entities from V as arguments. As a result, the answer to the question is TRUE if there exists a path between the two entities in G as prompted by the k-hop combination of the question template, and FALSE otherwise. We create templates for 2, 3, and 4 hops, with 5 relations from RLUBM and their inverses as R′LUBM. This makes for over 280 unique templates (while the number of questions depends on G). To illustrate our dataset creation we concentrate on an example and a discussion of a key step, sampling of positive and negative question–graph pairs, in the next two subsections. We refer to Appendix A for further details.
2The ontology is specified in Web Ontology Language OWL (https://www.w3.org/OWL/).

heading: 3.2 Example
text: Given the KG in Figure 1, we can create the following templates, for an increasing number of hops, where the “−” superscript denotes the inverse of the relation:
2 hops: [TEACHES, TAKESCOURSE−] → Does s teach a course that has a student named e?
3 hops: [TEACHES, TAKESCOURSE−, ADVISOR] → Does s teach a course that has a student supervised by e?
4 hops: [TEACHES, TAKESCOURSE−, ADVISOR, PUBLICATIONAUTHOR] → Does s teach a course that has a student supervised by an author of e?
To create questions from these templates that we label TRUE we can use PROFESSOR7 and GRADSTUDENT9 as arguments substituting parameters s and e, respectively, in the 2-hop case, PROFESSOR7 and PROFESSOR2 for the 3-hop case, and PROFESSOR7 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.

heading: 3.3 Sampling Procedure
text: As mentioned, we create each question–graph pair by sampling pairs of entities and the relations on the edges that are to hold between them in the graph G. The key requirement to this procedure is to guarantee that the k relations and their inverses in every sampled k-hop combination are as likely to be labeled TRUE as they are to be labeled FALSE; failing to do so introduces distributional bias. This means that our sampling procedure must ensure two important properties: i) it must be impossible for a text-only model to associate a question template (i.e., all questions produced from this template) to the TRUE or FALSE label, and ii) it must be impossible for a graph-only model to associate the presence of a specific set of relations in graph G with a specific label.
We ensure property i) by creating the same number of questions labeled TRUE as FALSE for every unique k-hop combination of relations. We ensure ii) by sampling k-hop relation paths from G symmetrically: We first sample i.i.d. two pairs of
different entities, s+, e+ and s−, e−, such that s+ and s− are of the same entity type, and e+ and e− are also of the same entity type. We then identify a k-hop combination over R′LUBM that exists between s+ and e+ but not between s− and e−, as well as verify that there exists another (different) k-hop combination over R′LUBM between s− and e−. If all this succeeds, the pair s+, e+ with the question corresponding to the template becomes a positive example, and the pair s−, e− with the same template a negative one. Further details of the sampling procedure can be found in Appendix A.

heading: 4 Modeling
text: 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 (Lin et al., 2019; Zhang et al., 2020; Yasunaga et al., 2021; Zhang et al., 2022; Kaur et al., 2022; Sun et al., 2022; Yasunaga et al., 2022), 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 ŷ ∈ {TRUE, FALSE}.

heading: 4.1 Encoders
text: Text encoder We obtain representations of q by using the special sentence representation token at the last layer of a pre-trained language model, as per Devlin et al. (2019): ztext = BERT(q).
Graph encoder As a graph encoder, we use the relational graph convolution model, R-GCN, from Schlichtkrull et al. (2018):
hℓ+1i = σ
(∑
r∈R
∑
j∈N ri
1
| N ri | W ℓrh ℓ j +W ℓ 0h ℓ i
) ,
where hℓi is the hidden state of a node i in layer ℓ, σ is the ReLU function and N ri is the set of neighborhood vertices of node i under relation r.

heading: 4.2 Final models
text: Inspired by previous work on combining text and graph encoders, we experiment with different approaches to integrating the two modalities and apply them using the above-mentioned encoders and our experimental setup. Figure 2 provides an overview of the differences between these approaches.
Disjoint The simplest way of having the two modalities interact is to initialize and run both encoders separately before conjoining their outputs in a final classification layer. This keeps the encoders disjoint, essentially making a “two-tower architecture” – conceptually similar to approaches such as Wang et al. (2019).
To get a final representation of the graph, zgraph, we take the embedding of the head and tail node targeted by the question after L rounds of message passing: zgraph = hLs ⊕ hLe , where s and e are the indices of the head and tail node and ⊕ is vector concatenation. We initialize these nodes by creating two distinct embeddings, Es and Ee, with Es, Ee ∼ N (0, 1). We keep these static throughout training and testing and use them for all head and tail nodes targeted by the questions. The initialization of remaining nodes in each graph is discussed in more detail in Section 4.3.
For the question, we take the output of the text encoder without any modifications. The final output prediction is then obtained by the following: f(ztext ⊕ zgraph), where f is a two-layered MLP with a ReLU activation function.
Grounded For this model, we concatenate the original question string from q with both the head and tail entity strings, respectively, using a separation token. This is then used as input to the text encoder, obtaining a representation of the head and tail nodes:
h0s = BERT(q <SEP> head surface form), h0e = BERT(q <SEP> tail surface form).
These are then used to initialize the embeddings for the nodes pertaining to these entities in the graph. This is done in a pre-processing step before the text encoder is fine-tuned on our datasets. The final output prediction is calculated in the same way as with the disjoint model.
Unidirectional In this model, we add a unidirectional interaction between the encoders, inspired by works such as Yasunaga et al. (2021). For each question–graph pair, (q,G), we introduce a new special context node, u, and connect u to each node in G. This special node is connected using two new relations, one for each direction, and its embedding is initialized using the text encoder representation of the question, BERT(q). In Figure 2, u is marked as a blue node. For each G, we perform global pooling over the hidden states:
zgraph = 1 |V ′| ∑
v∈V ′ hLv ,
where V ′ is the set containing the head, tail, and special context nodes. We do not consider the set of all nodes due to the zero-initialization of the remaining nodes in G (see Section 4.3). The head and tail nodes are initialized as in the grounded model, using the text encoder representations. We also take the embedding of the special node at the last layer, hLu , as a representation of G. The final output prediction is then given by: f(ztext⊕zgraph⊕ hLu ), where f is a two-layered MLP with a ReLU activation function.
Bidirectional We also develop a model inspired by the interaction approach used in works such as
Zhang et al. (2022) and Yasunaga et al. (2022) to allow for a bidirectional interaction between the two encoders. We keep the special context node u as described in the unidirectional model, but we add a special interaction token, t, to the question q. t is set to be the representation of the special context node u after L layers of message passing: t = hLu . This is done after the embedding of q in the text encoder. We produce the final output prediction using the same method as in the unidirectional model.
Baseline We use a sole graph encoder as a baseline. Theoretically, it should not be possible to solve the tasks without having access to both the text and the graph. By using a graph-only system as a baseline we therefore get both a sanity check and an upper bound on the noise produced by the sampling. As the natural language questions are not sampled, but rather constructed deterministically from the paths sampled from our graphs, one positive and one negative, the performance of a textonly encoder will by design be equal to a random classifier. The output of the baseline is calculated the same way as for the disjoint model, taking the representations of the head and tail entity.

heading: 4.3 Node initialization
text: Except for the head and tail nodes targeted by each question, and the special context node u, all nodes are initialized as zero-vectors. This means that we leak the position of the head and tail entity in G for each sample in the dataset, making any pruning of G redundant. It is often necessary to reduce the computational complexity of combining language models and large knowledge graphs using mechanisms such as subgraph retrieval and entity linking, but these steps are also known to be error-prone (Wold et al., 2023). This initialization ensures that we further isolate the application of compositional generalization rules, as opposed to evaluating the performance of a pipeline model with numerous error-prone components.

heading: 5 Experiments and results
text: In this section, we test our suite of models on data specifically targeting substitutivity (Section 5.1), productivity (Section 5.2), and systematicity (Section 5.3), going test by test. For all experiments, the distribution between the two classes is perfectly balanced. Statistics on the diversity of the generated graphs with respect to relation paths can be found in Table 1. Details on the selection of hyperparameters can be found in Appendix B.

heading: 5.1 Substitutivity
text: In our first test, we evaluate to what extent the five model configurations can answer questions targeting substitutivity, as defined in Section 2. Success at this task requires recognizing the mapping between the presence of certain relations in the graph and phrases in the natural language questions. Substitutivity is the most basic setting of our experiments and the results on this task demonstrate the general difficulty of the task.
Test design We generate 12 000 question–graph pairs using our generation procedure. We do this for 2, 3 and 4-hops. Each experiment targets one of the hop lengths, i.e., both training and evaluating on the same number of hops. For all experiments, we use 10 000 samples for training and 2 000 for testing. All results are reported using mean accuracy and standard deviation from five randomly seeded runs.
Results The results of the substitutivity tests can be seen in Table 2. There is a strong generalization in the 2-hop case for all models. In the 3-hop case, performance drops significantly and the variance also increases for most models. There is a further loss in generalization when moving to the 4-hop case, where there is little difference between the models. Figure 3 shows that there is a positive correlation between test accuracy on a specific question type and the frequency of the corresponding relation path in the training data for the 3-hop case. For the 2-hop and 4-hop cases, where the performance is closer to perfect and random classification, respectively, the relationship flattens. This aligns with the increase in unique combinations of relation paths as the number of hops increases, as shown in Table 1. For 2-hops there is either a high number of examples per relation path combination, which enables learning, or very few, which makes the performance on these relation paths negligible on the overall accuracy. For 4-hops, on the other hand, there is too much of a long tail on the dis-
tribution of number of samples per combination, making learning difficult. For 3-hops, however, there is a balance, which is reflected in the results. See Figure 4 in Appendix A for an illustration of the relative percentage of each unique combination to the total for each hop.
These results show that the models struggle to generalize to the long tail of the training distribution, which is a known attribute of neural networks. However, single relation types are reused extensively throughout our training data, as there are only 10 unique relations of length 1. This means that the distribution only has a long tail if one considers each 4-hop combination to be a single unique type, as opposed to being composed of four individual relations that are individually high-frequent. We argue that these results indicate that these models do not create internal representations of each 1-hop path together with a function for composing them into compounded expressions, but rather learn individual representations for each compound. This also explains why the performance drops as the complexity increases and the number of samples per relation decreases, making such a strategy less viable. This explanation is further explored in the systematicity tests. We also note that there is little difference between the models, indicating that an increase in model complexity does not add any benefits to this task.

heading: 5.2 Productivity
text: In our next test, we evaluate to what extent models can answer k-hop questions when trained on j-hops, with k ̸= j. We define experiments requiring extrapolation and interpolation for different values of k and j. Success at this task requires generalization to sequences with a different length than those seen during training.
Test design In our first experiment, we use an even amount of 2 and 3-hop questions for training while using 4-hop questions for testing, targeting extrapolation. In our second experiment, we tar-
get interpolation by training on an even amount of 2 and 4-hop questions while testing on 3-hops. For our last experiment, we target extrapolation to lower values, using a training split with an even amount of 3 and 4-hop questions while testing on 2-hops. For all three experiments, we generate 10 000 samples for training and 2 000 for testing.
Results The results of the productivity tests can be seen in Table 3. In general, we observe that all models struggle to extrapolate to both shorter and longer hops. We observe some generalization for the interpolation test, where the model has seen sequences both shorter and longer during training, but the overall absolute performance is still poor. This aligns with previous work, such as Lake and Baroni (2018) and Hupkes et al. (2020). We observe a tiny increase in performance with the more complex models compared to the simpler, disjoint model, but given the overall low scores and the variance, we do not think these results are significant. This indicates that adding a more complex interaction between the encoders does not provide any added benefit for extrapolation or interpolation.

heading: 5.3 Systematicity
text: In our last test, we evaluate to what extent our models can generalize systematically. This means that all unique 1-hop relations are seen during training in some k-hop combination, but in the test data, we only include unseen combinations. For example, during training the models might see samples using the relations TAKESCOURSE and
HASTEACHINGASSISTANT, and the 2-hop combination [TAKESCOURSE, HASTEACHINGASSISTANT], but in the test we target [HASTEACHINGASSISTANT, TAKESCOURSE]. Success at this task requires the model to learn that a 3-hop question, for example, consists of three individual parts that are combined, as opposed to encoding the entire sequence as one entity.
Test design With k being 2, 3, or 4, we generate question–graph pairs with length k. Then, for each k, we randomly select a fraction of the available k-length combinations of relations as our test combinations. We then separate the generated pairs into two parts: those who use the test combinations and those who do not. The former is saved as the test set. We note that the use of test combinations is not limited to the relations on the path between the head and tail entities targeted by the question, but any k-hop path that exists between these entities. For the training set, we split the remaining possible combinations into five chunks and collect all samples that use these combinations. This leaves us with five different folds of the training set. Models are then trained on each fold independently, but evaluated on the same test set. We do this to control for the fact that some combinations of relations might have a similar distribution of samples as the relations picked out for the test set, making them better fits for that particular split.
As this tests out-of-distribution generalization, we argue that folding is better suited for finding the true performance and variance of the models than the more straightforward evaluation method used for our substitutivity and productivity experiments. The results are reported as the mean accuracy over all five folds.
Results The results of the systematicity tests can be seen in Table 4. As with the productivity tests, we see that there is no consistent display of generalization for any of the models across hops. We see, however, that for the 3-hops setting the two simpler models achieve some success on the task. As these models had the highest performance on the substitutivity test, we take this to indicate that additional architectural complexity does not provide any performance benefit for this type of generalization. We also note that it is possible that these experiments are sensible to the hyperparameters, and that the two simpler models happened to have a better fit for the 3-hop setting. We did not do a specific hyperparameter search per model for the systematicity experiments but relied on those from the initial hyperparameter search.
Overall, these results might come from undersampling, or it might be the case, as is reported in Hupkes et al. (2020), that the models are not able to construct useful representations of smaller syntactic units. We argue that our results further support the intuition from the substitutivity experiments: the models do not learn to create representations that correspond to each 1-hop relation, together with a function for combining them, but rather rely on memorization of whole combinations of relation types. For short-tailed distributions and some settings of hyperparameters this works, but it is not a robust solution to the general problem of matching the text questions to certain patterns in the graphs, illustrated by the significant drop in performance in these results.
We also see adjacent work on assessing compositional generalizations in LLMs to provide possible explanations for our results. Dziri et al. (2024) hypothesize that transformer-based models try to solve a highly compositional problem, like ours, by
reducing it into linearized path matching. If this is the case, models do not learn the compositional rule needed to solve the task. If the samples from the test distribution only resemble the training distribution superficially, this pattern matching approach is not a viable solution for out-of-distribution generalization in both our productivity and systematicity experiments. In these experiments, the mapping from the input samples to output labels cannot be based on surface-form frequency, due to our balanced sampling, which could then explain the collapse in performance we are observing for these experiments.

heading: 6 Previous work
text: There have been numerous works on compositional generalization in neural networks (Andreas, 2019; Lake and Baroni, 2018; Kim and Linzen, 2020; Hupkes et al., 2020; Dankers et al., 2022b; Lake and Baroni, 2023; Dziri et al., 2024). Most similar to our work is Gu et al. (2021), 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 (Shu et al., 2022). 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 (Lindemann et al., 2023). 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 (Lin et al., 2019; Zhang
et al., 2020; Yasunaga et al., 2021; Zhang et al., 2022; Kaur et al., 2022; Sun et al., 2022), 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.

heading: 7 Conclusion
text: 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.
Limitations
Models Our models are inspired by previous work. However, since our experimental setup differs from the original settings these models were implemented to work in, we had to make multiple simplifications. Consequently, we are not able to conclude anything about the abilities of the specific models from the literature, but rather about the general interaction approach they propose.
Question variety The questions in our dataset are formulated in English, and although they have more linguistic variety than similar studies from semantic parsing, such as Lake and Baroni (2018)
and Hupkes et al. (2020), we still use a rather limited version of the language, which is by design devoid of any metaphors, idioms, analogies and other constructs that would make compositionality more difficult to measure. It is not given that our results transfer to real language data.

heading: Acknowledgments
text: We acknowledge Sigma2, Norway, for awarding this project access to the LUMI supercomputer, owned by the EuroHPC Joint Undertaking, hosted by CSC (Finland) and the LUMI consortium.

heading: A Dataset generation
text: A.1 LUBM
We use the LUBM UBA to generate knowledge graphs on the fly.3 We limit our graphs to the following entity types: Professor, AssociateProfessor, UndergraduateStudent, GraduateStudent, TeachingAssistant, Publication, Course; and the following relations: PUBLICATIONAUTHOR, TEACHEROF, ADVISOR, TAKESCOURSE, TEACHINGASSISTANTOF. We also add reverse edges with reverse relations for all of these to create more diverse question types in our final dataset, making |R′LUBM | = 10. We remove all literals. Using a sample size of approximately 14 000, we create graphs that have µ = 685, σ = 77.16 nodes and µ = 4949, σ = 532 edges after processing.
A.2 Statistics
The number of possible combinations of relations on the edges in a k-hop path increases with the number of hops. As our sampling procedure uses 10 distinct relations we have 10k theoretical combinations of relations for any k-hop path. As our graphs are committed to the LUBM ontology the number of relations that hold between two entity types is much lower.
3https://swat.cse.lehigh.edu/projects/lubm/
A.3 Sampling procedure
Given a directed multigraph G = (V, E) with labeled entities vi ∈ V and labeled edges (vi, r, vj) ∈ E where r ∈ R is a relation, we sample a positive and negative example for a k-hop path using the following procedure:
1. Sample two pairs of nodes (s+ and e+) and (s− and e−) from V with uniform probability, making sure that s+ ̸= s− or e+ ̸= e−, that s+ and s− are of the same entity type, and that e+ and e− are of the same entity type.
2. Let R+ be the set of all relation paths of length k from s+ to e+
3. Let R− be the set of all relation paths of length k from s− to e−
4. Let P+ be the set R+ \R− 5. Let P− be the set R− \R+ 6. If P+ ̸= ∅ and P− ̸= ∅:
(a) Sample a relation path q: q ∼ U(P+) (b) Return the triple (q, s+, e+) as a positive example and (q, s−, e−) as a negative example.
This procedure returns a k-hop relation path, q, that holds between s+ and e+ but not between s− and e−. However, we also make sure that there are paths that hold between s− and e− but not s+ and e+, ensuring symmetry.
In addition, we shuffle entities labels while preserving entity types before running this procedure since the LUBM generator introduces problematic patterns with its entity numbering. For example, in the original graph, Professor1 is more likely to author Paper1 than Paper5. By randomly exchanging the labels of Paper1 and Paper5, we ensure the models cannot exploit this regularity.

heading: B Models
text: B.1 Parameters
All our combined models have a total of ≈ 141 000 000 parameters, with the majority of them coming from the language model. Our baseline has ≈ 30 000 000.
B.2 Computation infrastructure
All the experiments ran on the LUMI supercomputer,4 using a single AMD MI250X GPU. Running all the experiments reported in the paper has a total computing budget of approximately 150 hours.
B.3 Hyperparameters
We tune the learning rate for the text encoder from {1× 10−6, 1× 10−5, 2× 10−5, 3× 10−5, 5× 10−5}, the graph encoder module from {2×10−4, 5×10−4, 1×10−3, 2×10−3, 1×10−5}, and the MLP module from {1× 10−4, 1× 10−5}; the dropout value from {0.1, 0.2, 0.3} and the epochs from {5, 8, 10}, with no early stopping. The hyperparameters are tuned on a development set targeting the substitutivity task with an equal mix of 2, 3, and 4-hop questions. We run 60 trials for each of the five model configurations and sample a random combination of these parameters for each trial, selecting the best combination for our experiments. We find that all models perform the best with no decay on the learning rate.
4https://www.lumi-supercomputer.eu/sustainable-future/

heading: Future Work
text: eu/sustainable-future/