gpt2-reuters-scratch
A small GPT-2 model trained from scratch on Reuters news articles. This is the base model.
The model was trained with self-supervised next-token prediction (causal language modelling) on the
ingeniumacademy/reuters_articles dataset.
Its weights started randomly initialised: no pretrained GPT-2 checkpoint was loaded. The only thing reused is the
tokenizer ingeniumacademy/gpt2-reuters-tokenizer,
a byte-level BPE tokenizer trained on the same corpus.
It was built for CS4681 Assignment 02: Self-Supervised Learning. Two related models were trained to study the effect of single settings:
| Model | Epochs | Layers / heads / hidden | Params | Val PPL | Test PPL |
|---|---|---|---|---|---|
| gpt2-reuters-scratch (this model) | 5 | 4 / 4 / 256 | 16.5 M | 86.92 | 70.27 |
| gpt2-reuters-scratch-2ep | 2 | 4 / 4 / 256 | 16.5 M | 161.95 | 129.65 |
| gpt2-reuters-scratch-large | 5 | 6 / 6 / 384 | 30.7 M | 66.34 | 54.56 |
Model configuration
| Class | GPT2LMHeadModel (decoder-only Transformer) |
Layers (n_layer) | 4 |
Attention heads (n_head) | 4 |
Hidden size (n_embd) | 256 |
Context window (n_positions) | 256 tokens |
| Vocabulary size | 52,000 |
| Dropout (residual / embedding / attention) | 0.1 / 0.1 / 0.1 |
| Activation | GELU (gelu_new) |
| Word embeddings tied to LM head | Yes |
| Special tokens | <|endoftext|> (id 0) used as BOS, EOS and PAD |
| Total parameters | 16,537,088 (≈ 16.5 M), all trainable |
Training data
| Articles | 256-token blocks | |
|---|---|---|
| Train | 17,262 | 11,882 |
| Validation | 2,158 | 1,609 |
| Test | 2,158 | 1,236 |
Pre-processing
- Each article's title and body are joined into a single full text:
TITLE + "\n" + BODY. <|endoftext|>is added to the end of every article so the model learns where an article ends.- The text is tokenized with
ingeniumacademy/gpt2-reuters-tokenizer. That gives 3,043,954 training tokens, about 176 tokens per article on average. - All tokens are concatenated and cut into fixed 256-token blocks, so no padding is needed.
labels = input_ids. The model shifts the labels by one position internally, so every token is trained to predict the next one (DataCollatorForLanguageModeling(mlm=False)).
Training procedure
Trained with the Hugging Face Trainer.
| Hyper-parameter | Value |
|---|---|
| Epochs | 5 |
| Steps | 1,860 (372 per epoch) |
| Batch size | 32 blocks (8,192 tokens) |
| Optimizer | AdamW (adamw_torch_fused), β = (0.9, 0.999), ε = 1e-8 |
| Weight decay | 0.1 |
| Peak learning rate | 5e-4 |
| LR schedule | Cosine decay after 93 linear warm-up steps (5 %) |
| Gradient clipping | 1.0 |
| Mixed precision | fp16 |
| Evaluation | Validation loss at the end of every epoch |
| Seed | 42 |
| Hardware | 1 × NVIDIA Tesla T4 (Google Colab) |
| Libraries | transformers 5.24.1, torch 2.14.1 |
| Wall-clock training time | 6.46 minutes |
Learning curve
| Epoch | Train loss (≈) | Validation loss | Val − train gap |
|---|---|---|---|
| 1 | 5.283 | 5.288 | 0.005 |
| 2 | 4.623 | 4.798 | 0.175 |
| 3 | 4.351 | 4.578 | 0.227 |
| 4 | 4.166 | 4.484 | 0.317 |
| 5 | 4.129 | 4.465 | 0.336 |
Validation loss goes down every epoch, but the improvement levels off after epoch 3. The growing gap between training and validation loss shows the model is starting to overfit.
Evaluation results
Perplexity is exp(loss), where the loss is the average cross-entropy per token on the 256-token blocks.
| Split | Loss | Perplexity |
|---|---|---|
| Validation | 4.4649 | 86.92 |
| Test | 4.2524 | 70.27 |
| Train (average over the whole run) | 4.8062 | – |