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)
  • 输出结果
相关推荐
前端小盆友6 小时前
从零实现一个GPT 【React + Express】--- 【3】解析markdown,处理模型记忆
gpt·react.js
资讯分享周1 天前
Alpha系统联结大数据、GPT两大功能,助力律所管理降本增效
大数据·gpt
猫头虎2 天前
猫头虎 AI工具分享:一个网页抓取、结构化数据提取、网页爬取、浏览器自动化操作工具:Hyperbrowser MCP
运维·人工智能·gpt·开源·自动化·文心一言·ai编程
北京地铁1号线2 天前
GPT-2论文阅读:Language Models are Unsupervised Multitask Learners
论文阅读·gpt·语言模型
前端小盆友3 天前
从零实现一个GPT 【React + Express】--- 【2】实现对话流和停止生成
前端·gpt·react.js
牛大了202313 天前
【LLM学习】2-简短学习BERT、GPT主流大模型
gpt·学习·bert
1213413 天前
LLM:重构数字世界的“智能操作系统”
gpt·aigc·ai编程·llama·gpu算力
叠叠乐19 天前
ROS2编译的理解,与GPT对话
gpt
蚂蚁数据AntData21 天前
DB-GPT V0.7.2 版本更新:图表组件可视化增强、支持混合搜索 、支持DeepSeek-R1-0528模型等
大数据·数据库·gpt·架构·数据库架构
PacosonSWJTU24 天前
加载GPT-2模型参数报错:TensorFlow不存在
人工智能·gpt·tensorflow