Language exhibits inherent structures, a property that explains both language acquisition and language change. Given this characteristic, we expect language models to manifest their own internal structures as well. While interpretability research has investigated how models compute representations mechanistically through attention patterns and Sparse AutoEncoders, the organization of the resulting representations is overlooked. To address this gap, we introduce StructLens, a framework to analyze representations through a holistic structural view. StructLens constructs maximum spanning trees based on the semantic representations in residual streams, inspired by tree representation in dependency parsing, and provides summaries of token relationships in representation space. We analyze how contiguous tokens are also nearby in representation space and find that middle layers show the strongest local-span organization. Moreover, analysis of pre-training checkpoints reveals that smaller local units become detectable earlier in pre-training, and larger units later. Our findings demonstrate that StructLens provides insights into how models organize token representations across layers and training. Our code is available at https://github.com/naist-nlp/structlens.
Figures & tables
Figure 1: Overview of StructLens . StructLens extracts hidden states and then computes inter-token similarity. Finally, it constructs Maximum Spanning Trees using the adjacency similarity matrices.
Figure 2: Contiguous and non-contiguous 4-node subtrees.
Figure 3: Illustration of trees. Colored nodes form contiguous 4-node subtrees.
Figure 4: Visualization of the layer-wise evolution of the contiguous 4-node subtrees and tokens in them for the original input order and the shuffled one for Llama3.1 8B. The x-axis denotes layer depth, and the y-axis denotes the contiguous subtree ratio and the contiguous token ratio.
Figure 5: Visualization of the layer-wise evolution of the 3-, 4-, and 5-node contiguous subtrees and tokens in them across multiple checkpoints of OLMo2 7B for MMLU. In each plot, the x-axis denotes the layer index, and the y-axis denotes the contiguous subtree and token ratio.
Figure 6: Inter-layer similarity samples of Llama3.1 8B for each metric on MMLU. Bright color represents high similarity, while dark color represents low similarity.
Metric
Layers removed
ARC-Easy
MMLU
CMMLU
GSM8K
Multinews
VCSUM
Avg.
Llama3.1 8B Instruct
Dense
-
85.8
68.4
55.9
70.4
26.1
16.6
53.8
CosBase-BI
24 25 26 27
78.3
66.8
54.4
43.0
23.1
8.7
45.7
CKA-BI
24 25 26 31
75.3 †
66.9
54.2
5.8 †
18.2 †
1.9 †
37.0
CosStruct-BI
23 24 25 26
79.3
67.8 †
55.1 †
57.1 †
25.1 †
16.2 †
50.1
TreeEdit-BI
23 24 26 27
78.1
66.9
55.8 †
40.9 †
22.7
10.7 †
45.8
Table 1: Pruning results. Each value denotes the accuracy or the correctness of an answer in a task, with higher values indicating better performance. Values of each dataset result denoted by † are statistically significant ( p<0.05 ) compared to CosBase-BI.
Appendix figures & tables17 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 7: Average L2 distance between tokens.
Table 2: HuggingFace ID and Hyperparameters.
Figure 8: Contiguous subtree and token ratios for 3-, 4-, and 5-node subtrees of Llama3.1 8B.
Figure 9: Contiguous subtree and token ratios for 3-, 4-, and 5-node subtrees of Qwen2.5 7B.
Figure 10: 5-node contiguous subtree ratio at Layer 18 and MMLU performance across checkpoints.
Figure 11: Visualization of the layer-wise evolution of the contiguous subtrees and tokens in them of multiple checkpoints of OLMo2 7B for MMLU. The x-axis denotes the layer index, and the y-axis denotes the contiguous subtree and token ratio.
Figure 12: Inter-layer similarity samples of Qwen2.5 7B for each metric on MMLU. Bright color represents high similarity, while dark color represents low similarity.
Figure 13: Inter-layer similarity samples by Edge-Edit of Llama3.1 8B and Llama3.1 70B for MMLU and CMMLU. Bright color represents high similarity, while dark color represents low similarity.
Figure 14: Inter-layer similarity samples by Edge-Edit of Qwen2.5 7B and Qwen2.5 72B for MMLU and CMMLU. Bright color represents high similarity, while dark color represents low similarity.
Figure 15: Inter-layer similarity samples of OLMo2 7B for each checkpoint on MMLU. Bright color represents high similarity, while dark color represents low similarity.
Method
k
Llama3.1 8B
Qwen2.5 7B
MMLU
CMMLU
MMLU
CMMLU
ARI ↑
Cond. ↓
ARI ↑
Cond. ↓
ARI ↑
Cond. ↓
ARI ↑
Cond. ↓
CKA
2
.84±.171
.70±.046
.60±.256
.60±.075
.92±.098
.86±.019
.88±.175
.43±.027
3
1.0±.016
.64±.001
.67±.177
.61±.024
.92±.077
.81±.017
.53±.267
.50±.057
4
.97±.039
.74±.001
.65±.209
.70±.017
.99±.060
.87±.007
.62±.185
.57±.028
Cos-Base
2
1.0±.017
.48±.001
.97±.051
.47±.010
.83±.220
.64±.046
.82±.144
.53±.022
Appendix
Table 3: Adjusted Rand Index (ARI) and Conductance (Cond.) on Llama 3.1 8B and Qwen2.5 7B. Bold denotes the best performance within each method.
Table 4: Frequent subtree samples. The tree is represented as a strict S-expression. The number before “_” denotes the index of the token in the input. We replaced “(” and “)” in the input tokens with “[” and “]” to run subtree mining correctly.
Table 5: Frequent subtree patterns found in non-adjacent layers. This shows the top two patterns with the longest periods during which the structure was not used. The absence interval represents the maximum number of layers between when a structure observed at a layer disappears and when it reappears. For example, when a structure is observed in layers 3, 6, and 8, the absence interval is 3, corresponding to the number of layers from layer 3 to layer 6.
Figure 16: Logit lens visualization on MMLU. We visualize the token predictions for each of the last eight tokens in the input. The lower rows represent predictions from the lower layers, while the upper rows show predictions from the higher layers. Color intensity represents prediction probability.
Table 6: Sample of clustering results of Edge-Edit for an instance of MMLU ( k=3 ). Layer 0 indicates the input embeddings. Cond. denotes Conductance (see Appendix E ).
Figure 17: Visualization of layer importance. Lighter colors represent less importance, while darker colors represent greater importance.
Model
Metric
Layers removed
ARC-Easy
MMLU
CMMLU
Avg.
Llama-3.1-8B
Dense
-
84.6
65.3
52.9
67.6
CosBase-BI
24 25 26 27
76.8
62.0
49.0
62.6
CKA-BI
24 26 27 31
72.4 †
62.3
49.4
61.4
CosStruct-BI
23 24 25 26
77.8
64.5 †
51.2 †
64.5
TreeEdit-BI
23 24 26 27
76.8
64.6 †
51.9 †
64.4
EdgeEdit-BI
23 24 25 26
77.8
64.5 †
51.2 †
64.5
Appendix
Table 7: Pruning results of multiple-choice QA tasks. Each value denotes the accuracy or the correctness of an answer in a particular task, with higher values indicating better performance. Values denoted by † are statistically significant ( p<0.05 ) compared to CosBase-BI.
Large language model (LLM) interpretability studies how internal representations and computations produce outputs, and how they can be explained or controlled.