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)
  • 输出结果
相关推荐
nju_spy2 小时前
GPT 系列论文1-2 两阶段半监督 + zero-shot prompt
人工智能·gpt·nlp·大语言模型·zero-shot·transformer架构·半监督训练
*星星之火*4 小时前
【GPT入门】第67课 多模态模型实践: 本地部署文生视频模型和图片推理模型
gpt
技术程序猿华锋4 小时前
深度解码OpenAI的2025野心:Codex重生与GPT-5 APIKey获取调用示例
人工智能·vscode·python·gpt·深度学习·编辑器
钝挫力PROGRAMER17 小时前
GPT与BERT BGE
人工智能·gpt·bert
edisao2 天前
[特殊字符] 从助手到引擎:基于 GPT 的战略协作系统演示
大数据·人工智能·gpt
陈敬雷-充电了么-CEO兼CTO2 天前
BLIP-2革新多模态预训练:QFormer桥接视觉语言,零样本任务性能飙升10.7%!
人工智能·gpt·机器学习·机器人·多模态·blip·多模态大模型
安思派Anspire3 天前
GPT-OSS 深度解析:OpenAI 最新大语言模型(LLM)架构
gpt·语言模型·架构
AIGC小火龙果4 天前
OpenAI的开源王牌:gpt-oss上手指南与深度解析
人工智能·经验分享·gpt·搜索引擎·aigc·ai编程
*星星之火*4 天前
【GPT入门】第66 课 llamaIndex调用远程llm模型与embedding模型的方法
gpt·embedding
golang学习记4 天前
Claude Code 平替:OpenAI发布 Codex CLI ,GPT-5 国内直接使用
gpt