Model Flow · companion note · October 2026 · version 0.3

Choosing an embedding layer without labels

Language models are often used to turn texts into vectors for search or classification, and which layer's vectors to use matters. Our answer for most cases: take the second-to-last layer. That is a long-standing habit, not our discovery. What we add is a pre-registered test of a label-free rule built to do better, which on most models did not, and a map of when to choose differently.

How this was made. A human–AI collaboration: the author set the question and direction and reviewed each step; Claude (Anthropic), working in Claude Code, wrote the code, ran the experiments and drafted this note. It accompanies Model Flow.

Which layer to use

Each case below is backed by the tests further down. The stability pick is the label-free rule we tested: the layer whose k-means groups come out most alike when the grouping is repeated.

The question

Every layer of a language model holds a vector for each token. To turn a whole text into one vector, a common recipe takes one layer and averages its token vectors. Which layer to take is a real choice: middle and late layers often give better embeddings than the last one (Skean et al. 2025). Finding the best layer normally needs labelled examples of the task. The question here is whether a signal computed from unlabelled texts alone can find a layer that is nearly as good.

The rule we tested

The idea comes from the main post: some layers sort texts into clear groups, others do not. For each layer we take the averaged vectors of a sample of the collection and split them into 512 groups with k-means, a standard method that groups points by distance. k-means starts from random points, so we run it twice and measure how much the two groupings agree. We call that agreement the layer's repeatability. The stability pick is the layer where it is highest, averaged over ten pairs of runs. Before grouping, each layer's vectors are reduced to their 64 main directions, each rescaled to the same spread; the few coordinates with huge values are left in. No labels are used.

To score a choice we need labels, but only for checking. Topic search asks, for each text, how many of its 10 nearest neighbours share its label. A choice's shortfall is how many points of topic search it loses against the best layer of that model on that collection. Lower is better, and 0 means it found the best layer.

The first test, and the gap it left

A first pre-registered test, on 11 combinations of 7 models and two topic collections (DBpedia article summaries and 20 Newsgroups posts), went well: the pick fell well under a point short on average and beat the last layer in 10 of 11. But one comparison was only made afterwards: simply taking the second-to-last layer did almost as well, and there was no interval on the difference. Two other label-free rules from recent work, based on how many dimensions a layer's data effectively uses (its intrinsic dimension), had not been compared at all (Wang et al. 2026; Tang & Yang 2026).

The second test pre-registered · fresh models

So we registered a second test before extracting anything: three models never used to develop the rule (Llama-3.2-1B, SmolLM2-360M, Qwen3.5-4B-Base) on the same two topic collections, plus nine models on Yelp reviews, where the label is the star rating, not a topic. We fixed five predictions in advance.

Prediction (fixed in advance)OutcomeStatus
P1. On new models, the pick stays within about a point of the best layer and beats the last layerHeldpassed
P2. It beats the second-to-last layer by at least half a point, with an interval that excludes no differenceThe two are indistinguishablefailed
P3. It beats both intrinsic-dimension rulesHeld, under our adaptation of thempassed
P4. It does poorly on star ratings (we expected the rule to follow the collection, not the task)It did poorly, as predictedheld
P5. A trained probe on the picked layer is about as good as on the best layer (topic collections)Heldpassed

The figure shows one model, chosen in advance, layer by layer. Repeatability (top) rises with search quality (third panel) and peaks at the same layer, which here is also the second-to-last. The intrinsic-dimension rules land elsewhere: the first peak of intrinsic dimension falls in the middle, where search is worse.

2026-10-19T10:21:09.444724 image/svg+xml Matplotlib v3.10.3, https://matplotlib.org/ 0.82 0.84 0.86 0.88 repeatability of k-means groups (the stability score) stability pick = second-to-last first ID peak (FEPoID) ID minimum 15 20 25 intrinsic dimension (TwoNN) 75 80 85 topic search: neighbours sharing the topic (%) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 layer (Llama-3.2-1B, 16 layers; layer 0, the embeddings, left out) 88 90 92 94 linear probe accuracy (%)
Llama-3.2-1B on DBpedia, one panel per layer. Top to bottom: repeatability of the k-means groups, intrinsic dimension (TwoNN), topic search, and a linear probe trained with labels. Vertical lines: the layer each rule picks. Shaded: the best layer for topic search.

Our registration said what a failed P2 would mean, and we hold to it: for most models, take the second-to-last layer. It is free, and the stability pick did not beat it.

Where the pick earns its cost noticed after the test

Looking pair by pair, the second-to-last layer fails badly in only a few places, and they share one family: Gemma 4. In the main post, Gemma 4 is the family whose geometry turns sharply partway through, so its best layer for search can sit far from the end. There, the stability pick still finds it.

2026-10-19T10:21:10.312654 image/svg+xml Matplotlib v3.10.3, https://matplotlib.org/ 0 2 4 6 8 points below the best layer (topic search, or star rating for Yelp) Gemma 4 E2B · 20 Newsgroups Gemma 4 E4B · 20 Newsgroups Gemma 4 E4B · DBpedia Qwen3-1.7B · 20 Newsgroups Qwen3.5-0.8B · 20 Newsgroups Qwen3.5-0.8B · DBpedia Qwen3.5-2B · 20 Newsgroups Qwen3.5-4B · 20 Newsgroups Qwen3.5-4B · DBpedia SmolLM2-1.7B · 20 Newsgroups SmolLM2-1.7B · DBpedia Llama-3.2-1B · 20 Newsgroups Llama-3.2-1B · DBpedia Qwen3.5-4B-Base · 20 Newsgroups Qwen3.5-4B-Base · DBpedia SmolLM2-360M · 20 Newsgroups SmolLM2-360M · DBpedia Gemma 4 E2B · Yelp Llama-3.2-1B · Yelp Pythia-2.8B · Yelp Qwen3-1.7B · Yelp Qwen3.5-2B · Yelp Qwen3.5-4B · Yelp Qwen3.5-4B-Base · Yelp SmolLM2-1.7B · Yelp SmolLM2-360M · Yelp first test (held out) second test: topics second test: ratings stability pick second-to-last layer the pick is the second-to-last layer
Shortfall of the stability pick (blue) and of the second-to-last layer (grey) on every pair, in points below the best layer. Gemma 4 pairs in orange. An open circle means the pick is the second-to-last layer itself, so the two have the same shortfall. The second-to-last layer was not a registered comparison in the first test.

Read the orange rows: on three of the four Gemma pairs the second-to-last layer loses several points, and the pick loses far less. On the other models the two often pick the same layer, and otherwise trade small differences. We found this after seeing the results, it rests on two models of one family, and it is not a tested claim.

How far to trust these results

Where it fails

Every test above uses topic collections, where texts fall into clear subject groups. We also registered tests where that is not the job, and the pick did worse in each. When nearby texts should share something other than a topic, such as being of similar length or having many digits or capital letters, it falls several points short of the best layer. On restaurant reviews scored by star rating it falls about two points short on average, as we predicted, though it still beats the last layer on most models. On single sentences, both short customer-service questions sorted by intent and sentence pairs rated for similar meaning, it beat the last layer in only about half the models.

It is also less reliable when the model differs from the ones it was developed on. On encoders, models that read the whole text at once rather than left to right, it met its goal in only one of four tests. On chat-tuned versions of the models, and on compressed versions of one chat model that store their weights in fewer bits, it missed its goal by modest margins. And it is sensitive to the few coordinates with huge values that most language models carry: removing them moves its result noticeably on about half the collections.

All of these fit one reading. Repeatability follows the strongest structure in the collection, which is usually its topics. When the task asks for something else, or the model's layers are shaped differently, that structure stops pointing at the best layer.

Open questions and possible improvements

Why repeatability tracks search quality at all is unknown. Three explanations we registered failed: it is not just how well separated a layer's groups are, not how many dimensions the layer uses, and not how settled the layers are. What remains is a description: across the layers of a trained model, repeatability and search quality rise and fall together. The link is learned. In Pythia models before training it runs the other way, and after training it is positive in all eight runs we checked.

None of the ideas below has been tested. Each follows from a failure above.

Prior work

Taking the second-to-last layer is an old habit. bert-as-service pooled it by default, reasoning that the last layer is too close to the pre-training objective (Xiao 2018), and Stable Diffusion 2 conditions on the penultimate layer of its text encoder (Stability AI 2022). Intermediate layers often make better embeddings than the last (Skean et al. 2025). Label-free layer choice has been proposed with intrinsic dimension (Wang et al. 2026; Tang & Yang 2026; the TwoNN estimator is from Facco et al. 2017). Cluster stability is a classical tool for choosing a clustering (Ben-Hur et al. 2002; von Luxburg 2010). We did not find it used to choose a layer. So what is new here is not the default but the test of it: a registered comparison of a label-free rule against the second-to-last layer, and a map of where each one fails.

Pre-registrations: PREREG_layer_selection.md (first test) and PREREG_stability_v2.md (second test), in the repository's docs/preregistrations/. Every number behind this page is in the claims ledger with its source file.

References