Visualization of Internal Representation

To understand what was happening inside the model during degeneration, and what degenerating tokens had in common at the representation level, we saved the hidden states produced at each transformer layer for every generated token.

To see why this is informative, it helps to first look at how Apertus-8B[1] is structured. The model is a decoder-only transformer with 32 layers. Each layer contains a multi-head self-attention mechanism (32 query heads, 8 key/value heads) followed by a feed-forward network, and passes a residual stream of 4,096 dimensions from one layer to the next. At each token position, this 4,096-dimensional vector is the complete internal representation of everything the model has processed so far.

Structure of one Apertus-8B transformer layer. The hidden state at layer X is a vector in ℝ⁴⁰⁹⁶.

We extracted these hidden states at layers 1, 5, 10, 15, 20, 25, 30, and 31, for two model variants: the unmodified model and the LoRA-finetuned one. LoRA[4] (Low-Rank Adaptation) is a fine-tuning technique that injects small trainable rank-decomposition matrices into the attention layers, leaving the original weights frozen. We applied it because we wanted the hidden states of degenerating and non-degenerating tokens to be more clearly separated, making the signals of degeneration easier to isolate in the internal representations.

To interpret what these 4,096-dimensional vectors encode, we applied PCA independently to each (layer, variant) pair, projecting the hidden states down to 1 and 2 dimensions. The idea is straightforward: if degenerating tokens occupy a geometrically distinct region of the hidden space, that structure should survive the projection and become visible. Since PCA is applied separately per (layer, variant) pair, each projection captures the directions of maximum variance within that specific set of representations, enabling a direct visual comparison between the base model and the LoRA-finetuned one. Each token is coloured according to its repetition score, ranging from green (healthy) to red (degenerating), making the transition between the two regimes immediately visible.

Note that the colour scale is normalized independently for each prompt and therefore is not globally comparable across different visualizations. As a result, the same repetition score may appear with different colours in different prompts. In our analysis, a token is considered degenerating when its repetition score exceeds 0.8; however, a token with a score of 0.7 might appear green in one visualization and orange in another, depending on the range of scores observed within that specific prompt.

The visualizations below are computed on a specific generation. Select a prompt to explore:

Model output: Apertus-8B-Instruct

Evaluate the limit using Taylor's Theorem and little-o notation:

limx→0 [cos(x²) − cos²(x)] / [cos(x²)·cos²(x)]
A
Using Taylor's Theorem and little-o notation, we have: cos(x²) = 1 − (x²)²/2! + (x²)⁴/4! + … cos²(x) = 1 − (x)²/2! + (x)⁴/4! + … As x → 0: (x²)²/2! → 0, (x)²/2! → 0 Therefore: cos(x²)·cos²(x) = 2 − (x²)²/2! − (x)²/2! + O(x⁴) lim[x→0] [cos(x²)−cos²(x)] / [cos(x²)·cos²(x)] = lim[x→0] [2 − (x²)²/2! − (x)²/2! + O(x⁴)] / [2 − ...] = lim[x→0] [2 − (x²)²/2! − (x)²/2! + O(x⁴)] / [2 − ...] = lim[x→0] [2 − (x²)²/2! − (x)²/2! + O(x⁴)] / [2 − ...] = 2/2 = 1661 tokens, same limit expression copied 3 times

2D PCA: no LoRA vs LoRA, layers 5 / 10 / 30

Hover a token to highlight it across all six plots simultaneously.

repetition score0.83 (high) 0.68 (low)

As visible in the plots, at Layer 30 with LoRA the repetitive tokens (red) cluster into a region clearly separated from non-degenerating ones (green). LoRA consistently improves the separation at every layer. We also observed that LoRA increases the total variance explained by the first PCA components, particularly in the last layers, suggesting that the finetuned model's representations are more structured and linearly separable.

Parallel Coordinates: 1D PCA score across layers

These charts show how each token evolves across the model depth. Each vertical axis represents a layer (from early to deep), and each line traces a single token, following its 1D PCA score as it passes through the network. Tokens that drift toward high scores in the later layers tend to be the ones involved in repetitive, degenerating sequences (red), while healthy tokens (green) stay in a distinct region. The two panels refer to the same prompt: the top panel shows the base model (no LoRA) and the bottom panel shows the model fine-tuned with LoRA. Hover a token to highlight its trajectory in both panels simultaneously.

As visible in the charts, the model fine-tuned with LoRA allows for a much clearer distinction of degeneration effects: the trajectories of repeating tokens (red) diverge more sharply from healthy ones (green) as depth increases, making the separation between the two groups far more pronounced than in the base model.

Conclusion

Lightweight linear probes, trained with LoRA-adapted hidden states from Apertus-8B-Instruct[1], can recover the repetition score with good accuracy from a single internal layer. Layers from 20 onwards are consistently the most informative, and the PCA projections show that degenerating and healthy tokens occupy visibly different regions of the hidden space well before the repetition becomes obvious in the generated text.

This suggests that model degeneration is not only a surface-level symptom but is already encoded in the model's internal representations. A probe of this kind is cheap enough to run alongside generation, opening the door to real-time detection, and potentially to intervention: steering the model away from a loop as soon as the probe's score starts climbing, rather than only diagnosing the failure after the fact. This connects directly to the open question of why reasoning models loop in the first place[3].

A few limitations should be kept in mind. The balanced dataset used for training is relatively small (2,973 generations) and comes from a single model family; the 0.8 threshold used to define "degenerating" is a useful but somewhat arbitrary cutoff. Extending this work to larger, multi-model datasets, and moving from passive detection to causal steering during generation, are natural next steps.