GPT-2 (small, from scratch) trained on Reuters articles
This is a small GPT-2 style language model for CS4681 Assignment 2. It was trained from random
weights on the train split of ingeniumacademy/reuters_articles (title + body as one text). No pretrained GPT
weights were used. The tokenizer is ingeniumacademy/gpt2-reuters-tokenizer plus one added [PAD] token.
Model
| layers / heads / hidden size | 6 / 8 / 256 |
| context length | 256 |
| vocabulary size | 52001 |
| parameters | 18,116,864 |
Training
5 epochs, learning rate 0.0005, batch size 16, AdamW with weight decay 0.01, cosine schedule with 5% warm-up, seed 42. Training took 17.9 minutes on Tesla T4.
Results (best epoch: 5)
| split | loss | perplexity | top-1 acc | top-5 acc |
|---|---|---|---|---|
| validation | 4.0057 | 54.91 | 0.339 | 0.537 |
| test | 3.7781 | 43.73 | 0.368 | 0.557 |
How to use
Start prompts with the end-of-text token, the way every training window starts:
import torch
from transformers import GPT2LMHeadModel, GPT2TokenizerFast
tok = GPT2TokenizerFast.from_pretrained("L0rd008/gpt2-reuters-from-scratch")
model = GPT2LMHeadModel.from_pretrained("L0rd008/gpt2-reuters-from-scratch")
ids = [tok.eos_token_id] + tok("YOUR TITLE HERE\n", add_special_tokens=False)["input_ids"]
out = model.generate(torch.tensor([ids]), max_new_tokens=100, do_sample=True, top_k=50, top_p=0.95,
pad_token_id=tok.pad_token_id)
print(tok.decode(out[0]))
Limits
The model is small and was trained on about 3,061,180 tokens of news text, so it writes Reuters-style sentences but it does not know facts. Do not rely on anything it writes.