Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Language models / Tokens and embeddings

Per-layer embeddings (PLE): could each layer look up the token again?

Could each layer look up static information about a token, leaving more feed-forward capacity for other concepts?

The feed-forward network learns transformations of each token’s current representation. Some learned information is static: it concerns the token itself, wherever it appears. Other work depends on the surrounding context.

If we gave static token information a direct route into each layer, more feed-forward capacity could go towards other concepts and context-dependent work. The original embedding already provides one lookup at the model’s entrance. We could pass it to every layer, but that would give all of them the same extra vector.

A separate table for each layer would let it learn the token information useful at that point in the model. As a first attempt, make those vectors as wide as the residual stream, so we can add them directly:

layer lookupCurrent token representationEarlier context is dimmed; outlined columns are current.Current token computation.Token idtResidual streamLayer 1Attention + feed-forward+E₁Earlier context is dimmed; outlined columns are current.Current token computation.+Earlier context is dimmed; outlined columns are current.Current token computation.Layer 2Attention + feed-forward+E₂Earlier context is dimmed; outlined columns are current.Current token computation.+Earlier context is dimmed; outlined columns are current.Current token computation.Layer 3Attention + feed-forward+E₃Earlier context is dimmed; outlined columns are current.Current token computation.+Earlier context is dimmed; outlined columns are current.Current token computation.Token passed to the next layer7,168—7,1687,1687,168—7,1687,1687,168—7,1687,1687,168
First proposal: give each layer a full-width token lookup and add it to the residual stream after its usual updates. The layers are stacked vertically; the same token id supplies a different learned vector to each one.

The token id takes the same route into the tables every time. The evolving representation flows down through the layers. Each layer therefore receives both what the model has worked out so far and a fresh lookup of its own static token information.

That direct addition exposes two problems. Full-width tables are large: we need a vector for every token at every layer. And a fixed lookup always adds the same contribution, even when the token is being used differently. A lookup for “bank” cannot respond to a river or a loan on its own.

Make the extra path narrow, then let context control it

The lookup does not have to be added immediately. We could keep it in a smaller space and only project it to the token width at the end. The worked models use 256 coordinates for this extra input; the main token width follows the model selected above.

That reduces the size of the tables, but a narrower fixed vector is still fixed. To make its contribution depend on the sentence, we can let the current representation produce a matching 256-coordinate gate. Multiplying the gate and lookup coordinate by coordinate changes what passes through. The output projection then restores the token width, and normalisation controls the update’s scale:

layer useToken after attention and feed-forwardEarlier context is dimmed; outlined columns are current.Current token computation.WgGELUEarlier context is dimmed; outlined columns are current.Current token computation.Layer ℓ’s extra inputEarlier context is dimmed; outlined columns are current.Current token computation.×WoRMSNormEarlier context is dimmed; outlined columns are current.Current token computation.+Updated token representation7,1687,168————7,1687,168
The side path: the current representation produces a gate, multiplies the extra input, projects it back to the token width and normalises it before addition. All widths follow the selected model.

The same static vector can now contribute differently in different contexts. We have added a gate and projections, so this is extra work, but their inner width stays small. The aim is to give static information its own capacity without making all of the feed-forward calculations wider.

There is still something we can reuse. Every new table is supplying information about tokens that already have learned representations in the original embedding table. Rather than asking the extra lookups to supply everything independently, we can give them access to that shared starting point.

Reuse the original embedding alongside the lookup

For each layer, project the original embedding into the same narrow width as its lookup, normalise the projected part, and combine them. The scale factors keep the two paths and their sum under control:

layer inputToken idtEℓEarlier context is dimmed; outlined columns are current.Current token computation.Original token embeddingEarlier context is dimmed; outlined columns are current.Current token computation.Wpℓ× 1/√DRMSNormEarlier context is dimmed; outlined columns are current.Current token computation.+× 1/√2Earlier context is dimmed; outlined columns are current.Current token computation.Prepared input for layer ℓ———7,1687,168———
One layer’s input combines its token-table lookup with a normalised projection of the original token embedding. Both have the same narrow width. D is the token width; ℓ identifies the layer.

The prepared vector fits into the extra-input branch of the gated diagram above. Its two parts still depend on the original token, so they can be prepared before the layer runs. The gate is calculated later from the current representation and decides how that static input contributes here.

This combination is called Per-Layer Embeddings (PLE). The lookup and projected original embedding are components of its prepared per-layer input, rather than separately named variants.

The tables still add parameters, and the side path still adds computation. What we have changed is where the model can keep and use its learned information: static token-specific capacity has a direct lookup path, while the feed-forward network can devote more of its capacity to other concepts and transformations.

Sources and assumptions

The additional tables add parameters, but accessing them is a lookup rather than a multiplication over the whole table. They can be stored outside accelerator memory and fetched as needed, with transfer costs. This is a supporting efficiency benefit; the main motivation here is the separate path for static token-specific information. The opening stack is the full-width proposal being improved; the later diagrams show the narrow path. The picker covers the Gemma variants used in these worked diagrams. Their per-layer width is 256 and their per-layer lookup vocabulary is 262,144; Gemma 3n’s main vocabulary additionally contains special tokens. Eℓ and Wpℓ represent one layer’s slices of the packed table and projection. The implementation prepares all layers’ inputs together. The input projection is scaled by 1/√D, normalised over the narrow coordinates, added to the scaled lookup and multiplied by 1/√2. The lookup’s embedding scale is folded into the looked-up vector in the diagram. The Gemma 4 path applies its GELU-family activation, multiplies by the prepared input, projects, normalises, then adds. AltUp (Alternating Updates) is the name of Gemma 3n’s multiple-stream mechanism, not a separate PLE variant. Gemma 3n adds the projected term to its other AltUp streams; it is not the single-stream residual drawing shown here. Other layer operations and Gemma 4’s final layer scalar are not expanded.

← Browse all subjectsBack to the beginning ↑