Statistical Depth for Ranking and Characterizing Transformer-Based Text Embeddings (2023)

Abstract: The popularity of transformer-based text embeddings calls for better statistical tools for measuring distributions of such embeddings. One such tool would be a method for ranking texts within a corpus by centrality, i.e. assigning each text a number signifying how representative that text is of the corpus as a whole. However, an intrinsic center-outward ordering of high-dimensional text representations is not trivial. A \textit{statistical depth} is a function for ranking k -dimensional objects by measuring centrality with respect to some observed k -dimensional distribution. We adopt a statistical depth to measure distributions of transformer-based text embeddings, \textit{transformer-based text embedding (TTE) depth} , and introduce the practical use of this depth for both modeling and distributional inference in NLP pipelines. We first define TTE depth and an associated rank sum test for determining whether two corpora differ significantly in embedding space. We then use TTE depth for the task of in-context learning prompt selection, showing that this approach reliably improves performance over statistical baseline approaches across six text classification tasks. Finally, we use TTE depth and the associated rank sum test to characterize the distributions of synthesized and human-generated corpora, showing that five recent synthetic data augmentation processes cause a measurable distributional shift away from associated human-generated text.

## introduction the transformer architecture @xcite has revolutionized the field of natural language processing (nlp). generalized transformer-based text embedding models such as s-bert @xcite and gense+ @xcite have yielded state of the art performance results on a variety of tasks such as natural language inference (nli) @xcite and semantic textual similarity (sts) @xcite . the figure 1 : tte depth gives a center-outward ordering of texts within a corpus using their representations in embedding space. this statistical tool can be used in modeling tasks and inference tasks. examples from the microsoft research paraphrase corpus @xcite demonstrate that representative samples from the corpus receive high depth scores and outliers receive low depth scores. a statistical depth is a function for ordering multidimensional objects with respect to some observed distribution. depths have been defined for functional data @xcite , directional data @xcite , and statistical representations of text data @xcite . in addition to offering an ordering for a single collection of multidimensional objects, a statistical depth also enables testing for significant differences between two distributions of such objects. we introduce a statistical depth for transformer-based text embeddings, tte depth, which provides a center-outward ordering of texts within a corpus based on the distributional properties of the texts in embedding space. a diagram of this tool is given in figure 1 . while there exist approaches for characterizing corpus distributions such as perplexity @xcite and more recent approaches like mauve @xcite , tte depth is an orthogonal statistical tool that gives an intuitive centrality ranking for use in both modeling and distributional inference in nlp pipelines. we investigate the use of depth in both modeling, via the task of prompt selection for in-context learning, and distributional characterization, via measuring the distributional differences between synthetic data and human-written data in synthetic data augmentation pipelines. the specific contributions of this work are as follows. ## transformer-based text embedding depth angular distance properties of text embeddings, such as high cosine similarity between embeddings of two similar texts, are often sought as a desired property of such embeddings @xcite . as such, we utilize an angular distance-based depth for our investigation. a class of angular distance-based depths for directional data was first introduced by @xcite , and later used by @xcite for classification of directional data. leaning on two depth definitions as introduced there we define a depth for transformer-based text embeddings, tte depth. tte depth: consider a set of embedded texts f derived from the theoretical set of all possible such documents s, each embedded by some text embedding model m : @xmath0. given a bounded distance δ(•, •) : r k × r @xmath1, the tte depth of an embedded text @xmath2 the cosine distance δ cos (•, •) between two embedded text documents x, @xmath3, 2019). it is defined as for any two embedded texts x, @xmath4, the chord distance δ ch (•, •) between the two is defined as while we primarily investigate tte depth using cosine distance, either cosine distance or chord distance can be used for calculating tte depth. using either distance function, we define the median of f, denoted x 0 , to be the text embedding in f with maximum depth. in other words, max @xmath5, f) = d δ (x 0 , f). tte depth produces this well-defined median at the center of the set of text embeddings f. ordering the text embeddings in f by tte depth gives a center-outward ranking of all text embeddings within a corpus. wilcoxon rank sum test: as tte depth gives an ordering to a corpus of text embeddings, we can use an existing rank sum test for determining whether the embeddings of two corpora differ significantly. existing applications of depth utilize the wilcoxon rank sum test generalized to multivariate data through the order induced by a depth function @xcite ; we follow these works in our definitions. suppose we have two corpora, and the sets of the embeddings in r k of texts within these corpora are given by f and g. we wish to determine whether it is unlikely that g comes from the same distribution as f . for a given text embedding @xmath6, we first define r(y, f ) as the fraction of the f population which is "less central" to f than the embedding y. that is, let x ∼ f be a random variable with uniform distribution over f and define this roughly measures how central a given text embedding @xmath7. for example, if r(y, f ) is low, then a large portion of the text embeddings in x are more central to f than y, indicating that y is an outlier with respect to f . next we use r(y, f ) to define the q parameter to gauge the overall "outlyingness" of the g text embeddings with respect to f . let x ∼ f and y ∼ g be independent random variables with uniform distributions over f and g, and define since r(y, f ) is the fraction of the f corpus which is "less central" to f than the value y, q(f, g) is the average of such fractions over all y's from the g corpus. this means that q allows us to characterize and quantify how two corpora differ in embedding space. when @xmath8, it means on average more than 50% of the f corpus is deeper than text embeddings y from g, indicating y is more outlying than x with respect to f , hence an inconsistency between f and g. we use the q parameter to test whether two sets of embedded texts f and g are likely to come from the same distribution. (liu and singh, 1993) propose a wilcoxon rank sum test for the hypotheses h o : @xmath9: @xmath10. let @xmath11, x 2 , ..., x m } and @xmath12, y 2 , ..., y n } be samples of text embeddings from f and g, respec- r(y i , f m ), where r(y i , f m ) is the proportion of x j 's having d δ (x j , f m ) ≤ d δ (y i , f m ). in other words, q(f m , g n ) is the average of the ranks of y i 's in the combined sample x ∪ y . if this sample estimate is low, we consider the likelihood that the samples x and y come from the same distribution of text embeddings to be low, and say that it is instead likely that f and g differ significantly. as empirically shown in @xcite ## methods to investigate the usefulness of tte depth as both a modeling and distributional inference tool, we perform several experiments. we first develop an intuition as to how many texts should be sampled from a population to ensure quality tte depth results, and use this intuition throughout our evaluation. next, we explore the use of tte depth as a ranking technique for in-context learning prompt selection across six classification tasks. finally, we use tte depth and the associated rank sum test to examine the distributional differences between five {human-written dataset, synthesized dataset} pairs. ## limitations and future work as defined in section 3, tte depth depends on text embedding models which produce embeddings with desired spatial relationships. this assumption holds for most popular text embedding models, including those used in this work. however, text vectorizations which do not claim this property, such as tf-idf, are not suitable for use in tte depth. additionally, tte depth at its core is a dimensionality reduction method that produces a single interpretable dimension along which texts can be measured. we note that no matter how the dimensionality of text embeddings is reduced, there will always be some amount of information loss. while the single dimension and intuitive center-outward ordering given by tte depth is useful for many tasks, it may not be appropriate as a one-size-fits-all approach to distributional inference and is meant to be used in conjunction with other statistical tools for a full picture of embedding space properties. future work may use tte depth for a variety of nlp modeling and inference tasks. modeling tasks may include the use of tte depth to select representative documents to facilitate hierarchical multi-document summarization @xcite . inference tasks could include the use of tte depth to investigate outlying documents in domain-specific corpora, such as research in anomaly detection in social media posts @xcite . ## conclusion in this work we have introduced tte depth, a novel approach to measure distributions of transformerbased text embeddings which endows corpora with intuitive notions of center and spread. tte depth gives a center-outward ordering of texts within a corpus based on the texts in embedding space. we have defined tte depth and an associated wilcoxon rank sum test for discovering significant differences between pairs of corpora. to demonstrate the use of tte depth in modeling, we have used tte depth as a ranking for the task of prompt selection, showing good performance across a variety of text classification tasks. additionally, we have shown the usefulness of tte depth for characterizing distributional properties of corpora by investigating the embedding distributions of source and synthetic datasets in several synthetic data augmentation pipelines. tte depth is a useful, novel tool for both modeling and distributional inference in modern transformer-based nlp pipelines.