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)
  • 输出结果
相关推荐
智慧地球(AI·Earth)2 天前
GPT-5.1发布!你的AI更暖更智能!
人工智能·gpt·神经网络·aigc·agi
盼小辉丶3 天前
PyTorch实战(10)——从零开始实现GPT模型
人工智能·pytorch·gpt·深度学习
Constantine374 天前
GPT-5.1已上线!亲测国内可用,保姆级使用教程
gpt
FreeBuf_4 天前
攻击者利用自定义GPT的SSRF漏洞窃取ChatGPT机密数据
gpt·chatgpt
yaocheng的ai分身4 天前
【转载】 OpenAI 推出 GPT-5.1:面向开发者的智能模型
gpt·chatgpt
AI探知-阿薇4 天前
GPT-5.1发布:深入解读与 GPT-5、GPT-4o 在性能与安全基准上的全面对比
gpt·安全
illuspas6 天前
MI50运算卡使用llama.cpp的ROCm后端运行gpt-oss-20b的速度测试
人工智能·gpt·llama
TGITCIC7 天前
开源模型登顶?Kimi K2 Thinking 实测解析:它真能超越 GPT-5 吗?
gpt·ai大模型·开源大模型·kimi·月之暗面·大模型ai·国产大模型
金木讲编程9 天前
如何创建“国学助手”GPT?
gpt·ai编程
少林码僧9 天前
2.3 Transformer 变体与扩展:BERT、GPT 与多模态模型
人工智能·gpt·ai·大模型·bert·transformer·1024程序员节