下载 GPT-2 模型
- https://huggingface.co/uer/gpt2-chinese-cluecorpussmall
git clone https://huggingface.co/uer/gpt2-chinese-cluecorpussmall
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/uer/gpt2-chinese-cluecorpussmall
快速开始 GPT-2
pip3 install torch torchvision torchaudio
pip3 install transformers
from transformers import BertTokenizer, GPT2LMHeadModel, TextGenerationPipeline
tokenizer = BertTokenizer.from_pretrained("./gpt2-chinese-cluecorpussmall")
model = GPT2LMHeadModel.from_pretrained("./gpt2-chinese-cluecorpussmall")
text_generator = TextGenerationPipeline(model, tokenizer)
result = text_generator("这是很久之前的事情了", max_length=100, do_sample=True)
print(result)