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.
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.
Models built as a Transformer encoder
- Name the emotion in a sentenceALBERT Base v2 Emotion12M params
- Change how a voice speakstiny-voca4.5M params
- Rerank search resultsMS MARCO TinyBERT-L24.4M params
- Find beats and downbeatsBeat This! Small3.2M params
- Fill a gap in ChineseBERT Base Chinese102M params
- Classify text with your labelsXtremeDistil zero-shot13M params
- Ask a question about a tableGoogle TAPAS Tiny4.5M params
- Read a phrase aloudKokoro 82M81M params
- Translate a Chinese sentenceHelsinki-NLP OPUS-MT111M params
- Find an answer in a passageDistilBERT SQuAD65M params
- Find a caption that fits a photoTinyCLIP ViT-8M/1623M params
- Transcribe a short English recordingWav2Vec2 Base 960h94M params
- Find the most relevant answerall-MiniLM-L6-v223M params