Text Generation
Transformers
ONNX
Safetensors
English
gpt2
fine-tuned
pirate
style-transfer
text-generation-inference
Instructions to use kruxarth/gpt2-pirate with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kruxarth/gpt2-pirate with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="kruxarth/gpt2-pirate")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("kruxarth/gpt2-pirate") model = AutoModelForCausalLM.from_pretrained("kruxarth/gpt2-pirate", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use kruxarth/gpt2-pirate with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kruxarth/gpt2-pirate" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kruxarth/gpt2-pirate", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/kruxarth/gpt2-pirate
- SGLang
How to use kruxarth/gpt2-pirate 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 "kruxarth/gpt2-pirate" \ --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": "kruxarth/gpt2-pirate", "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 "kruxarth/gpt2-pirate" \ --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": "kruxarth/gpt2-pirate", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use kruxarth/gpt2-pirate with Docker Model Runner:
docker model run hf.co/kruxarth/gpt2-pirate
GPT-2 Pirate π΄ββ οΈ
GPT-2 small (124M) post-trained to answer questions like a pirate.
Try it: GPT-2 Pirate demo, which shows plain GPT-2 and this model side by side.
Before vs after (questions not in the training data)
| Question | Plain GPT-2 | GPT-2 Pirate |
|---|---|---|
| What is the capital of Japan? | "The capital of Japan is Japan. Source: http://www.c-n.co.jp/..." | "Arr, the capital be Tokyo, matey, the capital of Japan be the capital o' the Pacific!" |
| Why do birds sing? | Rambles about birds' tongues | "Arr, birds sing by day, matey, to keep the sun at bay, an' keep the wind away!" |
Training
- Data: 60 hand-written question / pirate-answer pairs
- Method: full fine-tune (all 124M weights), AdamW, learning rate 5e-5, batch size 8, 6 epochs
- Loss: computed on the answer tokens only (question tokens masked with -100)
- Loss curve: 3.45 β 1.10
- Weight change: under 0.5% in any layer, yet the model picks up a new style and format
Usage
The model expects this prompt format:
from transformers import AutoTokenizer, AutoModelForCausalLM
tok = AutoTokenizer.from_pretrained("kruxarth/gpt2-pirate")
model = AutoModelForCausalLM.from_pretrained("kruxarth/gpt2-pirate")
prompt = "Question: How do I make tea?\nAnswer:"
inputs = tok(prompt, return_tensors="pt")
out = model.generate(**inputs, max_new_tokens=60, do_sample=True, temperature=0.7, top_p=0.9,
pad_token_id=tok.eos_token_id)
print(tok.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Limitations
This is a learning project. 60 examples teach the model a style, not knowledge, so answers are often factually wrong. GPT-2 small knows very little to begin with. Post-training shapes how a model answers; the knowledge comes from pretraining.
- Downloads last month
- 45
Model tree for kruxarth/gpt2-pirate
Base model
openai-community/gpt2