Recursive Neural Networks with Bottlenecks Diagnose (Non-)Compositionality (2022)

Abstract: A recent line of work in NLP focuses on the (dis)ability of models to generalise compositionally for artificial languages.However, when considering natural language tasks, the data involved is not strictly, or locally, compositional.Quantifying the compositionality of data is a challenging task, which has been investigated primarily for short utterances.We use recursive neural models (Tree-LSTMs) with bottlenecks that limit the transfer of information between nodes.We illustrate that comparing data’s representations in models with and without the bottleneck can be used to produce a compositionality metric.The procedure is applied to the evaluation of arithmetic expressions using synthetic data, and sentiment classification using natural language data.We demonstrate that compression through a bottleneck impacts non-compositional examples disproportionatelyand then use the bottleneck compositionality metric (BCM) to distinguish compositional from non-compositional samples, yielding a compositionality ranking over a dataset.

## introduction compositional generalisation in contemporary nlp research investigates models' ability to compose the meanings of expressions from their parts and is often investigated with artificial languages (e.g. @xcite or highly-structured natural language data (e.g. @xcite . for such tasks, the local compositionality definition of szabó (2012, p. 10) illustrates how meaning can be algebraically composed: "the meaning of a complex expression is determined by the meanings its constituents have individually and the way those constituents are combined." in natural language, there are fragments whose meaning can be composed as with arithmetic (e.g. figure 1 : when processing this phrase, "the ruler" is interpreted differently when comparing recursive processing with local processing. we enforce local processing by equipping models with bottlenecks, and our bottleneck compositionality metric (bcm) then compares inputs' representations before and after compression through the bottleneck. existing work in that direction mostly focuses on providing a 'compositionality rating' foot_0 for figurative utterances since figurative language is assumed to be less compositional @xcite @xcite . @xcite suggests a general-purpose formulation for measuring the compositionality of examples using their numerical representations, through the tree reconstruction error (tre), expressing the distance between a model's representation of an input and a strictly compositional reconstruction of that representation. determining how to compute that reconstruction is far from trivial. inspired by tre, we use recursive neural networks, tree-lstms @xcite , to process inputs according to their syntactic structure. we augment tree-lstms with bottlenecks to compute the task-specific meaning of an input in a more locally compositional manner. we use these models to distinguish more compositional examples from less compositional ones in a bottleneck compositionality metric (bcm). figure 1 provides an intuition for how a bottleneck can provide a metric. for fragments that violate the assumption that meanings of subexpressions can be computed locally (on the left side), one could end up with different interpretations when comparing a contextualised interpretation (in blue) with one locally computed (in green): disambiguating "ruler" requires postponed meaning computation, and thus local processing is likely to lead to different results from regular processing. for fragments that are non-ambiguous (on the right side) the two types of processing can yield the same interpretation because the interpretation of "pencil" is likely to be the same, with or without the context. the bottleneck hinders the model in postponing computations and more strongly impacts non-compositional samples compared to compositional ones, thus acting as a metric. in the remainder of the paper, we firstly discuss the related work in §2. §3 elaborates on the models used that either apply a deep variational information bottleneck (dvib) @xcite or compress representations through increased dropout or smaller hidden dimensionalities. in §4, we provide a proof-of-concept in a controlled environment where non-compositional examples are manually introduced, after which §5 elaborates on the natural language example of sentiment analysis. for both tasks, we (1) demonstrate that compression through a bottleneck encourages local processing and (2) show that the bottleneck can act as a metric distinguishing compositional from less compositional examples. compositionality by reconstruction tre (andreas, 2018) is a task-agnostic metric that evaluates the compositionality of data representations: tre(x) = δ(f (x), fη (d)). it is the distance between the representation of x constructed by f and the compositionally reconstructed variant fη (d) based on the derivation of x (d). when employing the metric, one should define an appropriate distance function (δ) and define fη parametrised by η. andreas illustrates the tre's versatility by instantiating it for three scenarios: to investigate whether image representations are similar to composed image attributes, whether phrase embeddings are similar to the vector addition of their components, and whether generalisation accuracy in a reference game positively correlates with tre. @xcite present two methods based on tre to obtain compositionality ratings for sentiment trees, referred to as tree impurity and weighted node switching that express the difference between the sentiment label of the root and the other nodes in the tree. @xcite ranked examples of sentiment analysis based on the extent to which neural models should memorise examples in order to capture their target correctly. while different from tre, memorisation could be related to non-compositionality in the sense that non-compositional examples require more memorisation, akin to formulaic language requiring memorisation in humans @xcite . other instantiations of the tre are from literature on language emergence in signalling games, where the degree of compositionality of that language is measured. @xcite contrast tre and six other compositionality metrics for signalling games where the colour and shape of an object are communicated. examples of such metrics are topographic similarity, positional disentanglement and context independence. these are not directly related to our work, considering that they aim to provide a metric for a language rather than single utterances. appendix b.2 elaborates on topographic similarity and the metrics of @xcite and zheng and jiang (2022), comparing them to our metric for sentiment analysis. compositional data splits recent work on compositional generalisation using artificial languages or highly-structured natural language data focuses on creating data splits that have systematic separation of input combinations in train and test data. the aim is to create test sets that should not be hard when computing meaning compositionally, but, in practice, are very challenging. an example compositionality metric for semantic parsing is maximum compound divergence @xcite , that minimises train-test differences in word distributions while maximising the differences in compound usage. this only applies to a data split as a whole, and -differently from the work at hand -does not rate individual samples. more recently, @xcite discussed a diagnostic metric for semantic parsing, that predicts model success on examples based on their local structure. because models struggle with systematically assigning the same meaning to subexpressions when they re-appear in new syntactic structures, such structural deviation diagnoses generalisation failures. notice that the aim of our work is different, namely identifying examples that are not compositional, rather than investigating generalisation failure for compositional examples. ## model the model we employ is the tree-lstm @xcite , which is a generalisation of lstms to treestructured network topologies. the lstm computes symbols' representations by incorporating previous time steps, visiting symbols in linear order. a sentence representation is simply the final time step. a tree-lstm, instead, uses a tree's root node representation as the sentence representation, and computes the representation of a non-terminal node using the node's children. equations 1 and 2 illustrate the difference between the lstm and an n -ary tree-lstm for the input gate. the lstm computes the gate's activation for time step t using input vector x t and previous hidden state h t-1 . the tree-lstm does so for node j using the input vector x j and the hidden states of up to n children of node j. in addition to the input gate, the tree-lstm's specification for non-terminal j (with its kth child indicated as h jk ) involves an output gate o j (equation analogous to 2), a forget gate f jk (equation 3 ), cell input activation vector u j (equation analogous to 2, with the σ function replaced by tanh), and memory cell state c j (equation 4 ). finally, c j feeds into the computation of hidden state h j (equation 5). we apply a binary tree-lstm to compute hidden state h j and memory cell state c j , that thus uses separate parameters in the gates for the left and right child. tree-lstms process inputs according to their syntactic structure, which has been associated with more compositional processing @xcite . yet, although the topology encourages compositional processing, there is no mechanism to explicitly regulate how much information is passed from children to parent nodes -e.g. given enough capacity, the hidden representations could store every input encountered and postpone processing until the very end. we add such a mechanism by introducing a bottleneck. ## proof-of-concept: arithmetic given a task, we assign ratings to inputs that express to what extent their task-dependent meaning arises in a locally compositional manner. to investigate the impact of our metric on compositional and non-compositional examples in a controlled environment, we first use perfectly compositional arithmetic expressions and introduce exceptions to that compositionality manually. ## sentiment analysis we apply the metric to the task of sentiment analysis, for which @xcite suggest the following notion of compositionality: sentiment is quasi-compositional: even though the sentiment of an expression is often a straightforward function of the sentiment of its parts, there are exceptions -e.g. consider cases of sarcasm, such as "i love it when people yell at me first thing in the morning" @xcite , which makes it a suitable testing bed. ## conclusion this work presents the bottleneck compositionality metric, a tre-based metric @xcite that is task-independent and can be applied to inputs of varying lengths: we pair up tree-lstms where one of them has more compressed representations due to a bottleneck (the dvib, hidden dimensionality bottleneck or dropout bottleneck), and use the distance between their hidden representations as a per-datum metric. the method was applied to rank examples in datasets from most compositional to least compositional, which is of interest due to the growing relevance of compositional generalisation research in nlp, which assumes the compositionality of natural language, and encourages models to compose meanings of expressions rather than to memorise phrases as chunks. we provided a proof-of-concept using an arithmetic task but also applied the metric to the much more noisy domain of sentiment analysis. the different bottlenecks lead to qualitatively similar results. this suggests that, while dvib might be better motivated (it directly optimises an estimate of the shannon information passed across the network), its alternatives may be preferable in practice due to their simplicity. because natural language itself is not fully compositional, graded metrics like the ones we presented can support future research, such as i) learning from data according to a compositionalitybased curriculum to improve task performance, ii) filtering datasets to improve compositional generalisation, or iii) developing more and less compositional models depending on the desiderata for a task -e.g. to perform well on sentences with idioms, one may desire a more non-compositional model. in addition, the formulation of the metric was general enough to be expanded upon in the future: one could pair up other models, such as an lstm and a tree-lstm, or a transformer and its recursive variant, as long as one keeps in mind that the compositional reconstruction itself should not be too powerful. after all, even tree-lstms could capture the exceptions in the arithmetic dataset despite their hierarchical inductive bias.