Instructions to use ktrapeznikov/gpt2-medium-topic-small-set with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ktrapeznikov/gpt2-medium-topic-small-set with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ktrapeznikov/gpt2-medium-topic-small-set")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ktrapeznikov/gpt2-medium-topic-small-set") model = AutoModelForCausalLM.from_pretrained("ktrapeznikov/gpt2-medium-topic-small-set", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ktrapeznikov/gpt2-medium-topic-small-set with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ktrapeznikov/gpt2-medium-topic-small-set" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ktrapeznikov/gpt2-medium-topic-small-set", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ktrapeznikov/gpt2-medium-topic-small-set
- SGLang
How to use ktrapeznikov/gpt2-medium-topic-small-set 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 "ktrapeznikov/gpt2-medium-topic-small-set" \ --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": "ktrapeznikov/gpt2-medium-topic-small-set", "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 "ktrapeznikov/gpt2-medium-topic-small-set" \ --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": "ktrapeznikov/gpt2-medium-topic-small-set", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ktrapeznikov/gpt2-medium-topic-small-set with Docker Model Runner:
docker model run hf.co/ktrapeznikov/gpt2-medium-topic-small-set
Commit ·
d048b57
1
Parent(s): 8cd96ce
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
thumbnail:
|
| 5 |
+
widget:
|
| 6 |
+
- text: "topic climate source"
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
# GPT2-medium-topic-news
|
| 10 |
+
|
| 11 |
+
## Model description
|
| 12 |
+
|
| 13 |
+
GPT2-medium fine tuned on a small news corpus conditioned on a topic, source, title
|
| 14 |
+
|
| 15 |
+
## Intended uses & limitations
|
| 16 |
+
|
| 17 |
+
#### How to use
|
| 18 |
+
|
| 19 |
+
To generate a news article text conditioned on a topic, source, title or some subsets, prompt model with:
|
| 20 |
+
```python
|
| 21 |
+
f"topic {topic} source"
|
| 22 |
+
f"topic {topic} source {source} title"
|
| 23 |
+
f"topic {topic} source {source} title {title} body"
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
Try the following tags for `topic: climate, weather, vaccination`.
|
| 27 |
+
|
| 28 |
+
Zero shot generation works pretty well as long as `topic` is a single word and not too specific.
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
device = "cuda:0"
|
| 32 |
+
tokenizer = AutoTokenizer.from_pretrained("ktrapeznikov/gpt2-medium-topic-small-set")
|
| 33 |
+
model = AutoModelWithLMHead.from_pretrained("ktrapeznikov/gpt2-medium-topic-small-set")
|
| 34 |
+
model.to(device)
|
| 35 |
+
topic = "climate"
|
| 36 |
+
prompt = tokenizer(f"topic {topics} source straitstimes title", return_tensors="pt")
|
| 37 |
+
out = model.generate(prompt["input_ids"].to(device), do_sample=True,max_length=500, early_stopping=True, top_p=.9)
|
| 38 |
+
print(tokenizer.decode(out[0].cpu(), skip_special_tokens=True))
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## Training data
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
## Training procedure
|