Beautiful on the Inside
How to create beautiful internal representations (and grok 6× faster) by pulling each activation towards its nearest neighbours.
Introduction
Intuitively, there is a difference between a student who passes a test by learning the mark scheme and a student who passes a test with a deeper understanding of the subject. Training networks on a single objective can certainly achieve the former. However, as we seek generalisation and adaptability in our networks, what we would like to achieve is the latter. The problem arises if both students pass the test equally well. To tell them apart, we have to look inside: better representations reuse the same building blocks to solve the same problems, so a symmetric problem should not need different building blocks for each half.
Previously, Kumar et al. showed that open-ended search can find beautiful (symmetric) representations in toy settings. However, until recently it was not clear whether SGD-based optimisation could also achieve this style of internal organisation.
This latest paper by Sheppard et al. shows that an auxiliary loss provided by a compressing network can help achieve them. They train a separate network, a unified factored organizer (UFO), to model regularities in another network’s representations.
The compressing network’s role is to put pressure on the main network’s activations to become more compressible. In effect, it rewards the main network for reusing the same activation patterns rather than spurious ones, which would be shortcut learning and not generalisation.
This raises two questions:
- Can we reward this reuse directly, without a UFO?
- If so, which activations should share a pattern?
Theory
Naively, we could say that similar inputs should share a pattern, but distance in input space can be very misleading. Instead, we use layer-by-layer activations as a guide. Activations that are already close to one another should be brought closer.
But how close is close enough? Aligning everything would be intuitively destructive to useful information, not just shortcuts. So we only align each activation with its k nearest neighbours. A large k smooths activations over a broad neighbourhood, while a small k only aligns activations that are already near-identical.
Near the input, activations have not yet had the chance to separate, so closeness means less: hence k should start large and shrink with layer depth. Early on, we only smooth over a broad neighbourhood, and as activations separate and closeness becomes more meaningful, we let them cluster.
Method
CPPN
A CPPN (compositional pattern-producing network, used here as a neural field) is a network that takes coordinates as input and outputs, in this case, a pixel’s colour. These networks have the useful property of being able to show their output over the entire input domain as an image, which makes them ideal for this kind of analysis.
For every neuron, we can draw its activation over the entire input space as an image and hence see whether its activations have symmetry or are otherwise intuitive, or whether they appear spuriously entangled.
Following the convention in Sheppard et al.’s UFO paper, I use CPPNs for the experiments pertaining to images.
ANNA objective
Activation Nearest-Neighbour Alignment (ANNA) works like this: at each layer, we batch-normalise the activations, scale each one to unit length, and pull it towards its k nearest neighbours.
If we pull activations together from the start, the patterns we are asking the network to preserve come from a random initialisation. If we wait too late, the patterns may already be too pathological. My intuition was that early in training we might find activations that are relevant to the task, but not yet short-cutting.
For this reason, on the images, I let the network train on the task loss alone for the first 1,000 steps, then increased the weight on the ANNA loss linearly over the next 1,000.
Following the intuition above, k shrinks geometrically with depth, from 128 neighbours at the first layer to five at the last.
Experiments
I compare ANNA with the paper’s UFOAs in the paper: an autoencoder with a hidden layer of 64 and a bottleneck of 4, a learning rate of 1e-3, a strength of 0.3, and selectivity falling from 1 to 0.1 over 20,000 steps. For the images, the UFO is on from the first step rather than warming up. Like every method here, it also sees 4,096 pixels per step, starts from weights scaled by 0.5 and uses a straight-through output clamp. In a blind comparison of paintings, these changes scored above the paper’s settings. Grokking uses the paper’s code and settings unchanged., and with a network trained on the task alone, in two settings.
Images. Each method trains a CPPN16 layers of 23 units: 17 identity, 4 Gaussian, 1 sigmoid and 1 sine. The inputs are x, y, distance from the centre and a bias, and the output is a colour in HSV. Initial weights are scaled by 0.5, and the output passes through a straight-through clamp. Trained with Adam at a learning rate of 3e-3, on 4,096 pixels per step for 50,000 steps. to paint one of three images: a butterfly, a skull and a cat. For each image, I run 16 seeds, matched so that all three methods start from the same weights. ANNA uses the same setting on every image: a strength of 0.3, with k shrinking from 128 to 5.
I measure two things:
- Symmetry: how closely each unit’s activation map matches its left–right mirror image (a proxy for beauty).
- MSE: how well the main network completes its task.
Grokking. Following the UFO paper, a two-layer transformer learns modular division, x / y mod 97, from half of all input pairs and is tested on the other half. ANNA and the UFO act on either the attention weights at the “=” token, or the MLP units there. I run eight seeds per setting, all with weight decay. With only two layers in the model, I used k schedules from 384 to 5 on attention and from 511 (whole batch) to 32 on the MLP.
Results
Cat training
Out of curiosity, I wanted to see how the internalsEach row shows six units from one quarter of the network’s depth, picked to be representative. The same units appear on both sides. change during training, with and without ANNA. Unlike the other experiments, I also lowered ANNA’s strength in two steps along the way, to get a better trade-off between MSE and symmetry.
Symmetry and MSE
Across the three images, I compared ANNA with the paper’s UFO and an unregularised network. ANNA matches the UFO’s symmetry on the butterfly and the cat, and is clearly ahead on the skull, at a similar or lower MSE. Without a regulariser, the network often paints a more accurate image, but its maps are far less symmetric.
Map symmetry ↑
Pixel MSE ↓
Grokking
In the UFO paper, they also show that the regularisation pressure accelerates grokking. To see whether ANNA has a comparable effect, I replicated the experiments with the paper’s code. On attention, ANNA groks about as fast as the UFO. On the MLP it is somewhat slower. Both are several times faster than weight decay alone.
Conclusion
ANNA is a simple way to encourage a network to structurise its activations. It only asks that activations which are already close become closer, and lets the network’s own activations decide which those are. Without training an auxiliary network, it matched the UFO’s symmetry on images and its speed of grokking on attention, although it was slower on the MLP.
Going back to the two students, both cat networks pass the test, but only by looking inside can we see that one of them has found a more structured solution. Notably, this structure does come at some cost to MSE. Whether it reflects deeper understanding, i.e. better generalisation beyond these toy settings, is still an open question, though the grokking results are an encouraging first sign.
Open questions:
- The relationship between k and batch size.
- A cooldown schedule for λ, which seemed to help on the showcase cat.
- Generality and scalability, with encouraging early signs.

