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)
  • 输出结果
相关推荐
向量引擎1 天前
告别多源向量API适配噩梦:一套通用中转层的设计与实践
人工智能·gpt·aigc·agi·api调用
向量引擎1 天前
向量引擎API中转站深度测评:如何实现低成本、高并发的向量检索
人工智能·gpt·aigc·api·ai编程
向量引擎1 天前
当搜索开始替人整理答案:我重新理解了向量检索和 API 中间层
人工智能·gpt·aigc·ai编程·ai写作·key·agi
小楼v1 天前
本周AI圈炸了(4.13 - 4.19):AI纳入教师资格考核、GPT-6来了、Claude反杀、机器人跑赢了人类
人工智能·gpt·ai·机器人·热点资讯·教资·opus 4.7
向量引擎1 天前
向量引擎技术文档给我的创作启发:AI搜索生态下的内容适配实践
人工智能·gpt·ai编程·ai写作·key
Arenaschi1 天前
关于GPT的版特点
java·网络·人工智能·windows·python·gpt
程序大视界1 天前
Google I/O 2026 全解析:Gemini 3.5 Flash 免费用、4倍速碾压 GPT-5.5,AI 迎来“Agent 时代“
人工智能·gpt
captain_AIouo1 天前
攻克行业技术痛点,GPT Image2重塑电商AI生图标准
大数据·人工智能·经验分享·gpt·aigc
xcLeigh2 天前
聚合AI工具KULAAI:GPT、Claude、Gemini、DeepSeek热门模型一键使用
人工智能·gpt·claude·gemini·deepseek·聚合ai·kulaai
m0_535817552 天前
macOS上Claude Code安装配置保姆级教程:国内直连API,从0到1跑通(附避坑指南)
gpt·macos·ai·node.js·claude·claudecode·88api