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)
  • 输出结果
相关推荐
.Bryce.18 小时前
你了解 Blackboard(黑板系统)吗?听说过基于黑板系统实现的智能体吗?
java·网络·gpt·php·agent·codex·黑板系统
zoutao983 天前
GPT-6 Luna 批量处理实战指南
gpt·ai写作
Web3&Basketball3 天前
决策模型vs GPT-5实测:便宜400倍
人工智能·python·gpt·大模型·ai落地·推理优化·决策模型
Jay_帅小伙3 天前
免费GPT
gpt
空堂与归4 天前
Gemini 4 Argon 发布:物理推理模型控机器人?
人工智能·gpt·ui·ai·机器人
西索斯coding5 天前
gpt-5.6-sol 接入 LobeChat 保姆级教程:endpoint 路径确认 + model 枚举填错会静默回退 gpt-5.5,收藏这篇就够了
gpt·ai
小草cys5 天前
用 GPT 直接生成可编辑 PPTX 的实操记录,artifact-tool是OpenAICodex环境专用
gpt·算法·pptx
jerryinwuhan5 天前
从GPT到Agent:下一代人工智能系统架构演进
人工智能·gpt·系统架构
嫂子开门我是_我哥5 天前
GPT辅助大数据类科研感悟
论文阅读·gpt·论文笔记