当前位置:   article > 正文

Mac 部署 GPT-2 预训练模型 gpt2-chinese-cluecorpussmall

gpt2-chinese-cluecorpussmall

下载 GPT-2 模型

在这里插入图片描述

git clone https://huggingface.co/uer/gpt2-chinese-cluecorpussmall
# 或单独下载 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/uer/gpt2-chinese-cluecorpussmall
  • 1
  • 2
  • 3

快速开始 GPT-2

  • 安装依赖
pip3 install torch torchvision torchaudio
pip3 install transformers
  • 1
  • 2
  • python脚本
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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 输出结果

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/713745
推荐阅读
相关标签
  

闽ICP备14008679号