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)
  • 输出结果
相关推荐
2501_945837437 小时前
OpenClaw:让AI从“能说”到“能做”的智能体革命
gpt
程序媛小鱼8 小时前
从预训练到Transformer到GPT
gpt·深度学习·bert·transformer
JavaPub-rodert10 小时前
2026年国内 Codex 安装教程和使用教程:GPT-5.4 完整指南
gpt·chatgpt·openai·codex·gpt5.4
柯儿的天空12 小时前
【OpenClaw 全面解析:从零到精通】第 019 篇:GoClaw 企业版——从开源到商业化的演进之路
gpt·开源·aigc·copilot·ai编程·ai写作·agi
智算菩萨15 小时前
ChatGPT在非洲主要国家教育中的应用:效益、接受度与伦理挑战——基于2022-2024年文献的系统综述精读
论文阅读·人工智能·gpt·深度学习·ai·chatgpt·论文笔记
柯儿的天空2 天前
【OpenClaw 全面解析:从零到精通】第007篇:流量枢纽——OpenClaw Gateway 网关深度解析
人工智能·gpt·ai作画·gateway·aigc·ai编程·ai写作
White-Legend2 天前
GPT5.4每日200刀
人工智能·gpt
华农DrLai2 天前
什么是Prompt模板?为什么标准化的格式能提高稳定性?
数据库·人工智能·gpt·nlp·prompt
晓晓不觉早2 天前
GPT-5.4 mini/nano 双炮登场:OpenAI 开启「模型编队」新时代
人工智能·gpt
2501_948114242 天前
OpenClaw 时代的多模型接入实战:当开源智能体遇上聚合网关,一个人如何跑通全自动生产流水线
人工智能·gpt·开源