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)
  • 输出结果
相关推荐
赞奇科技Xsuperzone16 小时前
DGX Spark 实战解析:模型选择与效率优化全指南
大数据·人工智能·gpt·spark·nvidia
CV-杨帆3 天前
博客阅读:chatgpt 2025 GPT-5 Jailbreak with Echo Chamber and Storytelling
gpt·chatgpt
2401_841495643 天前
【自然语言处理】轻量版生成式语言模型GPT
人工智能·python·gpt·深度学习·语言模型·自然语言处理·transformer
你的人类朋友4 天前
AI领域常见概念一览
gpt·ai编程·trae
wwlsm_zql5 天前
微软Copilot+企业版亮相:GPT-5赋能,效率激增47%,多模态操控金融级安全
人工智能·gpt·microsoft·copilot
DisonTangor6 天前
OpenAI开源gpt-oss-safeguard-120b和gpt-oss-safeguard-20b
人工智能·gpt·语言模型·开源·aigc
Baihai IDP6 天前
对 GPT 5 模型路由机制的深度解析
人工智能·gpt·ai·大模型·llms
七宝大爷6 天前
从 “你好 Siri” 到 “你好 GPT”:语言模型如何改变对话?
人工智能·gpt·语言模型
山山而川 潺潺如镜6 天前
chatgpt崩溃了,gpt怎么了
gpt
迪三达7 天前
GPT-0: Attention+Transformer+可视化
gpt·深度学习·transformer