This repository contains a GPT-2-style autoregressive language model trained from randomly initialized weights using the Reuters articles dataset.
The model learns to generate text by predicting the next token based on the preceding tokens in a sequence.
This model uses the GPT-2 architecture and was trained from scratch without loading pretrained GPT-2 weights. It was trained on English-language Reuters news articles using causal language modeling (CLM).
The model can be used for experimental text generation based on English-language financial and general news text. It can also be used to explore autoregressive language modeling and next-token prediction.
The model can serve as a starting point for further experiments involving:
This model is not intended for production applications, financial decision-making, or generating reliable factual reports. It should not be used as a source of verified financial or news information.
Users should review generated text before using it. Generated financial information should be independently verified. The model is best suited for educational and experimental purposes.
The following example demonstrates how to load the model and generate text using the Transformers library.
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "Dineth2001/reuters-gpt2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
prompt = "AMEX SAYS SHORT INTEREST"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
**inputs,
max_new_tokens=100,
do_sample=True,
temperature=0.8,
top_k=50,
top_p=0.95
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
The model was trained using the ingeniumacademy/reuters_articles dataset.
The dataset contains English-language Reuters news articles divided into three splits:
| Dataset split | Number of articles |
|---|---|
| Training | 17,262 |
| Validation | 2,158 |
| Test | 2,158 |
The title and body of each article were concatenated to form the input text.
The model was initialized using GPT2Config and GPT2LMHeadModel from Hugging Face Transformers. No pretrained GPT-2 model weights were used.
ingeniumacademy/gpt2-reuters-tokenizer was used.| Hyperparameter | Value |
|---|---|
| Training epochs | 5 |
| Batch size | 16 |
| Learning rate | 0.0005 |
| Weight decay | 0.01 |
| Random seed | 23 |
| Block size | 256 |
| Number of layers | 6 |
| Number of attention heads | 8 |
| Embedding dimension | 256 |
| Dropout | 0.1 |
| Optimizer | AdamW |
| Vocabulary size | 52,000 |
| Training objective | Causal Language Modeling |
| Training regime | FP16 |
The model was evaluated using the held-out validation and test datasets.
The test split contains 2,158 Reuters articles that were not used during training or validation.
The model was evaluated on its overall language modeling performance. Text generation was also examined using different Reuters article titles as prompts.
| Metric | Result |
|---|---|
| Final training loss | 3.7183 |
| Final validation loss | 4.1604 |
| Test loss | 3.9574 |
| Test perplexity | Approximately 52.3 |
The training and validation losses decreased over the five training epochs, indicating that the model learned patterns from the Reuters articles dataset.
The model was also evaluated through text generation using Reuters article titles as prompts. The generated text demonstrated some Reuters-style financial reporting patterns, although repetition, limited coherence, and weak relevance to some prompts were observed.
The model's next-token predictions were examined using prompts such as ROMEO: and JULIET:. The model produced predictions influenced by the patterns learned from the Reuters dataset, rather than demonstrating knowledge of Shakespeare's literary works.
The effect of changing a single word in a prompt was also examined by comparing next-token probability distributions.
The model is based on the GPT-2 transformer decoder architecture and uses causal language modeling as its training objective.
| Configuration | Value |
|---|---|
| Vocabulary size | 52,000 |
| Transformer layers | 6 |
| Attention heads | 8 |
| Embedding dimension | 256 |
| Maximum sequence length | 256 |
| Dropout | 0.1 |
| Total parameters | 18,116,608 |
T4 GPU was used.
This model was developed as part of an academic assignment.
model.safetensors 69 MiBtraining_args.bin 5.1 KiB