Data Factors for Better Compositional Generalization (2023)

Abstract: Recent diagnostic datasets on compositional generalization, such as SCAN (Lake and Baroni, 2018) and COGS (Kim and Linzen, 2020), expose severe problems in models trained from scratch on these datasets. However, in contrast to this poor performance, state-of-the-art models trained on larger and more general datasets show better generalization ability. In this work, to reconcile this inconsistency, we conduct an empirical analysis by training Transformer models on a variety of training sets with different data factors, including dataset scale, pattern complexity, example difficulty, etc. First, we show that increased dataset complexity can lead to better generalization behavior on multiple different generalization challenges. To further understand this improvement, we show two axes of the benefit from more complex datasets: they provide more diverse examples so compositional understanding becomes more effective, and they also prevent ungeneralizable memorization of the examples due to reduced example repetition frequency. Finally, we explore how training examples of different difficulty levels influence generalization differently. On synthetic datasets, simple examples invoke stronger compositionality than hard examples do. On larger-scale real language datasets, while hard examples become more important potentially to ensure decent data coverage, a balanced mixture of simple and hard examples manages to induce the strongest generalizability.

## introduction many recent diagnostic datasets, e.g., @xcite , cogs @xcite , etc., have exposed the compositional generalization problem of neural sequence-to-sequence (seq2seq) models. they show that seq2seq models that are trained from scratch fail miserably when tested on examples containing novel combinations of seen elements. however, in contrast to these results, models trained (or pretrained) on larger datasets, (including t5 @xcite , palm @xcite , etc.) show substantially better performance @xcite for compositional generalization. while some factors behind many of these improvements are the emergent abilities from scaling up @xcite , we explore an alternative and complementary angle: how and why does training on more complex datasets help a general transformer model, with limited size and capacity, generalize compositionally to unseen natural language queries? to answer this question, we empirically study how changes in data factors (e.g., scale, diversity, difficulty, etc.) influence the generalization ability of models trained from scratch. our first analysis is inspired by @xcite and @xcite , who make the model generalize significantly better on scan simply by increasing the number of unique primitives. we extend this observation in several directions and further explore where this gain comes from. our experiments show that this is not a special observation on scan for the jump and around right split. instead, the same effect can be observed on multiple different types of generalization challenges (e.g., primitive-level generalization, length-level extrapolation, etc.), and on both synthetic and reallanguage datasets. to summarize our first direction of analysis, there is a strong connection between increased dataset complexity and better compositional generalization. second, we try to understand why more complex datasets lead to better generalization. we build up our analysis by comparing two potentially competing behaviors of the models: surface memorization (i.e., memorizing the direct mapping from inputs to outputs without understanding the underlying composition), and compositional understanding i can't memorize all of them! original data more complex data walk left and walk twice composition walk lturn walk walk walk walk left twice sprint left and jog twice sprint lturn jog jog sprint jog left twice now i'd rather compose. dataset complexity example difficulty difficult (4 unique primitives per example) easy (2 unique primitives per example) walk left and jog twice and sprint right and look lturn walk jog jog sprint rturn look walk left and jog twice and jog left and walk walk left jog twice jog left walk lturn walk jog jog lturn jog walk @xmath0.e., first discovering a set of compositional rules from examples and then applying the rules for predictions). please also refer to the left part in figure 1 for an illustration. while both behaviors can lead to near-perfect training-set performance, only the latter guarantees good generalization performance. we argue that more complex datasets improve compositional generalization as they provide substantial obstacles to surface memorization. specifically, we make two hypotheses: (1) diversity: more diverse patterns (e.g., more unique primitives) exemplified in complex datasets increase the difficulty of surface memorization; (2) frequency: the larger dataset size causes a decrease in the frequency of seeing similar examples, thus preventing their memorization. to empirically confirm these hypotheses, we provide detailed ablations showing how both factors contribute to empirical gains in data augmentation. to further isolate the effect of frequently recurring examples, we show that deliberately encouraging example repetition even in a large dataset brings substantial detriment to the generalization performance. furthermore, as a corollary to our hypotheses, we provide a simple yet effective data augmentation method augzero that satisfies both contributing factors without utilizing any dataset-specific knowledge. finally, we provide a more fine-grained analysis to study how examples of different difficulties inside a dataset affect generalization. our analysis covers both smaller, synthetic datasets and larger-scale, real-language datasets. on synthetic datasets (e.g., scan), we create multiple versions of the datasets strictly controlling the difficulty of the examples in each version, and show that simpler examples facilitate compositional generalization more than difficult examples. on sub-sampling experiments in real-language datasets (e.g., atis, smcalflow), we observe similar but more complicated trends. potentially due to the need to cover all the diverse natural language phenomena, simple examples alone are not enough for achieving good performance, however mixing difficult examples with simple examples is still beneficial on the compositional dataset smcalflow-cs. in conclusion, we present an empirical study on how data factors influence compositional generalization behavior. we notice: (1) increased dataset complexity can improve the model's generalization ability; (2) increased complexity creates obstacles for surface memorization by having a higher cost of memorization and less recurring frequency of examples; (3) example difficulty can influence generalization substantially with simpler examples benefiting compositional generalization more. ## understanding the advantages brought by increased complexity we further explore how increased complexity improve generalization. we will first provide a discussion on dataset complexity and model behaviors. then, we will state our hypotheses on how data complexity impacts generalization by influencing the model behaviors. finally, we provide supporting experiments. ## which examples benefit generalization the most: a difficulty perspective previously, we demonstrate and explain that increasing the complexity of the whole dataset can improve compositional generalization. in practice, examples inside a dataset have different properties (e.g., difficulty, topic, etc.) and thus may influence generalization differently. in this section, we present a study from the difficulty perspective. we will start with a discussion on the definition of difficulty, and then show how example-level difficulty can substantially influence compositional generalization on both synthetic and real datasets. for this section, we report results with three runs as the dataset sizes are substantially larger. ## discussion advantage of large-scale pretraining. in this work, we have demonstrated how different data factors (e.g., scale, diversity, example difficulty, etc.) can substantially improve the model's ability to generalize compositionally. while our experiments are done on a smaller scale, these results also hint at why models pretrained on larger datasets show better generalization ability. we argue that doing large-scale pretraining implicitly satisfies many beneficial data factors studied in this work. during pretraining, models are exposed to a large set of different structures and primitives. additionally, pretraining datasets have a large size that prevents frequent repetition and contains a diverse set of simple and difficult examples. all these conditions incentives the emergence of compositional generalization ability. how about fine-tuning models? in our main experiments, we choose to not use pretrained models as they already possess a substantial amount of knowledge, which makes it very difficult to evaluate how models initially acquire compositionality. nonetheless, as fine-tuning models are of great practical importance, here we discuss related issues about fine-tuning models and summarize our preliminary findings with t5 models (more details are in appendix h.2). the behaviors of fine-tuning models are slightly different. we notice that the size and the diversity of the dataset can still be important as repetitive training on similar examples (e.g., with the same primitive) will cause substantial overfitting and hurt the pretrained model. however, as pretrained models already have a good understanding of basic language compositionality, they may need less assistance from the data, so maintaining a large number of different primitives or simple examples may be less important. overall, our results suggest that when fine-tuning on small datasets, data augmentation methods increasing the size and diversity may help the model's compositional generalization performance. ## conclusion we empirically study how dataset factors influence compositional generalization. we show that increased dataset complexity facilitates compositional generalization, with dataset size and pattern complexity as two important factors behind the gain. we also provide an analysis of example difficulty and discuss the implication of our work on pertaining and fine-tuning models.