Foundations to Frontier
Tests
E. Deep Learning › E12 Transformer Architectures

ALBERT

ALBERT (Lan and colleagues, ICLR 2020) shrinks BERT's parameter count dramatically with two tricks. A factorised embedding first maps tokens to a small dimension E and then projects them to the hidden size H. Cross-layer sharing uses one Transformer block for every layer. It also replaces next-sentence prediction with sentence-order prediction. ALBERT-base has about 12 M parameters against BERT-base's 110 M, but sharing does not reduce compute, and the best ALBERT models were very wide and slow. This page covers the two reductions, sentence-order prediction and the parameter–compute distinction. In the exercises you count factorised and shared models, then test sharing on a task that repeats one operation, three-hop pointer chasing. Two separate layers reach 0.992, while two layers sharing one block reach only 0.491, no better than a single layer (0.455), in the same training budget.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Fewer parameters by reusing them

ALBERT asks: does every layer of BERT need its own weights? It uses one set of layer weights over and over, twelve times, and makes the word table much thinner. The model’s file shrinks almost tenfold. But it still does twelve layers of computation, so it is not faster, and reusing weights can make some things harder to learn, as the research exercise shows. The demo shows the patterns of attention each layer computes.

Transformer lab
Computed pairs: 136 of 256 for 16 tokens. Sparse patterns grow linearly with length instead of quadratically.
Why engineers care

Parameter count, memory and compute are different budgets. ALBERT shows a model can be small to store yet just as expensive to run, which matters when choosing models for devices.

📝 Quick check (Level 0)
0/3 answered
  1. 1. ALBERT shares…
  2. 2. Sharing reduces…
  3. 3. ALBERT replaced next-sentence prediction with…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Factorised embedding:
    • V × E + E × H instead of V × H;
    • for V = 30,000, H = 768 and E = 128 that is 3.94 M instead of 23.0 M (5.9 times smaller);
    • at H = 4096, 4.36 M instead of 122.9 M (28 times).
    • The argument: word embeddings carry context-independent information and need less width than contextual hidden states.
  • Cross-layer sharing:
    • one block (attention and FFN) reused for all L layers saves (L − 1) times one layer’s parameters, 78 M for BERT-base’s 12 layers of 7.09 M;
    • an ALBERT-base-like model has about 11.7 M parameters against 109 M.
  • Compute is unchanged: each token still passes through L layers. Multiply–adds per token are L(4H² + 2H·d_ff), so ALBERT-xxlarge (H = 4096, 12 layers) costs about 28 times BERT-base per token while having about twice its parameters (235 M reported).
  • Sentence-order prediction:
    • positives are two consecutive segments (A, B), and negatives the same segments swapped (B, A);
    • unlike next-sentence prediction, topic cannot give the answer away.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Factorised embedding size for V = 30,000, E = 128, H = 768:
  2. 2. Parameters saved by sharing 12 layers of 7.09 M:
  3. 3. SOP negatives are…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

ALBERT in code

Exercise 1.

  • Factorised embeddings and full model counts gave 11,683,584 parameters for an ALBERT-base-like configuration, against 109,081,344 for BERT-base-like.
  • Sentence-order examples came out as consecutive pairs plus their swaps.

Practice.

  • Hugging Face AlbertModel uses embedding_size=128 and num_hidden_groups=1, which means all layers share one block.
  • Sharing reduces memory for weights and optimiser state, which helps with very wide models or memory-limited training. Activation memory and latency are unchanged.
  • ALBERT’s paper reported that sharing all parameters lowered accuracy somewhat at base size, sharing the FFN hurt most, and sharing attention little. The big wins came from making the shared model much wider.
from transformers import AlbertConfig, AlbertModel
cfg = AlbertConfig(embedding_size=128, hidden_size=768, num_hidden_layers=12, num_hidden_groups=1,
                   num_attention_heads=12, intermediate_size=3072)
model = AlbertModel(cfg); print(sum(p.numel() for p in model.parameters()))   # about 11.7 M
🐍 Exercise 1: shrinking BERT
Count factorised embeddings and shared encoders, and build sentence-order examples.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Hugging Face setting for full sharing:
  2. 2. Sharing does not reduce…
  3. 3. In ALBERT's ablation, sharing which part hurt most?

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Sharing as iterated computation.

  • A shared stack applies the same function L times, like an unrolled recurrent network in depth.
  • It can express any algorithm that repeats one step, and the Universal Transformer (Dehghani et al., 2019) builds on this.
  • Separate layers can specialise: early layers parse, later layers combine.

Why sharing can learn worse.

  • The single block must work well at every depth at once, where inputs have different statistics.
  • Gradients from all depths are summed into the same weights and can conflict.
  • In exercise 2, the task repeats one operation (follow a pointer), the best case for sharing, yet the shared stack learned far less in the same number of steps.

Factorisation’s argument. Lan et al. argue that the embedding table only needs to represent tokens out of context, which needs fewer dimensions than contextual hidden states. Factorisation also cuts the large gradient matrix for the embeddings.

📝 Quick check (Level 3)
0/3 answered
  1. 1. A shared stack resembles…
  2. 2. A model built on repeated shared layers:
  3. 3. Sharing can learn worse because…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Does sharing layers cost accuracy?

History.

  • Z. Lan, M. Chen, S. Goodman, K. Gimpel, P. Sharma and R. Soricut, “ALBERT: a lite BERT for self-supervised learning of language representations” (ICLR 2020).
  • ALBERT-xxlarge (235 M parameters, H = 4096) topped GLUE, SQuAD and RACE on release, at high compute.
  • M. Dehghani et al.’s Universal Transformer (ICLR 2019) also shared weights across depth.

Exercise 2.

  • Task: each of 8 tokens is a pointer to a position; the target at position i is a[a[a[i]]] (three hops). After reading its own token, a position needs two attention lookups.
  • Models: 1 layer, 2 separate layers, or 2 layers sharing one block, each with 4 heads and d = 32, using the multi-layer NumPy Transformer with gradients checked numerically.
  • Training: 600 Adam steps.
model parameters three-hop accuracy
1 layer 8,936 0.455
2 separate layers 17,352 0.992
2 layers, one shared block 8,936 0.491

A second seed gave 0.475, 0.998 and 0.754. Three layers sharing one block gave 0.483 and 0.739.

  • Two separate layers solve it; one layer cannot do two lookups.
  • Sharing halves the parameters but learned far less in the same budget: 0.49 and 0.75 over two seeds, sometimes barely better than one layer. This holds even though the task repeats exactly one operation.
  • Depth through repetition is possible but harder to learn. It is consistent with ALBERT’s small accuracy loss from sharing at equal width, and its reliance on much wider models to win back accuracy.
🐍 Exercise 2 (research): does sharing layers cost accuracy?
Train one layer, two separate layers and two shared layers on three-hop pointer chasing.

ALBERT in AI, robotics and aerospace

  • Storage-limited devices: shared weights shrink model files for over-the-air updates to vehicles or satellites, but not inference cost.
  • Choosing budgets: compare models on latency and energy, not only parameter count.
  • Recurrent depth: shared-layer models can trade more iterations at inference for accuracy, a property explored in adaptive-computation models.

References

  1. Z. Lan et al. (2020). “ALBERT: a lite BERT for self-supervised learning of language representations.” Proc. ICLR.
  2. M. Dehghani, S. Gouws, O. Vinyals, J. Uszkoreit, Ł. Kaiser (2019). “Universal Transformers.” Proc. ICLR.