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 小时前
猫头虎 AI工具分享:一个网页抓取、结构化数据提取、网页爬取、浏览器自动化操作工具:Hyperbrowser MCP
运维·人工智能·gpt·开源·自动化·文心一言·ai编程
北京地铁1号线3 小时前
GPT-2论文阅读:Language Models are Unsupervised Multitask Learners
论文阅读·gpt·语言模型
前端小盆友1 天前
从零实现一个GPT 【React + Express】--- 【2】实现对话流和停止生成
前端·gpt·react.js
牛大了202311 天前
【LLM学习】2-简短学习BERT、GPT主流大模型
gpt·学习·bert
1213411 天前
LLM:重构数字世界的“智能操作系统”
gpt·aigc·ai编程·llama·gpu算力
叠叠乐17 天前
ROS2编译的理解,与GPT对话
gpt
蚂蚁数据AntData19 天前
DB-GPT V0.7.2 版本更新:图表组件可视化增强、支持混合搜索 、支持DeepSeek-R1-0528模型等
大数据·数据库·gpt·架构·数据库架构
PacosonSWJTU22 天前
加载GPT-2模型参数报错:TensorFlow不存在
人工智能·gpt·tensorflow
zm-v-1593043398624 天前
GPT-ArcGIS 在生态评价中的综合应用:多因子权重分析与适宜性制图
gpt·arcgis
激进小猪100225 天前
LLM基础5_从零开始实现 GPT 模型
gpt