GPT-2 (small) trained from scratch on Reuters articles

A small GPT-2 language model trained from randomly initialised weights on the Reuters articles dataset using the causal (next-token prediction) language modelling objective. No pretrained GPT-2 weights were used.

This model was trained for CS4681 Assignment 02 (Self-Supervised Learning).

Model configuration

Setting Value
Architecture GPT2LMHeadModel
Layers (n_layer) 6
Attention heads (n_head) 8
Embedding size (n_embd) 256
Context length (n_positions) 256
Vocabulary size 52,000
Parameters 18,116,608
Tokenizer ingeniumacademy/gpt2-reuters-tokenizer

Training data

Each example is the article title and body joined as title + "\n" + body, followed by <|endoftext|>. Rows with both title and body empty were removed (16,544 train / 2,152 validation / 2,145 test articles). All tokenized articles were concatenated and split into blocks of 256 tokens (11,870 train / 1,609 validation / 1,235 test blocks, about 3.04M training tokens). Labels are a copy of the input tokens, so every token, including <|endoftext|>, is a prediction target.

Training procedure

Setting Value
Epochs 5 (1,855 steps)
Batch size 32 blocks
Optimiser AdamW, learning rate 5e-4, weight decay 0.01
Schedule 5% linear warmup, cosine decay
Precision fp32
Hardware Apple M4 Pro GPU (MPS)
Training time 143.2 min wall-clock (slowed by another process sharing the GPU; about 15 min at normal speed)

Results

Split Loss Perplexity
Validation 4.3772 79.62
Test 4.1644 64.36
Epoch Training loss Validation loss
1 5.2432 5.4248
2 4.6328 4.7668
3 4.2841 4.5010
4 4.1056 4.4121
5 4.0123 4.3772

Training and validation loss

The full training log is in log_history.json.

Downloads last month
52
Safetensors
Model size
18.1M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Dataset used to train Shaveen12/gpt2-reuters-from-scratch