BERT(Bidirectional Encoder Representations from Transformers): Built using transformer Encoder blocks. Is a fully bidirectional model (context from left and right). Used for text classification, question answering, Named Entity Recognition.
Pretraining: process of training in a model on a large dataset usually in unsupervised manner. Allows model to learn general knowledge before tuning it on a specific task.
BERT pretraining techniques
- Masked Language Modelling (MLM): Randomly masks 15% of input tokens and model tries to predict the missing words. Allows model to learn relationships between words and how meaning changes
- Next sentence prediction (NSP): Given a sentence A and sentence B, predict if B is a logical next sentence following A. Allows model to learn how sentences connect logically in a paragraph and how ideas naturally flow in human language.
Text classification using BERT:
- [CLS] (classification) token is prepended to whole input text before passing onto BERT, [CLS] token is a vector that is used to represent whole input text context.
- Every input token (including [CLS]) is passed through model, layers use self-attention, in the process [CLS] token too 'sees' the whole sentence just like every other token does.
- We disregard every token except for [CLS] token which is now treated as 'sentence representation' Remember through self-attention [CLS] attends to every other token enriching with context from the entire sequence.
- We pass [CLS] token to a custom classifier layer to make classifications on downstream tasks.
| Configuration | Transformer base encoder | BERT base | BERT large |
|---|---|---|---|
| Encoder layers | 6 | 12 | 24 |
| Hidden dimension | 512 | 768 | 1024 |
| Attention heads | 8 | 12 | 16 |
BERT base and BERT large have approximately 110M and 340M parameters. The original base Transformer has about 65M across its encoder–decoder model, so its total is not an encoder-only comparison.
The source table calls this row “FFNN Dimension,” but the listed 512/768 values refer to hidden or model width, not the larger intermediate feed-forward dimension. Parameter totals also depend on whether one counts an encoder alone or the entire encoder–decoder system.
BERT Variants
- RoBERTa: optimizes BERT-style pretraining with more data and training, and removes the next-sentence prediction objective.
RoBERTa stands for Robustly Optimized BERT Pretraining Approach. The notes emphasize better benchmark performance through changes to BERT’s training recipe; that comparison applies to the reported experimental settings rather than every task or model size.
- TinyBERT: distills a larger model into a smaller network for more efficient inference.
TinyBERT uses knowledge distillation to retain much of a larger teacher model’s performance in a smaller student. The motivation includes deployment on resource-constrained edge devices. The resulting accuracy, memory use, and latency depend on student size and the task.
- Multilingual BERT - Trained on 104 languages, supports zero-shot cross-lingual transfer
- BioBERT - Retrained on biomedial corpus
- SciBERT - Retrained on scientific articles
- BERTweet - RoBERTa trained on 850M tweets
- FinBERT - Adapted to financial domain
GPT (Generative Pre-trained Transformers): predicts the next token in a sequence based on all previous tokens. Built using transformer's Decoder block. Uses masked attention to prevent attending to future tokens. Doesn’t uses Cross attention.
| Model | Release year | Parameters | Layers | Training-data note |
|---|---|---|---|---|
| GPT-1 | 2018 | 117 million | 12 | BooksCorpus |
| GPT-2 | 2019 | 1.5 billion | 48 | WebText, approximately 40 GB |
| GPT-3 | 2020 | 175 billion | 96 | Mixture including filtered Common Crawl and other corpora |
GPT versions: training context and focus
| Version | Training context from the notes | Focus |
|---|---|---|
| GPT-1 | BooksCorpus, roughly 7,000 unpublished books | Unsupervised generative pretraining with a Transformer language model |
| GPT-2 | WebText, approximately 40 GB of text | Larger-scale language modeling with improved Transformer training |
| GPT-3 | A mixture of filtered Common Crawl and other corpora; the notes associate 570 GB with the web-data component | Few-shot learning, prompting, and emerging code-generation ability |
| GPT-4 | Architecture size and detailed training data were not disclosed in the technical report | Text-and-image input with text output; broader language and reasoning capabilities |
Historical correction: the notebook labels GPT-4 “not yet released” and speculates about approximately 100 trillion parameters. Those are not established specifications. Its technical report was released in March 2023 and does not disclose a parameter count. The notebook also lists 175 as GPT-3’s layer count; the 175-billion-parameter model has 96 layers.
Language Models are Few-Shot Learners (GPT-3)
GPT Applications:
- Text to UI
- Code generation
- Semantic search
- much more …
The next-token pretraining objective alone does not ensure reliable instruction following; instruction tuning and other post-training methods can improve it.
T5 (Text-to-Text Transfer Transformer): Inputs text and outputs text for all unified NLP tasks. Can do translation, summarization, classification, Q/A. Uses Transformer's Encoder and Decoder blocks. Uses relative scalar positional embeddings instead of absolute ones.
Pretraining strategy - Span Corruption: 15% of input tokens are replaced by unique sentinel tokens, decoder's job is to reconstruct the removed spans in order. The reconstruction should happen in flow, predict MASK1 then MASK2 …, each mask may have more than one words allowing T5 to learn sentence flow and learn larger and meaningful phrases.
Alignment:
- Since pretrained architectures are probabilistic by nature, we need to align models to behave in ways that are consistent with human values, intentions and ethical standards.
- Without alignment AI might follow instructions too literally, give harmful outputs, produce inaccurate, toxic content, Fail to follow user task instruction
Alignment Approaches:
- Instruction tuning - teaching model to follow instructions using high-quality human-written prompts and answers
- Human feedback (RLHF) - Human ranks multiple responses allowing model to understand best response
- Reward Modeling - Model predicts which responses are most aligned with human preferences
- Supervised Fine-tuning (SFT) training model on annotated dataset that represents ethical, safe and helpful behavior
Alignment Goals:
- Produce AI that is helpful
- Honest
- Harmless