Instructions to use Dineth2001/reuters-gpt2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Dineth2001/reuters-gpt2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Dineth2001/reuters-gpt2")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Dineth2001/reuters-gpt2") model = AutoModelForCausalLM.from_pretrained("Dineth2001/reuters-gpt2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Dineth2001/reuters-gpt2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Dineth2001/reuters-gpt2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Dineth2001/reuters-gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Dineth2001/reuters-gpt2
- SGLang
How to use Dineth2001/reuters-gpt2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Dineth2001/reuters-gpt2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Dineth2001/reuters-gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Dineth2001/reuters-gpt2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Dineth2001/reuters-gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Dineth2001/reuters-gpt2 with Docker Model Runner:
docker model run hf.co/Dineth2001/reuters-gpt2
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
- Repository: https://huggingface.co/Dineth2001/reuters-gpt2
- Training notebook: https://colab.research.google.com/drive/1LNzR0giRNQ--AMB5WyzoAklEzay-baQr?usp=sharing
- Dataset: Reuters Articles Dataset
- Tokenizer: GPT-2 Reuters Tokenizer
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-tokenizerwas 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