Reuters GPT-2

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.

Model Details

Model Description

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).

  • Shared by: Dineth2001
  • Model type: GPT-2-style autoregressive language model
  • Language(s): English
  • License: MIT
  • Fine-tuned from: Not applicable. Model weights were randomly initialized.

Model Sources

Uses

Direct Use

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.

Downstream Use

The model can serve as a starting point for further experiments involving:

  • Fine-tuning on domain-specific news articles.
  • Exploring text generation and language modeling.
  • Comparing training configurations and model performance.

Out-of-Scope Use

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.

Bias, Risks, and Limitations

  • The model was trained on a relatively small dataset compared with large-scale language models.
  • Its language patterns and knowledge are limited by the Reuters articles used during training.
  • Generated text may contain grammatical errors, repetition, or incoherent statements.
  • The model may generate inaccurate financial figures or misleading information.
  • The model does not have access to current news or real-time information.
  • A lower perplexity does not necessarily indicate that generated text is factually correct or coherent.

Recommendations

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.

How to Get Started with the Model

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))

Training Details

Training Data

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.

Training Procedure

The model was initialized using GPT2Config and GPT2LMHeadModel from Hugging Face Transformers. No pretrained GPT-2 model weights were used.

Preprocessing

  • Article titles and bodies were concatenated.
  • The tokenizer ingeniumacademy/gpt2-reuters-tokenizer was used.
  • An end-of-sequence token was added to separate articles.
  • Tokenized text was grouped into blocks of 256 tokens.
  • The model was trained using causal language modeling, where each token is used to predict the next token.

Training Hyperparameters

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

Speeds, Sizes, Times

  • Total parameters: 18,116,608 (approximately 18.12 million)
  • Training time: Approximately 459.63 seconds (7 minutes and 40 seconds)
  • Final model: Five-epoch trained model

Evaluation

The model was evaluated using the held-out validation and test datasets.

Testing Data, Factors & Metrics

Testing Data

The test split contains 2,158 Reuters articles that were not used during training or validation.

Factors

The model was evaluated on its overall language modeling performance. Text generation was also examined using different Reuters article titles as prompts.

Metrics

  • Training loss: Measures the model's prediction error on the training data.
  • Validation loss: Measures prediction error on the validation data and helps monitor generalization.
  • Test loss: Measures prediction error on the held-out test data.
  • Perplexity: Measures how well the model predicts the next tokens. Lower values indicate better predictive performance.

Results

Metric Result
Final training loss 3.7183
Final validation loss 4.1604
Test loss 3.9574
Test perplexity Approximately 52.3

Summary

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.

Model Examination

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.

Technical Specifications

Model Architecture and Objective

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

Compute Infrastructure

Hardware

T4 GPU was used.

Software

  • Python
  • PyTorch
  • Hugging Face Transformers
  • Hugging Face Datasets
  • Hugging Face Tokenizers

Citation

This model was developed as part of an academic assignment.

Downloads last month
38
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