Instructions to use Pathumi/reuters-gpt2-from-scratch with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Pathumi/reuters-gpt2-from-scratch with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Pathumi/reuters-gpt2-from-scratch")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Pathumi/reuters-gpt2-from-scratch") model = AutoModelForCausalLM.from_pretrained("Pathumi/reuters-gpt2-from-scratch", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Pathumi/reuters-gpt2-from-scratch with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Pathumi/reuters-gpt2-from-scratch" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Pathumi/reuters-gpt2-from-scratch", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Pathumi/reuters-gpt2-from-scratch
- SGLang
How to use Pathumi/reuters-gpt2-from-scratch 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 "Pathumi/reuters-gpt2-from-scratch" \ --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": "Pathumi/reuters-gpt2-from-scratch", "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 "Pathumi/reuters-gpt2-from-scratch" \ --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": "Pathumi/reuters-gpt2-from-scratch", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Pathumi/reuters-gpt2-from-scratch with Docker Model Runner:
docker model run hf.co/Pathumi/reuters-gpt2-from-scratch
GPT-2 Language Model Trained from Scratch on Reuters Articles
Model Details
The objective was to train a small GPT-2 language model from scratch using the Reuters news articles dataset. The model uses Causal Language Modeling (CLM), where it learns to predict the next token based on the preceding tokens in a text sequence.
The model was initialized with random weights without using any pretrained GPT-2 model weights. Training and evaluation were performed using Hugging Face Transformers and PyTorch.
- Developed by: Pathumi
- Model type: GPT-2 autoregressive language model
- Language: English
- Training method: Self-supervised causal language modeling
- Initialization: Random weights (trained from scratch)
- Repository: https://huggingface.co/Pathumi/reuters-gpt2-from-scratch
Model Sources
- Model Repository: https://huggingface.co/Pathumi/reuters-gpt2-from-scratch
- Dataset: https://huggingface.co/datasets/ingeniumacademy/reuters_articles
- Tokenizer: https://huggingface.co/ingeniumacademy/gpt2-reuters-tokenizer
Uses
The model is intended for educational and experimental purposes, particularly for understanding self-supervised learning and autoregressive text generation.
The model can be used for:
- Generating news-like text from an input prompt.
- Predicting the next token in a sequence.
- Analyzing next-token probability distributions.
- Evaluating generated text using perplexity.
- Studying the effects of training epochs and learning rates.
How to Get Started with the Model
The model can be loaded using Hugging Face Transformers.
from transformers import AutoTokenizer, GPT2LMHeadModel
model_id = "Pathumi/reuters-gpt2-from-scratch"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = GPT2LMHeadModel.from_pretrained(model_id)
prompt = "The company announced"
inputs = tokenizer(prompt, return_tensors="pt")
output = model.generate(
**inputs,
max_new_tokens=50,
do_sample=True,
temperature=0.8,
top_k=50,
pad_token_id=tokenizer.eos_token_id
)
print(tokenizer.decode(output[0], skip_special_tokens=True))
Training Details
Training Data
The model was trained using the Reuters Articles dataset available on Hugging Face.
| Dataset Split | Number of Articles |
|---|---|
| Training | 17,262 |
| Validation | 2,158 |
| Testing | 2,158 |
Each article contains two fields: title and body.
Training Procedure
Preprocessing
The title and body of each Reuters article were combined into a single text sequence.
The combined text was tokenized using the ingeniumacademy/gpt2-reuters-tokenizer, which has a vocabulary size of 52,000 tokens.
The maximum sequence length was set to 128 tokens to reduce computational requirements.
Model Configuration
| Parameter | Value |
|---|---|
| Model Architecture | GPT-2 |
| Transformer Layers | 4 |
| Attention Heads | 4 |
| Embedding Dimension | 256 |
| Vocabulary Size | 52,000 |
| Maximum Sequence Length | 128 |
| Total Parameters | 16,504,320 |
| Weight Initialization | Random |
| Training Objective | Causal Language Modeling |
Training Hyperparameters
Three training configurations were evaluated.
| Configuration | Epochs | Learning Rate |
|---|---|---|
| Baseline | 2 | 0.0005 |
| Experiment 1 | 5 | 0.0005 |
| Experiment 2 | 2 | 0.0002 |
The batch size was 8 for both training and evaluation. A fixed random seed of 42 was used across experiments to improve reproducibility.
Training was performed using the Hugging Face Trainer API with GPU acceleration and FP16 mixed precision.
Technical Specifications
Hardware: Google Colab GPU runtime.
Software:
- Python
- PyTorch
- Hugging Face Transformers 4.57.3
- Hugging Face Datasets 4.4.1
- Hugging Face Accelerate 1.12.0
- Downloads last month
- 83