We introduce P.STAR: a new parameter-free method that can be used to inspect the embedding space of a set of instance representations (e.g. words in context) across layers of a contextualized language model at one glance and without loss of information. We use a matrix reordering approach that relies on signature distances; instances are represented in terms of their distances to all other instances in the set. The reordered matrix of signature representations provides a visual depiction of how structures emerge across layers of a contextualized model. We validate our approach by comparing how words in context are grouped to their PoS and Sense labels in two annotated datasets. In line with previous research, we observe that lower-layer representations emphasize PoS-information while higher layers group instances on the basis of senses. We also show that our reordering approach can identify errors in the labels.
Within the field of model analysis and interpretability, several methods for analyzing internal model representations have been proposed [4]. The earliest and still widely used approaches use probing. This paradigm relies on testing whether the prediction of a specific linguistic property can be learned from embedding representations using labeled data and a simple (often linear) classifier. Probing results have been shown to vary substantially depending on the choice of classifier; the brittle nature of probing results has raised questions about the reliability of this approach [3, 13].
Clustering approaches can be seen as more direct ways of representing structure and have been used to analyze and visualize hidden layer representations (see, for example, [1, 6]). While clustering approaches do not require a classifier, they still depend on crucial parameters (e.g. the number of clusters). Zhou and Srikumar [31] propose hierarchical clustering as a parameter-free alternative, however, their approach crucially relies on labeled data to form clusters.
Previous work on visualizing embedding spaces includes methods using dimensionality reduction [5, 14, 23, 24, 25], which lose information when projecting to lower dimensions. Matrix reordering techniques [29] have shown that optimal linear orders can reveal meaningful structure in distance matrices, supporting our approach.
While cosine distances are commonly used for comparing embeddings, they can be noisy and unreliable [27, 30]. Signature distances, previously used in semantic change detection [11, 20, 21], provide a more robust alternative. Unlike previous work that uses static word embeddings, we apply signature distances to instance representations from contextualized models, creating second-order embeddings that capture contextual relationships within each layer.
P.STAR orders embedding instances so that similar points are grouped together, revealing clusters and structures. We frame this as an optimization problem: find an ordering that minimizes the distances between consecutive points. This is equivalent to solving an Open Traveling Salesperson Problem (OTSP), which we solve efficiently using the Concorde solver via the NEOS server [2, 8, 10, 12].
Instead of using standard cosine distances directly, we employ signature distances for more robust comparisons. For each instance, we compute its signature—a vector representing its distances to all other instances in the dataset. This signature captures the contextual relationships more reliably than direct cosine distances, which can be noisy [27]. The signature distance between two instances is then computed as the normalized Euclidean distance between their signatures.
By computing signature distances for all pairs of instances and solving the OTSP problem, we obtain an optimal linear ordering. This ordering is then visualized as a matrix where colors represent distances, revealing clusters and structures at different scales without requiring any parameters or dimension reduction.
We validate P.STAR using BERT-base-uncased [9] and GPT2 [18] models, analyzing embeddings from all 12 layers. We use two annotated datasets: SemCor3.0 [17] (manually annotated with WordNet senses) and OMSTI [26] (automatically annotated, containing one million sense-tagged instances). Both datasets include part-of-speech (PoS) tags.
We demonstrate P.STAR's effectiveness through three case studies. For the word "state", P.STAR clearly separates verbal and nominal uses in lower layers (Layer 7), while distinct senses emerge in higher layers. For "work", we observe a more complex pattern where syntactic boundaries (noun vs. verb) dominate in lower layers, while semantic relationships (related senses) become more prominent in higher layers.
Importantly, P.STAR also reveals annotation errors. When analyzing "cell", we identified mislabeled instances in the OMSTI dataset, including cases where "cell" referred to terrorist groups but was incorrectly labeled as biological cells. These errors were detectable because the instances were placed among semantically related prison cell references.
Our results confirm that lower layers emphasize syntactic (PoS) information while higher layers group instances by semantic similarity (senses), consistent with previous research [15, 28].
Our method relies on the visual inspection of matrices; as such, our validation consists of a comparatively small set of examples that serve as a first illustration. The clarity of the observations does, however, provide convincing evidence for the reliability of our method. This first step opens up new directions for exploration. One of the reasons why the approach provides such clear structures is that we make use of signature distances. The second-order distance approach is more robust than cosine distances between embeddings.
The major advantage of our method is that it can represent an entire set of instances at one glance without reducing dimensions, or setting parameters that might influence results. As such, it can provide a more direct depiction of structures than could be achieved through clustering approaches. As demonstrated in our validation, our method shows how clusters and nested clusters arise from the linear reordering of second-order signature representations.
From a linguistic analysis point of view, we believe that P.STAR could offer a powerful new method for the analysis of linguistic properties in contextualized language models and could yield new theoretical insights. From a practical perspective, P.STAR can be used to detect layers in contextualized models that are likely to carry useful information for a particular task or for further model fine-tuning. Our analysis shows that layers that capture word senses particularly well can be identified. Word sense information is of central importance for the task of Lexical Semantic Change Detection. Both the use of signature distances and better pinpointing where sense is represented most can help boost the performance of contextualized models for a task where static word embeddings often still outperform them [16, 22].
In the future, we will build on our P.STAR method to develop interactive visual analytics tools, enabling the exploration of patterns across model layers, for example, to investigate the progression of the learned semantic separability across the layers.
We introduce P.STAR: a parameter-free method that reveals the structure of a contextual embedding at a glance, with no loss of information. Our approach uses a matrix reordering technique based on signature distances, which provides a more robust and stable representation compared to direct cosine distances. We validate our method through an analysis of the emergence of part-of-speech (PoS) information and word senses in contextualized models, demonstrating that lower-layer representations emphasize PoS-information while higher layers group instances on the basis of senses. We also show that our reordering approach can identify errors in annotated data, providing a valuable tool for data quality assessment.
The major advantage of P.STAR is its ability to represent an entire set of instances at one glance without reducing dimensions or requiring parameter selection. This makes it particularly suitable for analyzing linguistic properties in contextualized language models and identifying layers that carry useful information for specific tasks. Our work opens up new directions for exploration and provides a foundation for future interactive visual analytics tools that can enable deeper investigation of patterns across model layers.