Instructions to use vihanga-munasinghe/gpt2-reuters with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vihanga-munasinghe/gpt2-reuters with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="vihanga-munasinghe/gpt2-reuters")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("vihanga-munasinghe/gpt2-reuters") model = AutoModelForCausalLM.from_pretrained("vihanga-munasinghe/gpt2-reuters", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use vihanga-munasinghe/gpt2-reuters with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vihanga-munasinghe/gpt2-reuters" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vihanga-munasinghe/gpt2-reuters", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/vihanga-munasinghe/gpt2-reuters
- SGLang
How to use vihanga-munasinghe/gpt2-reuters 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 "vihanga-munasinghe/gpt2-reuters" \ --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": "vihanga-munasinghe/gpt2-reuters", "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 "vihanga-munasinghe/gpt2-reuters" \ --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": "vihanga-munasinghe/gpt2-reuters", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use vihanga-munasinghe/gpt2-reuters with Docker Model Runner:
docker model run hf.co/vihanga-munasinghe/gpt2-reuters
gpt2-reuters
A small GPT-2 style causal language model trained from randomly initialised weights on the Reuters articles dataset. No pretrained GPT weights were used. It was trained for an Advanced Machine Learning (self-supervised learning) assignment and is intended for study, not for production use.
Model details
| Item | Value |
|---|---|
| Architecture | GPT2LMHeadModel (decoder-only transformer) |
| Parameters | 18.12M |
Layers (n_layer) |
6 |
Hidden size (n_embd) |
256 |
Attention heads (n_head) |
8 |
Context length (n_positions) |
256 tokens |
| Vocabulary size | 52,000 |
| Dropout (embedding / attention / residual) | 0.1 / 0.1 / 0.1 |
| Tied input and output embeddings | Yes |
Most of the parameters sit in the embedding table (52,000 x 256 is about 13.3M), so the transformer blocks themselves are a small part of the model.
Data
Dataset: ingeniumacademy/reuters_articles (train 17,262, validation 2,158, test 2,158 articles; columns
titleandbody).Tokenizer:
ingeniumacademy/gpt2-reuters-tokenizer(byte-level BPE trained on this corpus), included in this repository.Pre-processing: each article is turned into one "full text" string:
<title>\n<body><|endoftext|>All articles are concatenated into one token stream and cut into fixed blocks of 256 tokens (the leftover tail of each batch is dropped). Labels are a copy of the input ids; the model shifts them by one position internally for next-token prediction.
The title and body are joined with a single newline. Prompts at inference time should use the same separator (see usage below), because a different separator (for example a double newline) is tokenized differently and falls outside what the model saw in training.
Training
| Setting | Value |
|---|---|
| Objective | Causal language modelling (next-token prediction) |
| Framework | Hugging Face transformers Trainer (v5.22.1) |
| Epochs | 5 |
| Batch size | 32 sequences of 256 tokens |
| Learning rate | 5e-4, cosine schedule, 100 warmup steps |
| Optimizer | AdamW (default), weight decay 0.1, gradient clipping 1.0 |
| Seed | 42 |
| Hardware | Google Colab, single NVIDIA Tesla T4 |
| Training time | about 1,390 s (23 minutes), 1,860 steps |
Training and validation loss were logged every 100 steps.
Results
| Split | Loss | Perplexity |
|---|---|---|
| Train (last logged) | 4.03 | 56.2 |
| Validation | 4.382 | 80.0 |
| Test | 4.167 | 64.5 |
Perplexity is exp(loss). Validation and test sets contain different articles, which is why their
losses differ.
How to use
import torch
from transformers import AutoTokenizer, GPT2LMHeadModel
repo = "vihanga-munasinghe/gpt2-reuters"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = GPT2LMHeadModel.from_pretrained(repo).eval()
title = "AEL INDUSTRIES INC <AELNA.O> FIRST QTR NET"
prompt = title.strip() + "\n" # single newline, same as in training
ids = tokenizer(prompt, return_tensors="pt").input_ids
with torch.no_grad():
out = model.generate(ids, max_new_tokens=100, do_sample=True, top_p=0.9,
temperature=0.8, pad_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(out[0][ids.shape[1]:], skip_special_tokens=True))
Keep prompt plus generated text within 256 tokens, which is the model's context length.
Limitations
- Small data and model. The training corpus is only about 3 million tokens, far smaller than what language models are usually trained on, so the model learns the style and format of the corpus much better than facts or meaning.
- Output is fluent in form, not reliable in content. It reproduces the layout of Reuters briefs (for example "Shr ... vs ...", "Revs ... mln") and the closing "Reuter" line, but figures, names and events are invented and often inconsistent or repetitive.
- Domain and era. The text is 1980s newswire, with its abbreviations, upper-case headlines and company tickers. Prompts far from this style (for example literary text) give poor results.
- Context limit. The context window is 256 tokens.
- Not for real use. Do not use the output as a source of facts about companies or markets.
Files
model.safetensors,config.json,generation_config.json: model weights and configurationtokenizer.json,tokenizer_config.json,vocab.json,merges.txt,special_tokens_map.json: tokenizerREADME.md: this model card
Acknowledgements
Dataset and tokenizer by the ingeniumacademy Hugging Face account. Built with Hugging Face
transformers, datasets and accelerate.
- Downloads last month
- 83