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)
  • 输出结果
相关推荐
神奇霸王龙12 小时前
GPT-Image-2 角色一致性屠榜:2026 五款图生图模型 IP 漫剧实测
人工智能·gpt·tcp/ip·ai·ai作画·prompt·音视频
库拉大叔12 小时前
写小说谁家强?GPT-5.6、Claude 4.8 Opus、Gemini 3.5文学素养硬核横评
人工智能·gpt·aigc
OpenCSG1 天前
GPT-5.6 深夜正式上线:下一代模型能力升级,AI Agent 进入深度协作时代
人工智能·gpt
To_OC2 天前
还在追顶配模型?GPT 5.6 已经把玩法彻底改了
人工智能·gpt·llm
Days20502 天前
帮我在书本上画出了回忆中的学校-提示词
人工智能·gpt·ai作画·gpt-image
就是一顿骚操作2 天前
GPT-2 from scratch with torch:用 torch 从零实现 GPT-2
人工智能·gpt·transformer·论文解读·gpt-2
sugar__salt2 天前
Benchmark 与 GPT 5.6:大模型评测体系与 AI 工作方式的范式转移
人工智能·gpt
大鱼>2 天前
Whisper+GPT-SoVITS:语音识别到音色克隆的全链路实战
gpt·whisper·语音识别
库拉大叔3 天前
在盈彩AI使用GPT-Image-2:从入门到精通的完整指南
人工智能·gpt
吨吨ai3 天前
2026年7月更新:ChatGPT、Codex、Pro、Plus 背后的 AI Determinism 问题(GPT-5.6 工程化技术分享)
人工智能·gpt·chatgpt