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

文章目录

  • [下载 GPT-2 模型](#下载 GPT-2 模型)
  • [快速开始 GPT-2](#快速开始 GPT-2)

下载 GPT-2 模型

bash 复制代码
git clone https://huggingface.co/uer/gpt2-chinese-cluecorpussmall
# 或单独下载 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/uer/gpt2-chinese-cluecorpussmall

快速开始 GPT-2

  • 安装依赖
bash 复制代码
pip3 install torch torchvision torchaudio
pip3 install transformers
  • python脚本
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)
  • 输出结果
相关推荐
kyriewen2 天前
白宫前脚下了限制令,OpenAI 后脚就把 GPT-5.6 发了
前端·gpt·openai
AI工程效率栈4 天前
AI 帮你补异常处理时,新人最容易犯的错:把失败悄悄变成成功
gpt·chatgpt
AlfredZhao6 天前
GPT 省钱,不是别用最新模型,而是别浪费缓存
gpt·ai
newbe3652410 天前
对接 Reasonix 1.x 跑通 DeepSeek V4:ACP 模型选择器接入实战
gpt·claude·chatglm (智谱)
newbe3652411 天前
如何使用 Upptime 免费搭建自己的状态站点
gpt·claude·chatglm (智谱)
gis分享者12 天前
GPT-Image-2 图像生成模型新手实战指南
gpt·ai·image·模型·图像生成
Nayxxu12 天前
GPT 多模态 API 接入思路:文本、图片、音频请求怎么拆分
gpt