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)
  • 输出结果
相关推荐
哪吒编程4 小时前
如何用好 Codex?OpenAI 内部最佳实践指南:8 个最佳应用场景
gpt·openai
viperrrrrrrrrr73 天前
GPT系列模型-详解
人工智能·gpt·llm
2401_841495643 天前
预训练基础模型简介
gpt·语言模型·自然语言处理·bert·transformer·大语言模型·预训练
Skrrapper6 天前
GPT‑5 都更新了些什么?
gpt
三天哥8 天前
Sora 2为什么会火?
人工智能·gpt·ai·aigc·agi·ai视频·sora
. . . . .8 天前
GPT的前世今生及发展
人工智能·gpt
丁学文武8 天前
大模型原理与实践:第三章-预训练语言模型详解_第3部分-Decoder-Only(GPT、LLama、GLM)
人工智能·gpt·语言模型·自然语言处理·大模型·llama·glm
带娃的IT创业者8 天前
第2集:技术选型的智慧:Flask vs FastAPI,GLM-4 vs GPT
python·gpt·flask·fastapi·glm·技术选型
小森( ﹡ˆoˆ﹡ )9 天前
GPT_Data_Processing_Tutorial
数据库·gpt·mysql
眰恦ゞLYF9 天前
嵌入式硬件——基于IMX6ULL的GPT(通用定时器)实现
单片机·嵌入式硬件·gpt·imx6ull