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)
  • 输出结果
相关推荐
JJJennie7773 小时前
GPT-6 Astra 发布,Astra 和 Fable5.1对比,模型开始学会在陌生环境中自己找规则
gpt·评测对比
嘿嘿-664 小时前
Windows 一键使用 GPT-6 Astra:Codex CLI 配置教程
java·人工智能·windows·gpt·chatgpt·web
m0_380743876 小时前
给 OpenAI API 调用加上模型切换:GPT-5.1 和 Codex 的配置实践
人工智能·python·gpt
嘿嘿-6611 小时前
gpt-6-astra测试,测试你的模型有没有降智
人工智能·gpt·chatgpt·web
短视频矩阵源码定制12 小时前
GPT Image 2.0实战指南:从0到1构建合规稳定的AI服务接入方案
人工智能·gpt
梦想的颜色13 小时前
【AI速览】GPT‑6 Astra 硬核深度解析:不是噱头 AGI,而是面向端到端 Agent 工作流的前沿旗舰
gpt·大模型·openai·agent·deepseek·gpt6‑astra·大模型横评
外域速览14 小时前
GPT-6 Astra 开放、标普罕见拉响 AI 基建信用警报、三星 Arm 联手 2nm 端侧芯片:算力下半场的三条主线
arm开发·人工智能·gpt
梦想的颜色16 小时前
2026 年 9 月国内外主流大模型横向硬核评测:价格、算力、业务场景全维度对比,GPT‑6 Astra横空出世
gpt·claude·glm·minimax·kimi·deepseek·大模型测评