Recursive Neural Networks with Bottlenecks Diagnose
  (Non-)Compositionality
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 disproportionately and then use the
bottleneck compositionality metric (BCM) to distinguish compositional from
non-compositional samples, yielding a compositionality ranking over a dataset.
Verna Dankers, Ivan Titov
# Recursive Neural Networks with Bottlenecks Diagnose

###### 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 disproportionately and then use the bottleneck compositionality metric (BCM) to distinguish compositional from non-compositional samples, yielding a compositionality ranking over a dataset.

## 1 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. Lake and Baroni, 2018; Hupkes et al., 2020) or highly-structured natural language data (e.g. Keysers et al., 2019). For such tasks, the **local compositionality** definition of Szabo (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. "the cat is in the house"), while others carry contextual dependencies (e.g. "the kiwi grows on the farm"). Can we characterise whether an input's meaning arises from strictly local compositions?

Existing work in that direction mostly focuses on providing a 'compositionality rating'1 for figurative utterances since figurative language is assumed to be less compositional (Ramisch et al., 2016; Nandakumar et al., 2019; Reddy et al., 2011). Andreas (2018) 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.

Footnote 1: We colloquially refer to the ‘compositionality ratings’ of phrases, but a more appropriate way to express the same would be to refer to the extent to which the meaning of a phrase arises from a compositional syntax and semantics’. After all, compositionality is a property of a language, not of a phrase.

Inspired by TRE, we use recursive neural networks, Tree-LSTMs (Tai et al., 2015), to process inputs according to their syntactic structure. We augment Tree-LSTMs with bottlenecks to compute

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.
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 SS2. SS3 elaborates on the models used that either apply a _deep variational information bottleneck_ (DVIB) (Alemi et al., 2017) or compress representations through increased dropout or smaller hidden dimensionalities. In SS4, we provide a proof-of-concept in a controlled environment where non-compositional examples are manually introduced, after which SS5 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.

## 2 Related Work

Multi-word expressionsThe majority of the related work in the past two decades has discussed the compositionality of phrases in the context of figurative language, such as phrasal verbs ("to eat up") (McCarthy et al., 2003), noun compounds ("cloud nine" vs "swimming pool") (Reddy et al., 2011; Yazdani et al., 2015; Ramisch et al., 2016; Nandakumar et al., 2019), verb-noun collocations ("take place" vs "take a gift") (Venkatapathy and Joshi, 2005; McCarthy et al., 2007), and adjective-noun pairs ("nice house") (Guevara, 2010). Compositionality judgements were obtained from humans, who indicated to what extent the meaning of the compound is that of the words when combined literally, and various computational methods were applied to learn that mapping. Those methods were initially thesaurus-based (McCarthy et al., 2003), relied on word vectors from co-occurrence matrices later on (Reddy et al., 2011), or employed deep neural networks (Nandakumar et al., 2019).

Compositionality by reconstruction TRE (Andreas, 2018) is a task-agnostic metric that evaluates the compositionality of data representations: \(\text{TRE}(x)=\delta(f(x),\hat{f}_{\eta}(d))\). It is the distance between the representation of \(x\) constructed by \(f\) and the compositionally reconstructed variant \(\hat{f}_{\eta}(d)\) based on the derivation of \(x\) (\(d\)). When employing the metric, one should define an appropriate distance function (\(\delta\)) and define \(\hat{f}_{\eta}\) parametrised by \(\eta\). 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.

Bhathena et al. (2020) 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. Zheng and Jiang (2022) 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 (Wray and Perkins, 2000).

Other instantiations of the TRE are from literature on language emergence in signalling games, where the degree of compositionality of that language is measured. Korbak et al. (2020) 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 Bhathena
et al. (2020) and Zheng and Jiang (2022), comparing them to our metric for sentiment analysis.

Compositional data splitsRecent 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_(Keysers et al., 2019; Shaw et al., 2021), 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, Bogin et al. (2022) 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.

## 3 Model

The model we employ is the _Tree-LSTM_(Tai et al., 2015), which is a generalisation of LSTMs to tree-structured 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\).

\[i_{t}=\sigma(W^{(i)}x_{t}+U^{(i)}h_{t-1}+b^{(i)}) \tag{1}\]

\[i_{j}=\sigma(W^{(i)}x_{j}+\sum_{\ell=1}^{N}U_{\ell}^{(i)}h_{j\ell}+b^{(i)}) \tag{2}\]

In addition to the input gate, the Tree-LSTM's specification for non-terminal \(j\) (with its \(k\)th 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 \(\sigma\) 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).

\[f_{jk}=\sigma(W^{(f)}x_{j}+\sum_{\ell=1}^{N}U_{k\ell}^{(f)}h_{j\ell}+b^{(f)}) \tag{3}\]

\[c_{j}=i_{j}\odot u_{j}+\sum_{\ell=1}^{N}f_{j\ell}\odot c_{j\ell} \tag{4}\]

\[h_{j}=o_{j}\odot\text{tanh}(c_{j}) \tag{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 (Socher et al., 2013; Tai et al., 2015). 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**.

**1. Deep Variational Information Bottleneck** The information bottleneck of Alemi et al. (2017) assumes random variables \(X\) and \(Y\) for the input and output, and emits a compressed representation \(Z\) that preserves information about \(Y\), by minimising the loss \(\mathcal{L}_{IB}\) in Equation 6. This loss is intractable, which motivates the variational estimate \(\mathcal{L}_{VIB}\) provided in Equation 7 (Alemi et al., 2017) that we use to train the **deep variational information bottleneck (DVIB)** version of our model.

\[\mathcal{L}_{IB}=\beta I(X,Z)-I(Z,Y) \tag{6}\]

\[\mathcal{L}_{VIB}=\underbrace{\beta\underset{x}{\mathbb{E}}[\text{KL}[p_{ \theta}(z|x),r(z)]]}_{\text{information loss}}+ \tag{7}\]
In the information loss, \(r(z)\) and \(p_{\theta}(z|x)\) estimate the prior and posterior probability over \(z\), respectively. In the task loss, \(q_{\phi}(y|z)\) is a parametric approximation of \(p(y|z)\). In order to allow an analytic computation of the KL-divergence, we consider Gaussian distributions \(r(z)\) and \(p_{\theta}(z|x)\), namely \(r(z)=\mathcal{N}(z|\mu_{0},\Sigma_{0})\) and \(p_{\theta}(z|x)=\mathcal{N}(z|\mu(x),\Sigma(x))\), where \(\mu(x)\) and \(\mu_{0}\) are mean vectors, and \(\Sigma(x)\) and \(\Sigma_{0}\) are diagonal covariance matrices. The reparameterisation trick is used to estimate the gradients: \(z=\mu(x)+\Sigma(x)\odot\epsilon\), where \(\epsilon\sim\mathcal{N}(0,I)\).

We sample \(z\) once per non-terminal node, and average the KL terms of all non-terminal nodes, where \(x\) is the hidden state \(h_{j}\) or the cell state \(c_{j}\) (that have separate bottlenecks), and \(\mu(x)\) and \(\Sigma(x)\) are computed by feeding \(x\) to two linear layers. \(\beta\) regulates the impact of the DVIB, and is gradually increased during training. During inference, we use \(z=\mu(x)\).

2. Dropout bottleneckBinary **dropout**(Srivastava et al., 2014) is commonly applied when training neural models, to prevent overfitting. With a probability \(p\) hidden units are set to zero, and during the evaluation all units are kept, but the activations are scaled down. Dropout encourages distributing the most salient information over multiple neurons, which comes at the cost of idiosyncratic patterns that networks may memorise otherwise. We hypothesise that this hurts non-compositional examples most. We apply dropout to the Tree-LSTM's hidden states (\(h_{j}\)) and memory cell states (\(c_{j}\)).

3. Hidden dimensionality bottleneckSimilarly, decreasing the number of **hidden units** is expected to act as a bottleneck. We decrease the number of hidden units in the Tree-LSTM, keeping the embedding and task classifier dimensions stable, where possible.

The different bottlenecks have different merits: whereas the hidden dimensionality and dropout bottlenecks shine through simplicity, they are rigid in how they affect the model and apply in the same way at every node. The DVIB allows for more flexibility in how compression is achieved through learnt \(\Sigma(x)\) and by requiring an overall reduction in the information loss term, without enforcing the same bottleneck at every node in the tree.

From bottleneck to compositionality metricBCM compares Tree-LSTMs with and without a bottleneck. We experiment with two methods, inspired by TRE (Andreas, 2018). TRE aims to find \(\eta\) such that \(\delta(f(x),\hat{f}_{\eta}(d))\) is minimised, for inputs \(x\), their derivations \(d\), distance function \(\delta\), a model \(f\) and its compositional approximation \(\hat{f}_{\eta}\).

* In the **TRE training** (BCM-TT) setup, we include the distance (\(\delta\)) between the hidden representations of \(f\) and \(\hat{f}_{\eta}\) in the loss when training \(\hat{f}_{\eta}\). When training \(\hat{f}_{\eta}\) with TRE training, \(f\) is frozen, and \(f\) and \(\hat{f}_{\eta}\) share the final linear layer of the classification module. In the arithmetic task, \(\delta\) is the _mean-squared error_ (MSE) (i.e. the squared Euclidean distance). In sentiment analysis, \(\delta\) is the Cosine distance function.
* In the **post-processing** (BCM-PP) setup, we train the two models separately, extract hidden representations and apply _canonical correlation analysis_ (CCA) (Hotelling, 1936) to minimise the distance between the sets of hidden representations. Assume matrices \(A\in\mathcal{R}^{d_{A}\times N}\) and \(B\in\mathcal{R}^{d_{B}\times N}\) representing \(N\) inputs with dimensionalities \(d_{A}\) and \(d_{B}\). CCA linearly transforms these subspaces \(A^{\prime}=WA\), \(B^{\prime}=VB\) to maximise the correlations \(\{\rho_{1},\ldots,\rho_{\text{min}(d_{A},d_{B})}\}\) of the transformed subspaces. We treat the number of CCA dimensions to use as a hyperparameter.

## 4 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.

### Data and model training

Math problems have previously been used to examine neural models' compositional reasoning (e.g. Saxton et al., 2018; Hupkes et al., 2018; Russin et al., 2021). Arithmetic expressions are suited for our application, in particular since they can be represented as trees. We use expressions containing brackets, integers -10 to 10, and + and - operators - e.g. "( 10 - ( 5 + 3 ))" (using data from Hupkes et al., 2018). The output is an integer. This is modelled as a regression problem with the MSE loss. The'meaning' (the numerical value) of a subexpression can be locally computed at each node in
the tree: there are no contextual dependencies.

In this controlled environment, we introduce exceptions by making "\(\emptyset\)" ambiguous. When located in the subtree headed by the root node's left child, it takes on its regular value, but when located in the right subtree, it takes on the value of the leftmost leaf node of the entire tree (see Figure 2). The model is thus encouraged to perform non-compositional processing to keep track of all occurrences of "\(\emptyset\)" and store the first leaf node's value throughout the tree. 88% of the training data are the original arithmetic expressions, and 12% are such exceptions. We can thus track what happens to the two categories when we introduce the bottleneck. The training data consist of 14903 expressions with 1 to 9 numbers. We test on expressions with lengths 5 to 9, using 5000 examples per length. The Tree-LSTMs trained on this dataset have embeddings and hidden states of sizes 150 and are trained for 50 epochs with learning rate \(2\mathrm{e}{-4}\) with AdamW and a batch size of 32. The base Tree-LSTMs in all setups use the same architecture, namely the Tree-LSTM architecture required for the DVIB, but with \(\beta=0\). All results are averaged over models trained using ten different random seeds. In the Tree-LSTM, the numbers are leaf nodes and the labels of non-terminal nodes are the operators.2

Footnote 2: Appendix C further elaborates on the experimental setup.

### Task performance: Hierarchy without compositionality?

Figures 2(a) and 2(b) visualise the performance for the regular examples and exceptions, respectively, when increasing \(\beta\) for the DVIB. The DVIB disproportionately harms the exceptions; when \(\beta\) is too high the model cannot capture the non-local dependencies. Appendix A.1 shows how the hidden dimensionality and dropout bottlenecks have a similar effect. Figure 4 and Appendix A.2 provide insights in the training dynamics of the models: initially, all models will treat "\(\emptyset\)" as a regular number, independent of the bottleneck. Close to convergence, models trained with a low \(\beta\) have learnt to capture the ambiguities, whereas models trained with a higher \(\beta\) will remain in a more locally compositional state.3

Footnote 3: Comparing ‘early’ and ‘late’ models may yield similar results as comparing base and bottleneck models. Yet, without labels of which examples are compositional, it is hard to know when the model transitions from the early to the late stage.

Bottlenecks restrict information passed throughout the tree. To process an arithmetic subexpression, all that is needed is to pass on its outcome, not the subexpression itself - e.g. in Figure 2, one could simply store the value 6 instead of the subexpression "2 - -4". The former represents _local processing_ and is more efficient (i.e. it requires storing less information), while the latter leads to information from the leaf nodes being passed to non-terminal nodes higher up the tree. Storing information about the leaf nodes would be required to cope with the exceptions in the data. That the model could get close to accurate predictions for these exceptions in the first place suggests Tree-LSTMs can process inputs according to the hierarchical structure without being locally compositional. Increasing compression using bottlenecks enforces local processing.

Figure 4: Training dynamics for the Tree-LSTM with the DVIB: for all test examples we compute the MSE over the course of training on the validation set using (a) the compositional targets, or (b) the targets from the adapted dataset, of which a subset is not compositional.

Figure 3: Performance (MSE) on the arithmetic task for the Tree-LSTM with the DVIB (darker colours correspond to higher \(\beta\)). Exceptions have a contextual dependency and cannot be computed bottom up.

Figure 2: Illustration of the ‘exceptions’ in the arithmetic task: the value of “\(\emptyset\)” depends on its position and on the value of the leftmost leaf node in the tree.
### The Bottleneck Compositionality Metric

The bottleneck Tree-LSTM harms the exceptions disproportionately in terms of task performance, and through BCM we can exploit the difference between the base and bottleneck model to distinguish compositional from non-compositional examples. As laid out in SS3, we use the TT or PP method to compare pairs of Tree-LSTMs: the base Tree-LSTM with \(\beta=0\), no dropout and a hidden dimension of 150 (**base model**) is paired up with Tree-LSTMs with the same architecture, but a different \(\beta\), a different dropout probability \(p\) or a different hidden dimensionality \(d\) (**bottleneck model**). All Tree-LSTMs have a classification module that consists of two linear layers, where the first layer maps the Tree-LSTM's hidden representation to a vector of 100 units, and the second layer emits the predicted value. The 100-dimensional vector is used to apply the BCM:

* In BCM-PP the vector feeds into the CCA computation, that compares the hidden representation of the base model and the bottleneck model using their Cosine distance. We rank examples according to that distance, and use all CCA directions.
* In BCM-TT, the vector feeds into the TRE loss component. We train the base model, freeze that network, and add the MSE of the hidden representations of the bottleneck model and the base model to the loss. After training, the remaining MSE is used to rank examples.

Both setups have the same output, namely a compositionality ranking of examples in a dataset. A successful ranking would put the exceptions last. Figure 4(a) illustrates the relative position of regular examples and exceptions for all bottlenecks and BCM variants, for \(\beta=0.25\), \(p=0.5\) and \(d=25\). The change in MSE observed in SS4.2 is reflected in the quality of the ranking, but the success does not depend on the specific selection of \(\beta\), \(p\) or \(d\), as long as they are large (\(\beta\), \(p\)) or small enough (\(d\)). Figure 4(b) illustrates one of the rankings.

Summarising, we illustrated that recursive models can employ strategies that do not locally compose the meaning of arithmetic subexpressions but carry tokens' identities throughout the tree. We can make a model more locally compositional using bottlenecks and can use a model's hidden states to infer which examples required non-local processing afterwards, acting as our compositionality metric.

## 5 Sentiment analysis

We apply the metric to the task of sentiment analysis, for which Moilanen and Pulman (2007, p. 1) suggest the following notion of compositionality:

"For if the meaning of a sentence is a function of the meanings of its parts then the global polarity of a sentence is a function of the polarities of its parts."

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" (Barnes et al., 2019), which makes it a suitable testing bed.

### Data and model training

We use the SST-5 subtask from the Stanford Sentiment Treebank (SST) (Socher et al., 2013), that contains sentences from movie reviews collected

Figure 5: Rankings of arithmetic examples. (a) shows the relative position of regular examples and exceptions in the rankings of all setups, where 0 corresponds to the start of the ranking and 1 to the end. (b) illustrates the result of BCM-TT with the DVIB, \(\beta=0.25\).

Figure 6: The accuracy (solid) and macro-averaged \(F_{1}\)-scores (dashed) for the SST test set, for base models, bottleneck models and a sentiment-only baseline.
by Pang and Lee (2005). The SST-5 subtask requires classifying sentences into one of five classes ranging from very negative to very positive. The standard train, development and test subsets have 8544, 1101 and 2210 examples, respectively. The sentences were originally parsed with the Stanford Parser (Klein and Manning, 2003), and the dataset includes sentiment labels for all nodes of those parse trees. Typically, labels for all phrases are included in training, but the evaluation is conducted for the root nodes of the test set, only.

Following Tai et al. (2015), we use GloVe word embeddings (Pennington et al., 2014), that we freeze across models.4 The Tree-LSTM has 150 hidden units and is trained for 10 epochs with a learning rate of \(2\mathrm{e}{-4}\) and the AdamW optimiser. During each training update, the loss is computed over all subexpressions of 4 trees. Training is repeated with 10 random seeds.5 Figure 6 provides the performance on the test set for the base and bottleneck models, using the accuracy and the macro-averaged \(F_{1}\)-score. Tai et al. (2015) obtained an accuracy of 0.497 using frozen embeddings.

Footnote 4: The notion of local compositionality, relied on in this work, assumes that tokens are not disambiguated, which is why we refrain from using state-of-the-art contextualised representations. The focus of this work is on developing a compositionality metric rather than on improving sentiment analysis.

Footnote 5: Appendix C further elaborates on the experimental setup.

In sentiment analysis, as in our pseudo-arithmetic task, a successful model would often have to deviate from local processing. After all, the correct interpretation of a leaf node is often unknown without access to the context - e.g. in the case of ambiguous words like "sick" which is likely to refer to being ill, but could also mean "awesome". Being successful at the task thus requires a recursive model to keep track of information about (leaf) nodes while recursively processing the input, and more so for non-compositional examples than for compositional examples. As with the arithmetic task, local processing - enforced in the bottleneck models - should disproportionately hinder processing of non-compositional examples.

### A sentiment-only baseline

To assert that the bottlenecks make the models more compositional, we create a sentiment-only baseline that is given as input not words but their sentiment, and has a hidden dimensionality \(d=25\). Non-compositional patterns that arise from the composition of certain words rather than the sentiment of those words (e.g. "drop dead gorgeous") could hardly be captured by that model. As such, the model exemplifies how sentiment can be computed more compositionally. Figure 7 illustrates the default sentiment this model predicts for various input combinations. Its predictions can be characterised by i) predicting **positive** for positive inputs, ii) predicting **negative** for negative inputs, iii) predicting **neutral** if one input is neutral, iv) predicting a class **in between** the input classes or as v) predicting the same class as its inputs (**continuity**).

The performance of the model is included in Figure 6, and Figure 8 (a-c) indicates the Pearson's \(r\) between the sentiment predictions of bottleneck models and baseline models. Generally, a higher \(\beta\) or dropout probability, or a lower hidden dimen

Figure 8: Pearson’s \(r\) for the predictions of sentiment-only baselines and bottleneck models (a-c) and Spearman’s \(\rho\) for the SST validation set compositionality ranking of the baselines and bottleneck models (d-f), when varying the number of CCA dimensions used.

Figure 7: Illustration of the predictions of a sentiment-only baseline model. We indicate the predicted sentiment given two inputs. The labels range from very negative (‘- -’) to neutral (‘\(\sim\)’) to very positive (‘++’).
sionality, leads to predictions that are more similar to this sentiment-only model, unless the amount of regularisation is too extreme, debilitating the model (e.g. for dropout with probability 0.9).

### The Bottleneck Compositionality Metric

Now we use BCM to obtain a ranking over the SST dataset. We separate the dataset into four folds, train on those folds for the base and bottleneck model, and compute the cosine distances for the hidden representations of examples in the test sets (using BCM-PP or BCM-TT). We merge the cosine distances for the different folds, averaged over models trained with 10 random seeds, and order examples based on the resulting distance. We select the values for \(\beta\), dropout and the hidden dimensionality, as well as the number of CCA directions to use, based on rankings computed over the SST validation data. Figure 8 (d-f) illustrates how the rankings of bottleneck models correlate with rankings constructed using the sentiment-only baseline. We select 25 directions, \(\beta=0.0025\), dropout \(p=0.65\) and a hidden dimensionality of 25 to compute the full ranking. Contrary to the arithmetic task, BCM-TT underperforms compared to BCM-PP.

Different from the arithmetic task, it is unclear which examples _should_ be at the start or end of the ranking. Therefore, we examine the relative position of categories of examples in Figure 9 for the BCM-PP with the hidden dimensionality bottleneck, and in Appendix B.3 for the remaining rankings. The categories include the previously introduced ones, augmented with the following four:

* **amplification**: the root is even more positive/negative than its top two children;
* **attenuation**: the root is less positive/negative than its top two children;
* **switch**: the children are positive/negative, but the root node flips that sentiment;
* **neutral\(\leftrightarrow\)polarised**: the inputs are sentiment-laden, but the root is neutral, or vice versa.

We also include characterisations from Barnes et al. (2019), who label examples from the SST test set, for which state-of-the-art sentiment models cannot seem to predict the correct label, including, for example, cases where a sentence contains mixed sentiment, or sentences with idioms, irony or sarcasm. Appendix B.1 elaborates on the meaning of the categories. Figure 9 illustrates the relative positions of our sentiment characterisations and those of Barnes et al. on that ranking. Patterns associated with more compositional sentiment processing, such as 'positive', 'negative' and 'in between' lead to hidden representations that are more similar between the base model and bottleneck models than the dataset average (the mid point, 0.5). Atypical patterns like'switch' and 'neutral\(\leftrightarrow\)polarised', on the other hand, along with the characterisations by Barnes et al. lead to less similar hidden representations. Appendix B.3 presents the same results for all six rankings considered, along with example sentences from across the ranking, to illustrate the types of sentences encountered among the most compositional and the least compositional ones.

### Example use cases

Compositionality rankings can be used in multiple manners, of which we illustrate two below.

When data is scarce: use compositional examplesAssuming that most of natural language _is_ compositional, one would expect that when limiting the training data, selecting compositional examples yields the best test performance. To investigate this, we train models on various training dataset sizes, and evaluate with the regular test set. The training data is taken from the start of the ranking for the 'compositional' setup, and from the end of the ranking for the 'non-compositional' setup

Figure 9: Categories of SST examples and their average position on the compositionality ranking visualised for the BCM-PP with the hidden dimensionality bottleneck and \(d=25\). Categories in black are assigned by us; categories in gray are from Barnes et al. (2019). The categories are further explained in the main text and Appendix B.1. Jittering was applied to better visualise overlapping categories.
(excluding test data), while ensuring equal distributions over input lengths and output classes. We train a two-layer bidirectional LSTM with 300 hidden units, and Roberta-base Liu et al. (2019), using batch size 4. The models are trained for 10 and 5 epochs, respectively, with learning rates \(2e-4\) and \(5e-6\). Because the ranking is computed over full sentences, and not subexpressions, we train the models on the sentiment labels for the root nodes. Figure 10 presents the results, consolidating that when data is scarce, using compositional examples is beneficial.

**Non-compositional examples are challenging** For the same models, Table 1 indicates how performance changes if we redistribute train and test data such that the test set contains the most compositional examples, or the least compositional ones (keeping length and class distributions similar). The non-compositional test setup is more challenging, with an 11 percentage point drop in accuracy for the LSTM, and a 3 point decrease for Roberta.

In conclusion, applying the BCM to the sentiment data has confirmed findings previously observed for the arithmetic toy task. While it is harder to understand whether the method actually filters out non-compositional examples, both comparisons to a sentiment-only baseline, and the average position of cases for which the composition of sentiment is known to be challenging (e.g. for'mixed' sentiment, 'comparative' sentiment or'sarcasm'), suggest that compression acts as a compositionality metric. We also illustrated two ways in which the resulting ranking can be used.

## 6 Conclusion

This work presents the Bottleneck Compositionality Metric, a TRE-based metric Andreas (2018) 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 compositionality-based 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.

\begin{table}
\begin{tabular}{l c c c c c c} \hline \hline
**Model** & \multicolumn{2}{c}{**Comp.**} & \multicolumn{2}{c}{**Non-comp.**} & \multicolumn{2}{c}{**Random**} \\  & Acc. & \(F_{1}\) & Acc. & \(F_{1}\) & Acc. & \(F_{1}\) \\ \hline Roberta &.546 &.535 &.516 &.487 &.565 &.549 \\ LSTM &.505 &.485 &.394 &.310 &.478 &.447 \\ \hline \hline \end{tabular}
\end{table}
Table 1: Performance on the new SST compositionality splits, generated using the ranking from the BCM-PP metric with the hidden dimensionality bottleneck.

Figure 10: Change in SST test set accuracy (solid) and macro-averaged \(F_{1}\)-score (dashed) as the training set size increases, for LSTM and Roberta models. The examples are from the most (in blue) or the least compositional (in green) portion of the ranking from the BCM-PP metric with the hidden dimensionality bottleneck.
### Limitations

We identify three types of limitations for the work presented:

* A **conceptual limitation** is that we work from a very strict definition of compositionality (_local_ compositionality), which essentially equates language with arithmetic. While overly restrictive, current datasets testing compositional generalisation follow this notion. The framework might be extensible to more relaxed notions by allowing for token disambiguation by using contextualised token embeddings and only enforcing a bottleneck on the amount of further contextual integration within the model added on top of the token embeddings.
* although well-motivated from the perspective of compositional processing
- is a major limitation. Tree-LSTMs are most suited for sentence classification tasks, limiting the approach's applicability to sequence-to-sequence tasks. Nonetheless, the bottlenecks can be integrated in other types of architectures that process inputs in a hierarchical manner, such as sequence-to-sequence models inducing latent source and target trees [15] to yield an alternative implementation of the BCM. Our work also assumes that an input's tree structure is known, which might not always be the case. Therefore, the compositionality ranking obtained using BCM always depends on the trees used: what is non-compositional given one (potentially inadequate) structure might be more compositional given another (improved) structure.
* Lastly, the **evaluation** of our approach is limited in the natural domain through the absence of gold labels of the compositionality of examples in the sentiment analysis task, but for other tasks that could have been considered, the same limitation would have applied.

## Acknowledgements

We thank Chris Lucas for his contributions to this project when it was still in an early stage, Kenny Smith for his comments on the first draft of this paper, and Matthias Lindemann for excellent suggestions for the camera-ready version. VD is supported by the UKRI Centre for Doctoral Training in Natural Language Processing, funded by the UKRI (grant EP/S022481/1) and the University of Edinburgh, School of Informatics and School of Philosophy, Psychology & Language Sciences. IT acknowledges the support of the European Research Council (ERC StG BroadSem 678254) and the Dutch National Science Foundation (NWO Vidi 639.022.518).
