LayerFlow: Layer-wise Exploration of LLM Embeddings using Uncertainty-aware Interlinked Projections

Rita Sevastjanova, Robin Gerling, Thilo Spinner, Mennatallah El-Assady

Introduction

Understanding the internal mechanisms of Large Language Models (LLMs) like BERT remains a significant challenge in computational linguistics. Researchers often rely on visualizing high-dimensional "embeddings"—vector representations of words—to interpret how models process language. However, projecting these 768-dimensional vectors into a 2D space for human inspection is inherently lossy, often introducing distortions that can lead to erroneous conclusions.

Addressing Visualization Uncertainty

LayerFlow is a visual analytics workspace designed to mitigate the risks of misinterpreting projected embeddings. The system categorizes the challenges into three primary types of uncertainty that can obscure the true behavior of a model:

  1. Transformation Uncertainty: Distortions introduced during the dimensionality reduction process (e.g., PCA or UMAP).
  2. Representation Uncertainty: The degree to which the visual layout accurately reflects the underlying high-dimensional data structure.
  3. Interpretation Uncertainty: The difficulty in assigning semantic or syntactic meaning to observed clusters.
Conceptual pipeline of LLM embedding exploration, highlighting the three stages of uncertainty: transformation, representation, and interpretation.

The LayerFlow System

The core innovation of LayerFlow is its interlinked projection design, which moves beyond static scatterplots to track embedding evolution across model layers.

Interlinked Sankey-style Flows

LayerFlow connects data points across consecutive layers using a Sankey diagram layout. This allows researchers to trace how a specific word's contextual meaning shifts as it moves deeper into the model. To improve clarity, the system utilizes a "stretched" layout that vertically separates clusters, preventing the visual overlap common in traditional edge-bundling techniques.

Uncertainty-Aware Visual Components

To help users distinguish between genuine linguistic patterns and projection artifacts, LayerFlow integrates several diagnostic overlays:

  • Distance Matrices: Side-by-side comparisons of high-dimensional (HD) and 2D distances allow users to verify if visual clusters in the plot correspond to actual proximity in the original space.
  • Projection Quality Metrics: The tool employs Minimum Spanning Trees (MST) to calculate False Positive and False Negative rates, highlighting "false neighborhoods" where points appear close in 2D but are distant in HD.
  • k-Nearest Neighbor (k-NN) Links: True HD neighbors are linked directly on the 2D projection, providing immediate visual feedback on local neighborhood preservation.
The LayerFlow interface integrating interlinked projections, distance matrices, k-NN links, and quality metrics to expose visualization uncertainties.

Evaluation and Key Insights

The system was evaluated using the Groningen Meaning Bank dataset and the BERT-base model, focusing on polysemous words like "strike," "cell," and "post."

Validating Linguistic Patterns

LayerFlow visually confirmed the "middle layer" hypothesis in BERTology, showing that layers 4 through 8 are most effective at capturing syntactic structures, such as the distinction between attributive and predicative adjectives.

Exposing Projection Artifacts

Expert case studies revealed that seemingly "clean" clusters in UMAP projections were sometimes artifacts of the algorithm. By utilizing the False Positive Rate (FPR) metric and k-NN links, linguists were able to identify and discount these false groupings, leading to more robust interpretations of the model's behavior. Experts noted that the combination of flow-based tracking and distance matrices provided a much higher level of confidence in their analysis compared to standard scatterplots.

Conclusion and Future Work

LayerFlow demonstrates that uncertainty-aware visualization is crucial for the reliable analysis of LLM embeddings. While currently optimized for subsets of approximately 150 tokens per layer, future work aims to improve scalability to handle larger datasets without visual clutter. Additionally, automating the selection of uncertainty metrics based on detected projection errors could further lower the barrier for non-expert users.

Summary updated

BibTeX
@article{sevastjanova2025layerflow,
  author = {Rita Sevastjanova and Robin Gerling and Thilo Spinner and Mennatallah El-Assady},
  title = {{LayerFlow: Layer-wise Exploration of LLM Embeddings using Uncertainty-aware Interlinked Projections}},
  journal = {Computer Graphics Forum},
  year = {2025},
  doi = {10.1111/cgf.70123},
}
Figure