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 小时前
我用AI做了个微信小游戏-上线了
gpt·ai编程·gemini
ofoxcoding5 小时前
2026 轻量模型 API 实测:GPT-5.5 Nano、Gemini 3.1 Flash、Haiku 4.5 延迟与成本横评
运维·gpt·ai
@大迁世界11 小时前
GPT-5.5 和 Opus 4.7,到底该用谁?
gpt
码农阿强11 小时前
GPT-5.5 与 GPT-5.5-Pro 技术差异及接口接入实践
人工智能·gpt·ai·aigc·ai编程·ai写作·gpu算力
2601_9577875511 小时前
基于 4SAPI 的 GPT-Codex 本地部署与全功能配置实战教程
人工智能·gpt·ai编程·ai应用开发
crossoverJie1 天前
OpenAI 三连发:GPT-5.5、Codex移动端、DeployCo,AI编程进入新阶段
人工智能·gpt·ai编程
yaodong5181 天前
多模态处理能力:GPT-5.5 vs Grok4
gpt
~黄夫人~1 天前
常见AI专有名词解释(用公司管理的方式理解 AI 世界)
人工智能·gpt·ai
应用市场2 天前
Android分区表深度解析:GPT、各分区作用与布局实战
android·gpt
Resistance丶未来2 天前
【手把手详细教程】 Trae AI和Vscode~使用第三方中转API配置Claude ,GPT,Gemini等大模型教程
人工智能·gpt