A causal language model predicts each token from tokens earlier in the sequence, following the left-to-right order used when generating ordinary text. During training, a causal data collator prevents predicted tokens from using later prompt tokens. section 10.2.2 section 8.1.3
Distinguish causal prediction from masked or bidirectional modeling:
- Set mlm=False when training on ordinary left-to-right text; set it to True for randomly masked-token datasets such as those used with BERT. section 10.2.2
- Use causal models for normal text generation, while bidirectional or acausal models use information from both directions for tasks such as masking and OCR correction. section 10.2.2 section 8.1.3
Fine-tuning GPT-2
Load text lines, tokenize them with truncation and padding, split the dataset into training and evaluation sets, and configure Hugging Face Trainer with DataCollatorForLanguageModeling(mlm=False). Fine-tuning GPT-2 on the resulting dataset can change a completion such as “NLP is” into domain-shaped text.


