Skip to content

About

Reproducibility surface for the Accepted ICML 2026 Mechanistic Interpretability Workshop Paper: Metric Choice Determines Semantic Geometry in LLM Hidden States

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Metric Choice Determines Semantic Geometry in LLM Hidden States

Accepted at the Mechanistic Interpretability Workshop at ICML 2026 (Seoul, South Korea).

This repository is the code, prompt-suite, and results package for the accepted workshop paper:

Metric Choice Determines Semantic Geometry in LLM Hidden States: A Measurement Study of Hidden-State Geometry

It does not include manuscript source or camera-ready assets; see REPRODUCIBILITY_PACKAGE.md for what is and is not packaged.

Paper at a Glance

The paper tests three falsifiable hypotheses about layerwise hidden-state geometry in GPT-2, Phi-4-mini, Mistral-7B, and Gemma-3-12B:

  1. Expansion. Raw norms and raw pairwise L2 distances grow with depth across prompt families.
  2. Not semantic. The same growth appears for incoherent and unrelated controls, so raw expansion is not evidence of semantic separation. In the 32-vs-32 MIND diagnostic, the median raw-norm growth from the embedding layer to the final layer across the four checkpoints is 31.5x for meaningful news prompts and 33.3x for length-matched unigram-random controls from the same word pool (out/pass_2026-05-05/mind_meaningful_vs_unigram_random_all_models/).
  3. Recoverable. Sentence-, topic-, and category-level structure appears under shared-centroid (contrast-centered) cosine distance, which is the paper's primary semantic metric. The full four-checkpoint pass is in out/pass_2026-05-08/contrast_centered_cosine_full_4model/.

The takeaway is that the choice of metric, not the raw distance growth, determines whether hidden-state geometry reads as semantic structure. Raw norm and raw L2 are treated as expansion diagnostics only.

Overview

This repo studies what layerwise distances and separations in transformer hidden states mean for controlled prompt suites. The current research question is not whether distance directly measures "meaning"; it is when a particular representation and distance metric support a falsifiable semantic or topic-structure interpretation.

The latest completed result surface is the April 29, 2026 AG News random-cloud run. It replaces the earlier MIND 43-word random word-bag baseline as the current external-suite result. The active claim is:

Mean-pooled centered-cosine geometry tracks dataset-level semantic and topic structure across controlled prompt families, while last-token geometry is a useful but weaker decoder-final-position baseline.

Current External Dataset Suite

The current clean external prompt artifact is:

  • prompt_suites/external_prompt_suite_stsb_agnews_words_512.jsonl

It is generated by:

./.venv/bin/python scripts/build_stsb_agnews_prompt_corpus.py --seed 0

It contains 512 unique prompt texts across nine families:

  • stsb_high_similarity: 64 prompts from 32 high-score STS-B designed sentence pairs
  • stsb_low_similarity: 64 prompts from 32 low-score STS-B designed sentence pairs
  • ag_news_same_topic: 64 prompts from 32 same-label AG News designed article pairs
  • ag_news_cross_topic: 64 prompts from 32 different-label AG News designed article pairs
  • ag_news_random_64_stratified: 64 real AG News articles, stratified as 16 prompts per AG News label; analysis uses all 2016 unordered pairs and splits them into 480 within-label pairs and 1536 between-label pairs
  • mind_news_same_category: 64 prompts from 32 same-subcategory MIND designed title/abstract pairs
  • mind_news_random_64_category: 64 title/abstract prompts from 64 distinct MIND news subcategories; analysis uses all 2016 exact category-disjoint unordered article pairs
  • word_random: 32 single-word prompts drawn from low-score SimLex-999 pairs; analysis uses all 496 exact category-disjoint unordered word pairs
  • word_correlated: 32 prompts from 16 high-score SimLex-999 designed word pairs

The AG News random cloud is now the dataset-native AG News background distribution. It should be used for the internal AG News within/all/between diagnostic instead of the superseded synthetic MIND word-bag baseline.

Representation Policy

The primary interpretive surface is mean_pool: the average of all non-padding token hidden states at each layer. This gives one vector per prompt while using the whole prompt.

The last_token surface remains required as a baseline because it matches the decoder-LM final-position representation used by the earlier reproduction surface. It should be interpreted as decoder-final-position geometry, not automatically as whole-prompt semantic geometry.

Interpretation rules:

  • effects stable across mean_pool and last_token are stronger evidence for prompt-level geometry
  • effects found only under last_token are decoder-final-position effects
  • effects found only under mean_pool are distributed prompt-level effects
  • low-dimensional PCA shape alone is not semantic evidence without supporting distance statistics and extraction-mode comparison

Latest Output Roots

The completed April 29 full 512-prompt AG News random-cloud distance passes are:

out/pass_2026-04-29/external_agnews_random64_full_model_distance_mean_pool/
out/pass_2026-04-29/external_agnews_random64_full_model_distance_last_token/

The batch runner wrote these status files:

out/pass_2026-04-29/external_agnews_random64_full_model_distance_mean_pool/distance_extraction_status_2026-04-29-external-agnews-random64-mean-pool.json
out/pass_2026-04-29/external_agnews_random64_full_model_distance_last_token/distance_extraction_status_2026-04-29-external-agnews-random64-last-token.json

Both status files report ok for the four retained model slugs:

  • gpt2
  • phi4mini
  • mistral7b
  • gemma3_12b

Required per-model files:

  • README_results.txt
  • layerwise_family_distance_summary.csv
  • layerwise_pair_distances_long.csv
  • layerwise_family_extrema.csv
  • pair_manifest.csv
  • plots/<pair_group>_<metric>_four_stats.png

layerwise_pair_distances_long.csv is written by every run but is omitted from this repository because of its size (it is reproducible from the prompt suite and scripts/run_distance_extraction_pass.py). Compact CSVs derived from it are under results/derived/.

The active metrics are:

  • raw_l2
  • raw_cosine
  • centered_l2
  • centered_cosine

Every summary row records pair_scope and extraction_mode. Designed families use their metadata-defined pairs. Random-control pools marked with pair_summary_policy: exact_constrained_all_pairs use exact all-pair summaries for mean, median, min, and max.

Latest Results Summary

The newest centered-cosine policy is contrast_center: for each controlled comparison, both compared prompt groups share a centroid before cosine distance is computed. The full four-checkpoint pass is stored at:

out/pass_2026-05-08/contrast_centered_cosine_full_4model/

Average final-layer contrast-centered gaps (mean_pool) across GPT-2, Phi-4-mini, Mistral-7B, and Gemma-3-12B (results/derived/contrast_centered_cosine_final_layer_gaps_full_4model.csv):

contrast average control-minus-related gap
STS-B low minus high similarity 0.2730
AG News cross minus same topic 0.1818
MIND random minus same category 0.2254
SimLex random minus correlated words 0.1127

The regenerated paper figures are under paper_scripts/figures/, including paper_scripts/figures/main_fig2_centered_cosine_results.png and paper_scripts/figures/appendix/appendix_centered_cosine_comparisons.png.

The strongest current AG News result is internal to ag_news_random_64_stratified. At the final layer, averaged across the four retained model representatives:

extraction mode all 2016 pairs within-label 480 pairs between-label 1536 pairs between minus within
mean_pool 1.0155 0.8430 1.0694 0.2264
last_token 1.0017 0.8719 1.0422 0.1703

This is the cleanest current random-cloud comparison because all three values come from the same AG News pair surface and the same family-centering surface. Mean-pool gives the larger within-vs-between gap.

Other current findings:

  • STS-B high-similarity pairs are closer than STS-B low-similarity pairs in 4/4 retained models.
  • AG News same-topic designed pairs are closer than AG News cross-topic designed pairs in 4/4 retained models.
  • MIND same-subcategory articles are closer than random cross-subcategory MIND articles in 4/4 retained models.

Inspect Artifacts

Paper figures and the inspection graph pack:

  • paper_scripts/figures/main_fig1_broad_expansion.png
  • paper_scripts/figures/main_fig2_centered_cosine_results.png
  • paper_scripts/figures/appendix/appendix_centered_cosine_comparisons.png
  • graphs/inspect_graphs/README.md
  • graphs/inspect_graphs/manifest.json

Manuscript source, progress notes, and the earlier inspect*.md interpretation notes are intentionally not part of this package; see REPRODUCIBILITY_PACKAGE.md.

Graph pack layout:

  • graphs/inspect_graphs/mean-pool/<model>/...
  • graphs/inspect_graphs/last-token/<model>/...
  • graphs/inspect_graphs/pca_layers/

Key graph files (one set per model folder):

  • ag_main_groups_random64.png
  • ag_random64_within_between.png
  • stsb_high_vs_low.png
  • ag_same_vs_cross.png
  • mind_same_vs_random_article.png
  • word_correlated_vs_random.png

Repo Layout

  • distance_extraction/: reusable extraction, pair construction, metrics, and output-writing package
  • scripts/: active command-line entry points for prompt building, model runs, inspect graph generation, and PCA visualization
  • prompt_suites/: generated JSONL prompt suites kept as reviewable inputs
  • docs/: workflow contracts, rules, and prompt-family design notes
  • out/: retained compact generated outputs (summaries, manifests, plots)
  • results/derived/: compact CSVs derived from the omitted raw pairwise CSVs, used to audit the paper tables and figures
  • graphs/inspect_graphs/: generated inspection graph pack
  • paper_scripts/: figure-generation scripts and the generated paper figures under paper_scripts/figures/
  • tests/: regression tests for extraction modes and pair policies
  • PACKAGE_MANIFEST.json, REPRODUCIBILITY_PACKAGE.md: package file list and notes on what is included and excluded

Current Target Models

The active batch runner now targets the useful general-purpose model set for expansion-rate experiments:

  • openai-community/gpt2
  • microsoft/Phi-4-mini-instruct
  • mistralai/Mistral-7B-v0.1
  • google/gemma-3-12b-pt

Run Surface

Bootstrap:

./init.sh

Authenticated Hugging Face run surface:

export HF_HOME="$HOME/.cache/huggingface"
export XDG_CACHE_HOME="$HOME/.cache"
export MPLCONFIGDIR=/tmp/iw-cache/mpl

Regenerate the current external prompt suite:

./.venv/bin/python scripts/build_stsb_agnews_prompt_corpus.py --seed 0

Run a current full distance pass:

./.venv/bin/python scripts/run_distance_extraction_pass.py \
  --prompts prompt_suites/external_prompt_suite_stsb_agnews_words_512.jsonl \
  --out_root out/pass_2026-04-29/external_agnews_random64_full_model_distance_mean_pool \
  --date_tag 2026-04-29-external-agnews-random64-mean-pool \
  --run_label distance_512 \
  --device cuda \
  --max_length 256 \
  --extraction_mode mean_pool \
  --distance_block 256 \
  --metrics raw_l2 raw_cosine centered_l2 centered_cosine

Run the same command with --out_root out/pass_2026-04-29/external_agnews_random64_full_model_distance_last_token, --date_tag 2026-04-29-external-agnews-random64-last-token, and --extraction_mode last_token for the decoder-final-position baseline.

Derive expansion rates from existing distance outputs (this reads layerwise_pair_distances_long.csv, which is not shipped in this repository, so run the two distance passes above first):

./.venv/bin/python scripts/extract_expansion_rates.py \
  --distance_roots out/pass_2026-04-29/external_agnews_random64_full_model_distance_mean_pool \
                   out/pass_2026-04-29/external_agnews_random64_full_model_distance_last_token \
  --metrics centered_cosine \
  --min_previous_distance 1e-4 \
  --out_dir out/pass_2026-05-04/expansion_rates_agnews_random64

For attention-vs-MLP component diagnostics, rerun extraction with component hooks:

./.venv/bin/python scripts/run_distance_extraction_pass.py \
  --prompts prompt_suites/external_prompt_suite_stsb_agnews_words_512.jsonl \
  --out_root out/pass_2026-05-04/external_agnews_random64_component_distance_mean_pool \
  --date_tag 2026-05-04-external-agnews-random64-components-mean-pool \
  --run_label distance_512_components \
  --device cuda \
  --max_length 256 \
  --extraction_mode mean_pool \
  --capture_block_components \
  --metrics centered_cosine

Cheap smoke run:

./.venv/bin/python scripts/run_distance_extraction_pass.py \
  --models gpt2 \
  --prompts prompt_suites/external_prompt_suite_stsb_agnews_words_512.jsonl \
  --out_root out/smoke_distance_extraction \
  --date_tag smoke \
  --device cpu \
  --max_prompts 8 \
  --extraction_mode mean_pool \
  --metrics raw_l2 raw_cosine centered_l2 centered_cosine

About

Reproducibility surface for the Accepted ICML 2026 Mechanistic Interpretability Workshop Paper: Metric Choice Determines Semantic Geometry in LLM Hidden States

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages