Instructions to use cambridgeltl/simctg_writingprompts with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use cambridgeltl/simctg_writingprompts with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="cambridgeltl/simctg_writingprompts")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("cambridgeltl/simctg_writingprompts") model = AutoModelForCausalLM.from_pretrained("cambridgeltl/simctg_writingprompts") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use cambridgeltl/simctg_writingprompts with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "cambridgeltl/simctg_writingprompts" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "cambridgeltl/simctg_writingprompts", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/cambridgeltl/simctg_writingprompts
- SGLang
How to use cambridgeltl/simctg_writingprompts 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 "cambridgeltl/simctg_writingprompts" \ --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": "cambridgeltl/simctg_writingprompts", "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 "cambridgeltl/simctg_writingprompts" \ --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": "cambridgeltl/simctg_writingprompts", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use cambridgeltl/simctg_writingprompts with Docker Model Runner:
docker model run hf.co/cambridgeltl/simctg_writingprompts
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
This model provides a GPT-2 language model trained with SimCTG on the WritingPrompts benchmark (Fan et al., 2018) based on our paper A Contrastive Framework for Neural Text Generation.
We provide a detailed tutorial on how to apply SimCTG and Contrastive Search in our project repo. In the following, we illustrate a brief tutorial on how to use our approach to perform text generation.
1. Installation of SimCTG:
pip install simctg --upgrade
2. Initialize SimCTG Model:
import torch
# load SimCTG language model
from simctg.simctggpt import SimCTGGPT
model_name = r'cambridgeltl/simctg_writingprompts'
model = SimCTGGPT(model_name)
model.eval()
tokenizer = model.tokenizer
3. Prepare the Text Prefix:
prefix_text = r"[ WP ] A kid doodling in a math class accidentally creates the world 's first functional magic circle in centuries . <|endoftext|>"
print ('Prefix is: {}'.format(prefix_text))
tokens = tokenizer.tokenize(prefix_text)
input_ids = tokenizer.convert_tokens_to_ids(tokens)
input_ids = torch.LongTensor(input_ids).view(1,-1)
4. Generate Text with Contrastive Search:
beam_width, alpha, decoding_len = 5, 0.6, 200
output = model.fast_contrastive_search(input_ids=input_ids, beam_width=beam_width,
alpha=alpha, decoding_len=decoding_len)
print("Output:\n" + 100 * '-')
print(tokenizer.decode(output))
'''
Prefix is: [ WP ] A kid doodling in a math class accidentally creates the world 's first functional magic circle in centuries . <|endoftext|>
Output:
----------------------------------------------------------------------------------------------------
[ WP ] A kid doodling in a math class accidentally creates the world's first functional magic circle in centuries. <|endoftext|> I looked at
the circle, it wasn't there. I couldn't see it, and my eyes were watering from the rain that had fallen over the school, the wind howling through
the windows and making a wispy noise as it passed through the air. `` What is it? '' I asked, trying to find the source of the noise. `` It's a
circle, '' the teacher said in a voice that sounded like it was from an old TV show or something like that. `` You can't make it out of there. ''
I looked around the room, there was no one there. It was as if I was in a dream, but no one seemed to notice me. Then I saw a flash of light, and
the circle appeared in front of me. I turned around to see what was going on, I had never seen anything like it before in my life. I ran up to the
teacher and asked, `` Are you sure this is real?
'''
For more details of our work, please refer to our main project repo.
5. Citation:
If you find our paper and resources useful, please kindly leave a star and cite our paper. Thanks!
@article{su2022contrastive,
title={A Contrastive Framework for Neural Text Generation},
author={Su, Yixuan and Lan, Tian and Wang, Yan and Yogatama, Dani and Kong, Lingpeng and Collier, Nigel},
journal={arXiv preprint arXiv:2202.06417},
year={2022}
}
- Downloads last month
- 17