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)
  • 输出结果
相关推荐
Swift社区1 小时前
最强生图模型NanoBanana 2,一手深度测- 附教程
gpt·claude·gemini
智算菩萨11 小时前
ChatGPT等AI工具辅助学术论文写作全流程:从选题、润色到降重的实战指南
论文阅读·gpt·ai·语言模型·ai写作
balmtv11 小时前
GPT技术架构深度拆解:从Transformer到GPT-5.4的演进之路
gpt·架构·transformer
chian-ocean14 小时前
一个插件,免费用NanoBanana 2+GPT 5.4
gpt
智算菩萨14 小时前
GPT-5.4的“慢思考“艺术:详解推理时计算(Inference-Time Compute)如何重塑复杂任务解决能力
人工智能·gpt·ai·chatgpt
放下华子我只抽RuiKe51 天前
机器学习全景指南-直觉篇——基于距离的 K-近邻 (KNN) 算法
人工智能·gpt·算法·机器学习·语言模型·chatgpt·ai编程
White-Legend1 天前
免费额度每日20刀Codex GPT 5.4分享
gpt·ai编程
海天一色y1 天前
从 GPT 到 GPT-2:解密生成式预训练模型的架构演进
gpt
白狐_7982 天前
2026 避坑指南:GPT-5.4 Codex、OpenClaw 与订阅版本全解析
gpt·自动化代理
智算菩萨2 天前
GPT-5.4原生操控电脑揭秘:从Playwright脚本到屏幕截图识别,手把手搭建你的第一个自动化智能体
人工智能·gpt·ai·chatgpt·自动化