Instructions to use Shaveen12/gpt2-reuters-from-scratch with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Shaveen12/gpt2-reuters-from-scratch with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Shaveen12/gpt2-reuters-from-scratch")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Shaveen12/gpt2-reuters-from-scratch") model = AutoModelForCausalLM.from_pretrained("Shaveen12/gpt2-reuters-from-scratch", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Shaveen12/gpt2-reuters-from-scratch with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Shaveen12/gpt2-reuters-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": "Shaveen12/gpt2-reuters-from-scratch", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Shaveen12/gpt2-reuters-from-scratch
- SGLang
How to use Shaveen12/gpt2-reuters-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 "Shaveen12/gpt2-reuters-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": "Shaveen12/gpt2-reuters-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 "Shaveen12/gpt2-reuters-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": "Shaveen12/gpt2-reuters-from-scratch", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Shaveen12/gpt2-reuters-from-scratch with Docker Model Runner:
docker model run hf.co/Shaveen12/gpt2-reuters-from-scratch
GPT-2 (small) trained from scratch on Reuters articles
A small GPT-2 language model trained from randomly initialised weights on the Reuters articles dataset using the causal (next-token prediction) language modelling objective. No pretrained GPT-2 weights were used.
This model was trained for CS4681 Assignment 02 (Self-Supervised Learning).
Model configuration
| Setting | Value |
|---|---|
| Architecture | GPT2LMHeadModel |
Layers (n_layer) |
6 |
Attention heads (n_head) |
8 |
Embedding size (n_embd) |
256 |
Context length (n_positions) |
256 |
| Vocabulary size | 52,000 |
| Parameters | 18,116,608 |
| Tokenizer | ingeniumacademy/gpt2-reuters-tokenizer |
Training data
Each example is the article title and body joined as title + "\n" + body, followed by <|endoftext|>.
Rows with both title and body empty were removed (16,544 train / 2,152 validation / 2,145 test articles).
All tokenized articles were concatenated and split into blocks of 256 tokens
(11,870 train / 1,609 validation / 1,235 test blocks, about 3.04M training tokens).
Labels are a copy of the input tokens, so every token, including <|endoftext|>, is a prediction target.
Training procedure
| Setting | Value |
|---|---|
| Epochs | 5 (1,855 steps) |
| Batch size | 32 blocks |
| Optimiser | AdamW, learning rate 5e-4, weight decay 0.01 |
| Schedule | 5% linear warmup, cosine decay |
| Precision | fp32 |
| Hardware | Apple M4 Pro GPU (MPS) |
| Training time | 143.2 min wall-clock (slowed by another process sharing the GPU; about 15 min at normal speed) |
Results
| Split | Loss | Perplexity |
|---|---|---|
| Validation | 4.3772 | 79.62 |
| Test | 4.1644 | 64.36 |
| Epoch | Training loss | Validation loss |
|---|---|---|
| 1 | 5.2432 | 5.4248 |
| 2 | 4.6328 | 4.7668 |
| 3 | 4.2841 | 4.5010 |
| 4 | 4.1056 | 4.4121 |
| 5 | 4.0123 | 4.3772 |
The full training log is in log_history.json.
- Downloads last month
- 52
