GPT-2 trained from scratch on Reuters articles

A small GPT-2 decoder trained from random initialisation (no pretrained weights) with the self-supervised next-token-prediction objective on ingeniumacademy/reuters_articles (title + body of each article), using the tokenizer ingeniumacademy/gpt2-reuters-tokenizer. CS4681 Advanced Machine Learning, Assignment 02 (Self-Supervised Learning).

Results

split loss (nats/token) perplexity
validation 3.9179 50.29
test 3.7727 43.50

loss curves

Model

layers / heads / d_model / FFN 8 / 8 / 512 / 2048
context length 256
vocabulary 52000 (tied input/output embeddings)
dropout 0.2
parameters 51,975,168 (25,220,096 non-embedding)

Training

  • Data: 2,786,171 training tokens. Text = TITLE\nbody<|endoftext|>; hard line-wraps re-joined, empty rows and duplicate articles removed.
  • Packing: articles concatenated and cut into 256-token windows at random offsets every epoch.
  • AdamW (beta2 0.95), lr 0.0006, cosine schedule with 5% warm-up, weight decay 0.1, batch 64 x 256 tokens, 20 epochs, bf16, best-validation checkpoint kept (epoch 19.39).
  • Training time: 17.94 min on one NVIDIA GB10.
  • Experiment tracking: MLflow on DagsHub, https://dagshub.com/ifa.imty015/adv-ml-assignment/experiments

Sample perplexities on test-title prompts

title decoding PPL(generated) PPL(real article)
PENTAGON STOPS NEW BUSINESS WITH TOSHIBA greedy 2.6 113.1
PENTAGON STOPS NEW BUSINESS WITH TOSHIBA nucleus 4.2 113.1
VENEZUELA WANTS 2.4 BILLION DLRS EXPORT FINANCE greedy 2.7 20.8
VENEZUELA WANTS 2.4 BILLION DLRS EXPORT FINANCE nucleus 3.8 20.8
AUDI OF AMERICA LIFTS CAR PRICES greedy 2.2 241.3
AUDI OF AMERICA LIFTS CAR PRICES nucleus 4.7 241.3
ARCHER-DANIELS DENIES RUMOR greedy 3.1 90.9
ARCHER-DANIELS DENIES RUMOR nucleus 6.6 90.9

Usage

from transformers import AutoTokenizer, AutoModelForCausalLM
tok = AutoTokenizer.from_pretrained("IfaImty/gpt2-reuters-from-scratch")
model = AutoModelForCausalLM.from_pretrained("IfaImty/gpt2-reuters-from-scratch")
ids = tok(tok.eos_token + "PENTAGON STOPS NEW BUSINESS WITH TOSHIBA\n", return_tensors="pt").input_ids
out = model.generate(ids, max_new_tokens=100, do_sample=True, top_p=0.9, temperature=0.8, pad_token_id=tok.eos_token_id)
print(tok.decode(out[0][ids.shape[1]:]))

Other files

  • training/: full log history (every 10 steps), run summary, configuration record
  • evaluation/: hyper-parameter search results, generated samples and their perplexities
  • figures/: loss curves and all analysis plots
  • q4-runs/ablation-A-2epochs, q4-runs/ablation-B-small-d256-L4: the two single-setting runs (Q4)

Limitations

Trained on ~3M tokens of 1987 Reuters business news only: fluent newswire style, but facts and numbers are invented, long-range coherence is weak and prompts outside the domain (e.g. Shakespeare) are handled poorly.

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

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