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)
  • 输出结果
相关推荐
16Miku7 小时前
Claude KYC 认证避坑指南:从无法使用到顺利通关
gpt·claude·codex·kyc
Joshkhh7 小时前
2026年多模型AI使用指南:Gemini/Claude/GPT如何轻松上手?
人工智能·gpt
恒哥的爸爸8 小时前
GPT原理笔记
人工智能·笔记·gpt
2501_948114241 天前
2026 深度评测:Qwen 3.6-Plus 全模态逻辑链融合架构解析与高可用接入实践
人工智能·gpt·ai·架构·claude
xixixi777772 天前
从Mythos到GPT-5.4-Cyber:AI安全竞赛的“双轨”分化与防御新范式
网络·gpt·安全·机器学习·架构·大模型·claude
Aaron_Chou3132 天前
如何在Trae中配置Claude,gpt-5.4,deepseek等大模型的中转API
人工智能·gpt·claude·deepseek·cline·trae
2501_948114242 天前
2026旗舰模型四强争霸:GPT-5.4、Claude Opus 4.6、Gemini 3.1 Pro与Grok 4.20深度横评
人工智能·gpt·ai·谷歌
SiYuanFeng2 天前
一展使用gpt-5-mini和gemini-3.1-flash-image-preview-0.5k的运行demo代码
linux·python·gpt
come112342 天前
最新的 gpt 5.4 和 claude 4.7 模型为什么更好用
人工智能·gpt
ai大模型中转api测评2 天前
Claude Opus 4.7 深度拆解:自验证架构与 1M 上下文,全方位对标 GPT-5.4
人工智能·gpt·自动化·api