GPT-2 Reuters – 5 Epochs
Model Description
This model is a small GPT-2-based causal language model trained from scratch on the Reuters articles dataset.
The model was initialized with randomly generated weights rather than pretrained GPT-2 weights. It was trained for 5 epochs to learn language patterns, terminology, and textual structures from Reuters news articles.
This experiment extends the 2-epoch training experiment to investigate how additional training affects language modeling performance and text generation quality.
The model is designed for next-token prediction and autoregressive text generation, particularly in news and financial text domains.
Model Details
| Property | Value |
|---|---|
| Model architecture | GPT-2 |
| Model type | Causal Language Model |
| Parameters | 16,602,624 |
| Transformer layers | 4 |
| Attention heads | 4 |
| Hidden size | 256 |
| Vocabulary size | 52,000 |
| Maximum sequence length | 512 |
| Training epochs | 5 |
| Initialization | Random weights |
Training Dataset
The model was trained using the Reuters Articles Dataset.
The dataset contains English-language news articles with separate title and body fields.
The title and body of each article were combined into a single text sequence before tokenization.
Dataset splits:
| Split | Articles |
|---|---|
| Training | 17,262 |
| Validation | 2,158 |
| Testing | 2,158 |
The text was tokenized using GPT-2 Reuters Tokenizer.
Tokenized sequences were grouped into blocks of 512 tokens for causal language modeling.
| Split | Training blocks |
|---|---|
| Training | 5,468 |
| Validation | 736 |
| Testing | 581 |
Training Configuration
| Parameter | Value |
|---|---|
| Training epochs | 5 |
| Learning rate | 5e-4 |
| Training batch size | 4 |
| Evaluation batch size | 4 |
| Gradient accumulation steps | 4 |
| Weight decay | 0.01 |
| Warmup steps | 100 |
| Maximum sequence length | 512 |
| Optimizer | Hugging Face Trainer default |
| Evaluation strategy | Every epoch |
| Best checkpoint selection | Lowest validation loss |
The model was trained using the Hugging Face Transformers Trainer API.
Evaluation Results
The model was evaluated on the validation and test splits using cross-entropy loss and perplexity.
| Metric | Result |
|---|---|
| Training loss | 5.4450 |
| Validation loss | 4.8550 |
| Test loss | 4.6179 |
| Validation perplexity | 128.38 |
| Test perplexity | 101.28 |
| Training time | 10.58 minutes |
Perplexity was calculated as the exponential of the corresponding evaluation loss.
Intended Use
This model can be used for:
- Autoregressive text generation.
- Next-token prediction experiments.
- Exploring language modeling on financial and news-related text.
- Educational experiments involving GPT-2 architecture and training from scratch.
- Comparing the effects of different training durations on language model performance.
- Studying how additional training affects generated text and perplexity.
Limitations
- This is a relatively small language model with approximately 16.6 million parameters.
- The model was trained for only 5 epochs and has limited general language knowledge.
- The model may generate repetitive, incomplete, or factually incorrect text.
- Its domain coverage is influenced by the Reuters training dataset.
- It should not be used as a source of verified financial or factual information.
- The model is not instruction-tuned or optimized for conversational tasks.
How to Use
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "NaveenSandaruwan/gpt2-reuters-scratch-5epochs"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
prompt = "The global financial markets"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
**inputs,
max_new_tokens=100,
do_sample=True,
temperature=0.8,
top_k=50,
pad_token_id=tokenizer.eos_token_id
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Training Information
- Training framework: PyTorch and Hugging Face Transformers.
- Model architecture: GPT-2.
- Training approach: Random initialization followed by causal language model training.
- Tokenizer: GPT-2 Reuters Tokenizer.
- Dataset: Reuters Articles Dataset.
This model was developed as part of an educational assignment exploring GPT-2 language model training and evaluation.