Instructions to use ktrapeznikov/gpt2-medium-topic-news with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ktrapeznikov/gpt2-medium-topic-news with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ktrapeznikov/gpt2-medium-topic-news")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ktrapeznikov/gpt2-medium-topic-news") model = AutoModelForCausalLM.from_pretrained("ktrapeznikov/gpt2-medium-topic-news") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use ktrapeznikov/gpt2-medium-topic-news 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" # 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", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ktrapeznikov/gpt2-medium-topic-news
- SGLang
How to use ktrapeznikov/gpt2-medium-topic-news 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" \ --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", "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" \ --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", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ktrapeznikov/gpt2-medium-topic-news with Docker Model Runner:
docker model run hf.co/ktrapeznikov/gpt2-medium-topic-news
GPT2-medium-topic-news
Model description
GPT2-medium fine tuned on a large news corpus conditioned on a topic
Intended uses & limitations
How to use
To generate a news article text conditioned on a topic, prompt model with:
topic: climate article:
The following tags were used during training:
arts law international science business politics disaster world conflict football sport sports artanddesign environment music film lifeandstyle business health commentisfree books technology media education politics travel stage uk society us money culture religion science news tv fashion uk australia cities global childrens sustainable global voluntary housing law local healthcare theguardian
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-news")
model = AutoModelWithLMHead.from_pretrained("ktrapeznikov/gpt2-medium-topic-news")
model.to(device)
topic = "climate"
prompt = tokenizer(f"topic: {topic} article:", 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(list(out.cpu()[0])))
Training data
Training procedure
- Downloads last month
- 9