Instructions to use IfaImty/gpt2-reuters-from-scratch with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use IfaImty/gpt2-reuters-from-scratch with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="IfaImty/gpt2-reuters-from-scratch")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("IfaImty/gpt2-reuters-from-scratch") model = AutoModelForCausalLM.from_pretrained("IfaImty/gpt2-reuters-from-scratch", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use IfaImty/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 "IfaImty/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": "IfaImty/gpt2-reuters-from-scratch", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/IfaImty/gpt2-reuters-from-scratch
- SGLang
How to use IfaImty/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 "IfaImty/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": "IfaImty/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 "IfaImty/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": "IfaImty/gpt2-reuters-from-scratch", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use IfaImty/gpt2-reuters-from-scratch with Docker Model Runner:
docker model run hf.co/IfaImty/gpt2-reuters-from-scratch
GPT-2 trained from scratch on Reuters articles
A small GPT-2 decoder trained from random initialisation (no pretrained weights) with the self-supervised
next-token-prediction objective on ingeniumacademy/reuters_articles
(title + body of each article), using the tokenizer ingeniumacademy/gpt2-reuters-tokenizer.
CS4681 Advanced Machine Learning, Assignment 02 (Self-Supervised Learning).
Results
| split | loss (nats/token) | perplexity |
|---|---|---|
| validation | 3.9179 | 50.29 |
| test | 3.7727 | 43.50 |
Model
| layers / heads / d_model / FFN | 8 / 8 / 512 / 2048 |
| context length | 256 |
| vocabulary | 52000 (tied input/output embeddings) |
| dropout | 0.2 |
| parameters | 51,975,168 (25,220,096 non-embedding) |
Training
- Data: 2,786,171 training tokens. Text =
TITLE\nbody<|endoftext|>; hard line-wraps re-joined, empty rows and duplicate articles removed. - Packing: articles concatenated and cut into 256-token windows at random offsets every epoch.
- AdamW (beta2 0.95), lr 0.0006, cosine schedule with 5% warm-up, weight decay 0.1, batch 64 x 256 tokens, 20 epochs, bf16, best-validation checkpoint kept (epoch 19.39).
- Training time: 17.94 min on one NVIDIA GB10.
- Experiment tracking: MLflow on DagsHub, https://dagshub.com/ifa.imty015/adv-ml-assignment/experiments
Sample perplexities on test-title prompts
| title | decoding | PPL(generated) | PPL(real article) |
|---|---|---|---|
| PENTAGON STOPS NEW BUSINESS WITH TOSHIBA | greedy | 2.6 | 113.1 |
| PENTAGON STOPS NEW BUSINESS WITH TOSHIBA | nucleus | 4.2 | 113.1 |
| VENEZUELA WANTS 2.4 BILLION DLRS EXPORT FINANCE | greedy | 2.7 | 20.8 |
| VENEZUELA WANTS 2.4 BILLION DLRS EXPORT FINANCE | nucleus | 3.8 | 20.8 |
| AUDI OF AMERICA LIFTS CAR PRICES | greedy | 2.2 | 241.3 |
| AUDI OF AMERICA LIFTS CAR PRICES | nucleus | 4.7 | 241.3 |
| ARCHER-DANIELS DENIES RUMOR | greedy | 3.1 | 90.9 |
| ARCHER-DANIELS DENIES RUMOR | nucleus | 6.6 | 90.9 |
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
tok = AutoTokenizer.from_pretrained("IfaImty/gpt2-reuters-from-scratch")
model = AutoModelForCausalLM.from_pretrained("IfaImty/gpt2-reuters-from-scratch")
ids = tok(tok.eos_token + "PENTAGON STOPS NEW BUSINESS WITH TOSHIBA\n", return_tensors="pt").input_ids
out = model.generate(ids, max_new_tokens=100, do_sample=True, top_p=0.9, temperature=0.8, pad_token_id=tok.eos_token_id)
print(tok.decode(out[0][ids.shape[1]:]))
Other files
training/: full log history (every 10 steps), run summary, configuration recordevaluation/: hyper-parameter search results, generated samples and their perplexitiesfigures/: loss curves and all analysis plotsq4-runs/ablation-A-2epochs,q4-runs/ablation-B-small-d256-L4: the two single-setting runs (Q4)
Limitations
Trained on ~3M tokens of 1987 Reuters business news only: fluent newswire style, but facts and numbers are invented, long-range coherence is weak and prompts outside the domain (e.g. Shakespeare) are handled poorly.
- Downloads last month
- -
