BERT model
An encoder-only transformer that learns bidirectional text representations through masked language modeling pretraining.
Bidirectional Encoder Representations from Transformers (BERT) is an encoder-only transformer that reads whole token sequences at once and learns contextual vectors for each position, which is why it became the standard starting point for classification and understanding tasks rather than open-ended text generation.
At a glance
- Family
- bert
- Source type
- Research
- Released
- October 2018
- Authors
- Jacob Devlin, Ming-Wei Chang, Kenton Lee, et al.
- Modalities
- Text
- Parameter count
- 110 million to 340 million parameters
- Context length
- 512 tokens
- Precision
- float32
What It Is
Bidirectional Encoder Representations from Transformers (BERT) is a research text model from Google that popularized deep bidirectional transformer encoders. It is encoder-only: it reads an input sequence and produces contextual representations for every token instead of generating new text one token at a time like decoder-only language models.Inputs And Outputs
BERT takes tokenized text as input. WordPiece tokenization splits words into subword pieces so rare words can still be represented. Each token receives a learned embedding, a position embedding that marks its place in the sequence, and a segment embedding when two sentences are packed together for tasks like question answering. The model returns a hidden vector for each token position. Downstream systems use those vectors for sentence classification, question answering, named-entity recognition, and other understanding tasks rather than open-ended generation.Architecture
Unlike decoder-only models that predict the next token from left to right, BERT processes the full sequence through transformer encoder blocks with bidirectional self-attention. The diagram below traces WordPiece tokens into combined embeddings, a repeated encoder block with bidirectional attention and feed-forward layers, contextual token vectors, and the masked-language-model or task heads used during pretraining and fine-tuning.Contextual
Token
RepresentationsMLM &
Task HeadsRepeated transformer encoder block containerBidirectional attention sublayer containerFeed-forward sublayer containerN×Add & NormBidirectional
Multi-Head
AttentionAdd & NormFeed
ForwardEmbeddingPosition
EmbeddingSegment
EmbeddingToken
EmbeddingWordPiece
TokensContextual
Token
Representations to MLM &
Task HeadsAdd & Norm to Contextual
Token
RepresentationsFeed
Forward to Add & NormAdd & Norm to Feed
ForwardAdd & Norm to Add & NormBidirectional
Multi-Head
Attention to Add & NormEmbedding to Bidirectional
Multi-Head
AttentionEmbedding to Add & NormToken
Embedding to EmbeddingPosition
Embedding to EmbeddingSegment
Embedding to EmbeddingWordPiece
Tokens to Token
Embedding