Parameter-Efficient Transformer Embeddings via Functional Factorization

A transformer reads text as tokens, and a token needs unpacking. Before the model sees any text, a fixed program cuts the text into pieces drawn from a vocabulary of a few tens of thousands of pieces. A common word is one piece and a rare word is several, so unbelievable might become un, believ and able. Each piece has a number, its id, and the model only ever sees the list of ids.

The first thing the model does with each id is look up a row of numbers for it in a table, with one row per token in the vocabulary. That row is the token's embedding, the table is the embedding table, and it is the dullest part of a transformer. The length of each row is the model width, and every layer above works on lists of that length. In a small sentence encoder, a model that turns a whole sentence into one list of numbers, the table is also most of the parameters, where a parameter is one learned number and the count of them is the usual measure of a model's size.

A 30,522-token vocabulary at width 256 is 7.8M numbers before a single attention layer. In the one-layer encoder below that table is 7.8M of the 8.9M total. Those numbers are the wrong shape for a device budget. The attention layers, where each token reads the other tokens in the sentence, and the feed-forward layers, where each token is transformed on its own, are where the sentence gets understood. They are crowded out by a lookup that gives every token its own independent 256 numbers, including the tokens seen a handful of times in training.

Rare tokens end up with under-trained vectors. Distinct vectors end up encoding overlapping roles. And the count grows as VdV d, vocabulary size times width, whether or not that freedom is used. I wanted to know whether a compact sentence encoder actually needs an independent vector per token, or whether the rows of that table could be generated by one shared function of the token id.

namewhat it is
SNLI and MNLITwo datasets of sentence pairs labelled by whether the second sentence follows from the first. NLI stands for natural language inference, and these are what the encoders train on.
STS-BThe Semantic Textual Similarity Benchmark, sentence pairs that people scored from 0 to 5 for how similar they are. This is what the encoders are tested on.
BERTGoogle's 2019 encoder model that most small sentence encoders descend from.
WordPieceThe program BERT uses to cut text into tokens. Its vocabulary has 30,522 word pieces, each with an id.
BERT-Tiny, BERT-Mini, TinyBERT, MobileBERT-TinyShrunk versions of BERT at 4M to 15M parameters. I quote them only as context for scale.
ALBERTA BERT variant that, among other changes, shrinks the table by writing it as the product of two smaller matrices. It is one of the methods I did not compare against.

PETE does the second. It maps the id to a single number between minus one and one, expands that number with fixed sines and cosines, and refines the result with a small shared network. Encoders are trained on NLI, the task of saying whether one sentence follows from another, and tested on STS-B, which asks how similar two sentences are. In that setting PETE keeps most of the lookup table's score with a model up to eight times smaller, and a 58K-parameter version still lines up with human similarity judgments to a useful degree. The claim is narrow and I will say how narrow.

The row generator

From here on there is some notation, but it all describes one picture. A standard embedding layer learns a free matrix E∈RV×dmodelE \in \mathbb{R}^{V \times d_{\text{model}}}, one independent row per token, so its parameter count is VdmodelV d_{\text{model}}. Geometrically the table is VV points scattered freely in a space with dmodeld_{\text{model}} dimensions, with nothing tying one to another. PETE replaces the rows with a rule,

Ep,:=gθ ⁣(ϕ(p)),fθ=gθ∘ϕ:[−1,1]→Rdmodel, E_{p,:} = g_\theta\!\left(\phi(p)\right), \qquad f_\theta = g_\theta \circ \phi : [-1, 1] \to \mathbb{R}^{d_{\text{model}}},

where ϕ\phi is a fixed rule that turns a token id into a list of numbers, and gθg_\theta is a learned function shared by every token. The composite fθf_\theta takes a single number to a vector, so the set of all its possible outputs is a curve in Rdmodel\mathbb{R}^{d_{\text{model}}}. The VV rows of the table are VV samples along that one curve.

That is the geometric content of the method. Instead of placing VV points I place one curve and read it at VV positions. The learned part is a two-layer MLP of hidden width hh. An MLP is the plainest kind of neural network. It multiplies its input by a matrix of weights, passes each result through a fixed curve such as one that sets negative values to zero, and multiplies by a second matrix, and the hidden width is the number of results in the middle. So the embedding stage has O(dmodelh+hdmodel)O(d_{\text{model}} h + h d_{\text{model}}) learned parameters and none of them depend on VV. Make the vocabulary ten times larger and the embedding stage does not grow, it is only read at more positions.

This is not a low-rank factorisation E≈ABE \approx AB, where the table is written as the product of two thin matrices. The rank of a table is the number of independent directions its rows span, and a low-rank table puts all VV rows inside a flat sheet with rr directions through the origin. A curve is a different constraint. It has one direction at any point, but it can wind through the whole space, so the matrix of its samples need not have low rank at all.

What the two share is the motivation, replacing an unconstrained dense matrix with a structured one that has far fewer free numbers. PETE is a low-capacity row generator, not a rank cut.

The coordinate

The curve needs a parameter, and the only thing a token brings to the embedding layer is its id, its position in the vocabulary list. So the coordinate is the id, scaled into a fixed interval,

xp=2pV−1−1,p∈{0,…,V−1}, x_p = \frac{2p}{V - 1} - 1, \qquad p \in \{0, \dots, V - 1\},

which puts token 0 at −1-1, token V−1V - 1 at +1+1 and the rest evenly between. The interval is the same whatever the vocabulary size.

Two things make that less silly than it sounds. Subword tokenisers like BPE and WordPiece, the programs that cut text into tokens, assign ids roughly in descending order of frequency. So the frequent tokens crowd one end of the interval and the rare ones the other, and there is weak statistical structure along the index even though the ordering is imperfect, corpus-dependent and noisy.

And the point is not that neighbouring ids mean similar things. They mostly do not. The id is a fixed coordinate system over the vocabulary and that is all it is. PETE does not assume that id proximity means similar meaning, does not claim the vocabulary has a hidden structure along a single line, and leaves the disentangling of what the index muddles to the layers above the embedding.

Fourier features

A single number is a poor input for a small network, which would have to carve [−1,1][-1, 1] into tens of thousands of distinguishable pieces on its own. So the coordinate is first turned into dmodeld_{\text{model}} numbers by a fixed set of sines and cosines. A basis is a set of building-block functions that other functions are written as combinations of, and sines and cosines at whole-number frequencies are the Fourier basis,

Ti(p)={sin⁡ ⁣(πxp(⌊i/2⌋+1)),i even,cos⁡ ⁣(πxp(⌊i/2⌋+1)),i odd,T(p)∈Rdmodel. T_i(p) = \begin{cases} \sin\!\left(\pi x_p (\lfloor i/2 \rfloor + 1)\right), & i \text{ even}, \\ \cos\!\left(\pi x_p (\lfloor i/2 \rfloor + 1)\right), & i \text{ odd}, \end{cases} \qquad T(p) \in \mathbb{R}^{d_{\text{model}}}.

Pairs of coordinates share an integer frequency. Coordinates 0 and 1 are the sine and cosine at frequency 1, which complete one cycle as xx runs from −1-1 to 11. Coordinates 2 and 3 are at frequency 2, and so on up to frequency dmodel/2d_{\text{model}}/2.

Each sine and cosine pair traces a circle as xx moves, and the pair at frequency kk goes round kk times across the vocabulary. T(p)T(p) is the point on all those circles at once at the moment xpx_p. So TT is itself a curve, a fixed one, smooth and bounded in every coordinate, winding through Rdmodel\mathbb{R}^{d_{\text{model}}}.

Two ids far apart on the index are far apart on the curve, and two adjacent ids are close. The high-frequency coordinates separate ids that the low-frequency ones cannot. Because every coordinate takes the same value at x=−1x = -1 and x=1x = 1, the curve is closed, and the first and last ids receive the same features.

These sines and cosines are a standard basis for functions on an interval. Any reasonably smooth function of the index can be written as a combination of them. The low frequencies carry the slow trends, such as whatever frequency ordering the tokeniser left in the ids, and the high frequencies carry the fine variation.

Three things make this the right lift. It costs no parameters, it is fixed before training, and it covers both slowly and rapidly varying functions of the index at once.

The residual MLP

The fixed curve on its own is not an embedding. Its shape was chosen with no knowledge of language, and the index is only weakly tied to token statistics, so the curve has to be bent into a shape the encoder can use. A shared MLP does the bending, and it is attached as a residual, which means its output is added to its input rather than replacing it,

E(p)=MLP ⁣(T(p))+T(p). E(p) = \mathrm{MLP}\!\left(T(p)\right) + T(p).

Read this as a displacement field. Every point on the fixed curve is moved by a vector the MLP computes from where that point is. Because the MLP is continuous the moved points still lie on a continuous curve.

The residual matters for two reasons. When the MLP's output is small, which is how it starts, the embedding is already the Fourier curve, a spread-out set of distinct vectors rather than noise, so training begins from structure. And the MLP only has to learn the correction to that structure rather than the structure itself.

The embedding table becomes a low-capacity deformation of a fixed basis, and every token shares the parameters of the deformation. That sharing is a strong structural prior, a built-in assumption about what the table should look like. It is better understood as a constraint that keeps the encoder from overfitting than as a claim that token meaning lies along a single line.

It also has a cost I will come back to. The curve is smooth, so neighbouring ids get nearly the same embedding. That is enforced smoothness over an index that does not in general respect meaning.

the embedding table as a curvetwo of the d coordinates · a lookup table places V free points, PETE reads one curve at V positionslookup tableV × d free numberseach row placed on its ownnothing ties one token to anotherfixed Fourier curve Tsin(πkx), cos(πkx), k = 1 .. d/2zero parameterstoken p sits at x_p = 2p/(V−1) − 1drawn here, sin(πx) against sin(2πx)E = MLP(T) + Tone shared displacement bends the curveO(d·h) parameters, none depend on Vneighbours in id stay neighboursthe dashed curve is T before bending
A lookup table is V free points in d dimensions. PETE places one fixed Fourier curve, reads it at V evenly spaced positions, and lets a shared MLP bend it. Two of the d coordinates are drawn and the bending is schematic.
one token id becomes one embedding rowno row is stored · the same function generates every row of Etoken 7id in 0..30521x_p-1.000T(p)sin, cos · d of themE(p)MLP(T) + Tfirst 24 Fourier coordinates of T(p)x_p = 2p/(V−1) − 1 = -1.000token 2048id in 0..30521x_p-0.866T(p)sin, cos · d of themE(p)MLP(T) + Tfirst 24 Fourier coordinates of T(p)x_p = 2p/(V−1) − 1 = -0.866token 11091id in 0..30521x_p-0.273T(p)sin, cos · d of themE(p)MLP(T) + Tfirst 24 Fourier coordinates of T(p)x_p = 2p/(V−1) − 1 = -0.273token 22970id in 0..30521x_p+0.505T(p)sin, cos · d of themE(p)MLP(T) + Tfirst 24 Fourier coordinates of T(p)x_p = 2p/(V−1) − 1 = +0.505token 30521id in 0..30521x_p+1.000T(p)sin, cos · d of themE(p)MLP(T) + Tfirst 24 Fourier coordinates of T(p)x_p = 2p/(V−1) − 1 = +1.000
A token id is scaled into the interval from minus one to one, lifted by fixed sines and cosines at integer frequencies, and corrected by a shared residual MLP. Nothing is looked up. Five ids cycle through so the feature vector changes with the coordinate.

The comparison

The question is whether a sentence encoder with its table replaced still produces useful sentence vectors, so the test is sentence-level and nothing else changes. Encoders train on SNLI and MNLI with a contrastive loss in the style of InfoNCE. A contrastive loss teaches the model to pull matching pairs together and push everything else apart.

Each training pair is a premise and a hypothesis labelled entailment, which means the hypothesis follows from the premise, and that pair is a positive. Every other sentence in the batch is a negative. The sentence embedding is the one list of numbers the encoder produces for a whole sentence. Sentence embeddings hih_i and hjh_j are compared by cosine similarity, the cosine of the angle between the two vectors, which is 1 when they point the same way and 0 when they are at right angles. The similarity is scaled by a learned temperature τ\tau that sets how sharp the comparison is. The loss pushes the positive pair's similarity above the similarity to every in-batch negative.

Evaluation is zero-shot, meaning the model never trains on STS-B. I take the model's cosine similarity for each pair of sentences and measure how well it agrees with the human scores on the STS-B validation set. Spearman correlation measures whether the model ranks the pairs in the same order as people do, and Pearson correlation measures whether the two sets of scores move together in a straight line.

The lookup baseline and PETE share everything else. Same number of layers, same number of attention heads, where a head is one of several copies of attention run side by side, same width and same feed-forward ratio, the size of the feed-forward layer relative to the width. Both use the same GeGLU activation inside the feed-forward layers, a gated version of the fixed curve, rotary position embeddings, which tell the model where in the sentence each token sits, RMSNorm, which rescales each vector to a standard size, and the BERT WordPiece tokenizer with V=30,522V = 30{,}522.

Both train with the same AdamW optimiser, the procedure that updates the weights from the loss, at a learning rate of 2×10−52 \times 10^{-5}, which is the size of each update step. Both use 1,000 warmup steps, during which the learning rate ramps up from zero, a batch of 128 pairs per step, 122,700 steps and mixed precision, which stores some numbers at lower precision to run faster. Neither uses dropout, the practice of switching off random units during training, so that nothing regularises one and not the other. In the table, L is the number of layers, H the number of heads and d the width.

modelL / HdparamsSpearmanPearson
PETE1 / 42561.1M74.9374.54
lookup1 / 42568.9M77.0176.80
PETE1 / 85124.7M75.2174.65
lookup1 / 851220.1M77.5076.78
PETE2 / 42562.2M76.3876.02
lookup2 / 42569.9M77.3476.89

Read the parameter column against the score column. At one layer and width 256 the lookup model is 8.9M parameters and PETE is 1.1M, about eight times smaller, for 2.1 Spearman points. At width 512 it is 20.1M against 4.7M for 2.3 points. At two layers and width 256 it is 9.9M against 2.2M for about one point.

The gap closes with depth, which is what you would expect if the layers above are doing the refining that the table used to do. The reduction is smaller at the larger configurations because the encoder layers grow with width and depth while the table does not. So the table's share of the total shrinks and there is less for PETE to remove.

total parameters, millions, same transformer with and without the tablelookup, 1 layer, d=2568.9MPETE, 1 layer, d=2561.1Mlookup, 1 layer, d=51220.1MPETE, 1 layer, d=5124.7Mlookup, 2 layers, d=2569.9MPETE, 2 layers, d=2562.2M
With a 30,522-token vocabulary at width 256 the table alone is 7.8M parameters, more than everything else in a one-layer encoder. PETE replaces it with a two-layer MLP whose size depends on the width, not the vocabulary.
zero-shot STS-B Spearman after NLI training707274767877.074.91L · 25677.575.21L · 51277.376.42L · 256lookupPETE
Same encoder, same training, only the way the embedding rows are produced differs. PETE gives up about two Spearman points at one layer and one point at two layers, for a model four to eight times smaller.

Pushing further down, with smaller feed-forward layers and reduced intermediate widths while keeping the same embedding mechanism, a 58K-parameter PETE encoder reaches 69.25 average correlation after fine-tuning on STS-B, meaning further training on STS-B's own training split. 396K reaches 78.0, 1.5M reaches 79.7, and 3.6M reaches 81.8.

BERT-Tiny at about 4M and BERT-Mini at about 11M sit at 73.95 in the same table. TinyBERT and MobileBERT-Tiny at 14 to 15M reach 80.4 and 80.1 Spearman. But the training objectives, data, distillation and optimisation all differ across those rows. Distillation means training a small model to copy a large one, and some of those models had that help. So that table is context for the scale of the models and not a head-to-head. The controlled comparison in this paper is the one above.

What it does not say

The result means that in a compact sentence encoder the embedding layer tolerates a far stronger built-in assumption than it usually gets. Independent token vectors are not necessary for useful sentence-level representations at this scale, and a curve with a shared deformation recovers most of what they gave. It does not mean the table is unnecessary in general.

What stands is that the embedding layer in a small sentence encoder can take a far stronger built-in assumption than it usually gets, and that generating rows from a function is a reasonable design point next to explicit low-rank compression rather than a replacement for it.

References

  1. Lan et al., ALBERT: a lite BERT for self-supervised learning of language representations, 2020.
  2. Svenstrup, Hansen and Winther, Hash embeddings for efficient word representations, 2017.
  3. Xu, Xu and Mandic, TensorGPT: efficient compression of large language models based on tensor-train decomposition, 2024.
  4. Shen et al., Q-BERT: Hessian based ultra low precision quantization of BERT, 2019.
  5. Bowman et al., A large annotated corpus for learning natural language inference, EMNLP, 2015.
  6. Williams, Nangia and Bowman, A broad-coverage challenge corpus for sentence understanding through inference, NAACL, 2018.
  7. Cer et al., SemEval-2017 task 1: semantic textual similarity, 2017.
  8. Devlin et al., BERT: pre-training of deep bidirectional transformers for language understanding, NAACL, 2019.
  9. Su et al., RoFormer: enhanced transformer with rotary position embedding, 2023.