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)
  • 输出结果
相关推荐
询问QQ:180809513 小时前
复现ICRA 2022自动驾驶实时轨迹规划:速度路径解耦方法研究,基于Linux系统ROS的场...
gpt
桂花饼7 小时前
GPT-5.1-Codex-Max 架构深度解析:原生“压缩”机制如何重塑智能体编程?
gpt·aigc·ai编程·大模型实战·gemini 3 pro·claude opus 4.5·gpt-5.1max
桂花饼1 天前
GPT-5.1-Codex-Max:原生“记忆压缩”重塑编程范式,让 AI 连续写代码 24 小时不再是梦
人工智能·gpt·ai绘图·nano banana 2·图像生成api·openai兼容接口·gpt-5.1-codex
陈 洪 伟2 天前
Transformer彻底剖析(1):GPT中的Transformer架构
gpt·深度学习·transformer
zxcxylong3 天前
almalinux系统-数据盘扩容后文件系统扩容步骤
gpt·almalinux·parted·lvm·/dev/sdb
hay_lee3 天前
DeepSeek发布V3.2系列模型,性能媲美GPT-5与Gemini
gpt
生信大表哥4 天前
GPT-5-Codex VS Gemini 3 VS Claude Sonnet 4.5 新手小白入门学习教程
人工智能·gpt·学习·rstudio·数信院生信服务器
致Great6 天前
DeepSeek-V3.2技术报告解读:开源大模型的逆袭之战——如何用10%算力追平GPT-5
人工智能·gpt·开源·大模型·agent·智能体
黑客思维者6 天前
重塑信任与效率:Salesforce Einstein GPT 客服体系深度案例研究
人工智能·gpt·llm·客服系统·salesforce
*星星之火*7 天前
【大白话 AI 答疑】第2篇 GPT 全系列发展历程:从 GPT-1 到 GPT-5,每一代的关键突破都在这!
gpt