Syntax-guided Neural Module Distillation to Probe Compositionality in Sentence Embeddings (2023)

Abstract: Past work probing compositionality in sentence embedding models faces issues determining the causal impact of implicit syntax representations. Given a sentence, we construct a neural module net based on its syntax parse and train it end-to-end to approximate the sentence’s embedding generated by a transformer model. The distillability of a transformer to a Syntactic NeurAl Module Net (SynNaMoN) then captures whether syntax is a strong causal model of its compositional ability. Furthermore, we address questions about the geometry of semantic composition by specifying individual SynNaMoN modules’ internal architecture & linearity. We find differences in the distillability of various sentence embedding models that broadly correlate with their performance, but observe that distillability doesn’t considerably vary by model size. We also present preliminary evidence that much syntax-guided composition in sentence embedding models is linear, and that non-linearities may serve primarily to handle non-compositional phrases.

## introduction the principle of semantic compositionality suggests that the meaning of a sentence should derive from its subconstituents in a regular, structured fashion @xcite . in recent years, transformers @xcite have become effective at producing sentential meaning representations useful for downstream tasks such as natural language inference, image-text matching, and document classification @xcite . however, it has famously been conjectured that "you can't cram the meaning of a whole %&!@xmath0&!#* vector" @xcite . since recent models do appear to capture sentence meaning effectively, one wonders how they compose arbitrarily many word meanings together such that their relational structure is captured in a single, fixed-dimensional sentence embedding. much work has sought to probe these models for syntax representations and their causal relevance to embedding output. @xcite train linear probes to determine if models encode syntactic features like tree distance and depth @xcite . one line seeks out direct mappings between neural representations and tree structures @xcite @xcite @xcite . other work raises methodological issues with probing @xcite ) such as choice of formalism @xcite and semantic entanglement (maudslay and cotterell, 2021). @xcite raise the possibility that probing may identify causally un-used features; @xcite partly address this concern to show that some syntactic features are causally relevant. another line of work explores the geometry of semantic representations @xcite and the linearity @xcite of syntactic analogies @xcite . rather than directly analyze sentence embedding models, neural module nets @xcite seek to improve compositionality by modularizing semantic functions. we see this effort as ultimately similar to probing for structural representations since the former explores whether explicit structure improves performance and the latter explores whether performant models implicitly learn structure. @xcite discovers logical tree causal structures in bert and @xcite then guides model distillation using this structure. our work builds on these findings by strictly taking syntax as the causal structure of sentential semantics and linearity as the geometry of syntaxguided composition; we conduct experiments to test the distillability of transformer-based sentence embedding models to a syntactic neural module net (synnamon), an architecture we introduce that implements these two priors. the extent to which a model can be distilled to a synnamon tells us about its internal syntax representations & compositional ability. unlike prior work @xcite , synnamon modules don't approximate high-level objectives like 'find' or 'count' but rather correspond to specific syntactic rules like '@xmath1. each module receives an input of dimensionality (1, n * d) ## experiments our main experiment runs 5 sentence embedding models (bert-base @xcite , mp-net @xcite , gtr-t5-base, gtr-t5-large, and gtr-t5-xl @xcite ) on 3 synnamons with differing internal architectures (linear, nonlin, double; see sec. 2.2). for bert-base, we extract input word embeddings for each token and use the cls token as the sentence embedding as is common practice. for the other 4 models, we encode each token alone to serve as its embedding and use the output as the sentence embedding. when words are encoded as more than 1 token, we compute the mean across the subtokens to serve as its word embedding. in order to heuristically select a learning rate, 5 training runs were conducted with synnamons optimizing for bert-base, and learning rate manually set at increments between 10 -5 and 10 -3 . we finally chose a rate of 5 × 10 -5 , but recognize from results that optimal learning rate will likely vary by teacher model & synnamon internal architecture. analysis would best be reported on the optimal scores achieved by a synnamon after hyperparameter tuning, but due to compute restrictions (1 nvidia k80 gpu with 12gb of ram), this was unfeasible. additionally, due to the number of modules (originally 900, each with 1m parameters on average), we encountered frequent out-of-memory errors both on cpu & gpu. since each module corresponds to a syntax rule and is initialized upon encountering the rule in the dataset, we constrained our data to minimize the number of modules needed. specifically, we first constrained our trees to those of height 4 & 5 (@xmath2, and then further constrained the trees to those that use a subset of the 300 most common production rules among them. this resulted in 1494 trees, from which we generated a train-validation split of 1250-244. furthermore, we ensured that all the productions present in trees of the validation split were also included amongst trees in the training split. all this finally resulted in 273 production rules present in our dataset, and the instantiation of 273 modules. ## results in tab. 1, we present scores for all 5 sentence embedding models across the 3 synnamon architectures. we compute the average mse between sentence embeddings in the complete dataset for each model and divide each model's mse loss by this mean distance to normalize results. the normalized scores we present may intuitively be seen as the portion of variance in a model's sentence embeddings that a synnamon fails to explain. from a probing perspective, the lower a model's score, the more it can be causally approximated by composition along syntactic lines. sent. emb. model linear nonlin double bert-base-cls .765 4.17 .625 mp-net-base .606 .963 .538 gtr-t5-base .541 .844 .499 gtr-t5-large .550 .898 .502 gtr-t5-xl .536 .775 .498 first, notice that gtr-t5-xl outperforms all the other models across all the synnamon architectures. this seems to confirm our expectation that larger models should produce more compositional sentence embeddings. however, gtr-t5-xl only marginally outperforms other sizes of gtr-t5 (except on nonlin, for which it does far better), suggesting that size actually isn't a significant factor in compositionality. the lower performance of gtr-t5-large further corroborates this, but considering its anomalously lower average embedding mse, the issue requires more work. the fact that gtr-t5 models all display high compositionality despite variance in size suggests something about their architecture or training approach is important-perhaps the representational bottleneck. all 3 gtr-t5 models perform better than mp-net, which in turn outperforms bert cls. this first fact is slightly surprising considering that on standard sentence representation tasks @xcite , mp-net (63.30) marginally outperforms all gtr-t5 (base: 59.40, large: 62.38, xl: 62.88) models. evaluation of these sentence embedding models on large-scale, humaninterpretable compositionality tasks may reveal that gtr-t5 does indeed produce better compositional representations than mp-net. although bert's cls token embedding is widely used for sentence representation, these results show that it fails to capture nearly as much compositional information as more targeted sentence embedding models. next, observe that although distilling to a double synnamon is intuitively easier than to a linear synnamon due to increased parameterization, there aren't always major improvements in distillability. it is possible that the geometric expressivity of the double synnamon will kick in with scaling of training data, but we hypothesize that this double score will still approach a limit for all sentence embedding models. this is because syntax only describes a subset of sentence meaning, and the strictness of synnamon's structure prevents this non-compositional component from being learned. for example, a strictly syntactic compositional interpretation of "village on the river", would represent the village as being literally on top of the river since this is the semantic geometry learned for syntactic structures of the form "np on np". a synnamon that includes non-linearities may better learn the geometry of this non-literal "on" relation, but a transformer model would best learn to handle non-compositional phrases due to its lack of strict syntactic constraints. our broader takeaway from comparing linear & double scores is that much composition along syntactic lines is linear, and nonlinearities in transformers primarily serve a purpose other than syntax-guided composition-perhaps in handling non-compositional phrases. on a less theoretical note, we observe that our learning curves for linear synnamon on gtr-t5 (fig. 3 ) are clearly overfitted due to fixing hyperparameters as mentioned in sec. 3. we remediate this issue in tab. 1 by reporting the best scores (minimum across epochs) for each learning curve. since we want to construct the best possible synnamon for a transformer model (as this most accurately reveals the transformer's distillable compositional ability), scores could be slightly improved with further hyperparameter tuning. ## conclusion the human ability to apprehend the unitary meaning of a sentence corresponds to a neural model's ability to construct compositional sentence embeddings. in this work, we introduced syntactic neural module nets and used it in a distillation approach to assess how well syntax explains the sentential semantics computed by a transformer model. we showed that some models are more compositional by this metric, syntax-guided composition is largely linear, and modules learn composition functions that correspond to our semantic intuition. future work could explore this approach's alignment with other compositionality metrics and the non-compositional semantics left uncaptured by synnamons. we are also interested in how syn-namons of different linguistic formalisms vary in distillability, as well as other potential use cases of synnamons beyond probing.