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)
  • 输出结果
相关推荐
量子位1 小时前
Nano Banana新玩法无限套娃!“GPT-5都不会处理这种级别的递归”
人工智能·gpt
AIBox36516 小时前
国内可用 ChatGPT 中文版网站推荐(2025年11月最新)
人工智能·gpt·chatgpt
Ma0407131 天前
GPT:生成式预训练变形金刚
gpt
极客BIM工作室3 天前
从Transformer的Encoder与Decoder,到BERT和GPT的独立王国
gpt·bert·transformer
倔强的石头1067 天前
AiOnly大模型深度测评:调用GPT-5 API+RAG知识库,快速构建智能客服机器人
人工智能·gpt·机器人·aionly
boring_1117 天前
KubeFlow
gpt
智算菩萨7 天前
2025年通用大语言模型前沿进展评测:GPT-5.1、Claude 4.5、文心一言5.0 等全面解析
gpt·语言模型·文心一言
智慧地球(AI·Earth)9 天前
GPT-5.1发布!你的AI更暖更智能!
人工智能·gpt·神经网络·aigc·agi
盼小辉丶10 天前
PyTorch实战(10)——从零开始实现GPT模型
人工智能·pytorch·gpt·深度学习
Constantine3711 天前
GPT-5.1已上线!亲测国内可用,保姆级使用教程
gpt