Instructions to use ktrapeznikov/gpt2-medium-topic-news-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ktrapeznikov/gpt2-medium-topic-news-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ktrapeznikov/gpt2-medium-topic-news-v2")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ktrapeznikov/gpt2-medium-topic-news-v2") model = AutoModelForCausalLM.from_pretrained("ktrapeznikov/gpt2-medium-topic-news-v2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ktrapeznikov/gpt2-medium-topic-news-v2 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-news-v2" # 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-news-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ktrapeznikov/gpt2-medium-topic-news-v2
- SGLang
How to use ktrapeznikov/gpt2-medium-topic-news-v2 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-news-v2" \ --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-news-v2", "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-news-v2" \ --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-news-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ktrapeznikov/gpt2-medium-topic-news-v2 with Docker Model Runner:
docker model run hf.co/ktrapeznikov/gpt2-medium-topic-news-v2
GPT2-medium-topic-news
Model description
GPT2-medium fine tuned on a largish news corpus conditioned on a topic, source, title
Intended uses & limitations
How to use
To generate a news article text conditioned on a topic, source, title or some subsets, prompt model with:
f"topic {topic} source"
f"topic {topic} source {source} title"
f"topic {topic} source {source} title {title} body"
Try the following tags for topic: climate, weather, vaccination.
Zero shot generation works pretty well as long as topic is a single word and not too specific.
device = "cuda:0"
tokenizer = AutoTokenizer.from_pretrained("ktrapeznikov/gpt2-medium-topic-small-set")
model = AutoModelWithLMHead.from_pretrained("ktrapeznikov/gpt2-medium-topic-small-set")
model.to(device)
topic = "climate"
prompt = tokenizer(f"topic {topics} source straitstimes title", return_tensors="pt")
out = model.generate(prompt["input_ids"].to(device), do_sample=True,max_length=500, early_stopping=True, top_p=.9)
print(tokenizer.decode(out[0].cpu(), skip_special_tokens=True))
- Downloads last month
- 13