Expand description
BERT Model V2 - Clean implementation using solid abstractions
BERT is an encoder-only model with key differences from decoder-only models:
- Returns embeddings (ModelOutputs::Embeddings) instead of logits
- Bidirectional attention (NO causal masking)
- Uses position embeddings (learned) instead of RoPE
- Uses token type embeddings for segment distinction
- Uses LayerNorm (not RMSNorm)
- Has a pooler for [CLS] token representation
Structsยง
- Bert
Attention - BERT attention: self-attention + output projection with residual
- Bert
Config - Bert
Embeddings - BERT embeddings: word + position + token_type embeddings, then LayerNorm
- Bert
Encoder - BERT encoder: stack of BertLayer
- Bert
Intermediate - BERT intermediate (first FFN layer with activation)
- Bert
Layer - BERT transformer layer
- Bert
Model V2 - Main BERT model implementation
- Bert
Output - BERT output (second FFN layer with residual and LayerNorm)
- Bert
Pooler - BERT pooler: takes [CLS] token and projects through dense + tanh
- Bert
Self Attention - BERT self-attention (bidirectional, no causal mask)
- Bert
Self Output - BERT self-attention output projection