Transformer encoder

Attention · pattern · Text, Token sequence → Scores, Embedding, Class label

Token embeddings refined by repeated blocks of self-attention and a feed-forward MLP, each wrapped in a residual and LayerNorm.

Also called BERT-style encoder, Encoder-only transformer, Self-attention stack

Figure 1. The Transformer encoder as a schematic: the parts it is built from and how data flows between them. Select a part to read about it.

What it does

A transformer encoder turns a sequence of tokens into a sequence of context-aware vectors. Token and position embeddings are summed, then the same block is repeated L times: multi-head self-attention lets every token gather information from every other token, and a two-layer feed-forward MLP transforms each token on its own. Each sub-layer has a residual connection and layer normalization. A small head reads the result: the first token’s vector for classification, a start and end score per token for question answering, or the mean over tokens for an embedding.

Formula

X0 = E[tokens] + PA = LN(X + MHA(X))X′ = LN(A + W2 GELU(W1 A + b1) + b2)

Shapes and parameters

Shapes
Token ids [N, T]; hidden states [N, T, D] throughout; the feed-forward block widens to [N, T, 4D].
Parameters
Per layer about 4D² (attention) + 8D² (feed-forward) = 12D², plus the embedding table V × D. With D = 256 and 6 layers: about 4.7 million plus embeddings.
Used for
BERT, ALBERT, DistilBERT, MiniLM, TinyBERT, TAPAS and XtremeDistil in the catalog; the text side of CLIP.

Figure 2. A real transformer encoder in WeightSpace: Ask a question about a table, drawn from the file the app runs. Open a module to see the parts inside.

In WeightSpace

Catalog encoders are edited at their output: classifier biases (emotions, entailment, punctuation marks, masked-word candidates), a few reranker weights, or single final LayerNorm parameters in the QA and retrieval models, always within ±8 of the shipped value.