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)
  • 输出结果
相关推荐
BJ_Kingfisher15 小时前
GPT Image 2.5 到底改了什么:一个单模型拆成了两条道
大数据·科技·gpt
ServBay1 天前
ChatGPT Pro 20X 限时回归
gpt·chatgpt·openai
码狂☆2 天前
GPT-6 Astra 上线 Codex:1.4 折接入教程
人工智能·gpt
tiger8652 天前
大语言模型面试和题解,梳理中国主流开源 LLM 系列的发展脉络、技术路线与工程取舍
人工智能·gpt·深度学习·算法·自然语言处理·面试·transformer
技术程序猿华锋3 天前
深度解析 GPT-Image-2.5:双架构模型演进、获取API 接入与工程化开发教程
人工智能·gpt
西索斯coding4 天前
GPT-5.6-Luna 接入 Cline 教程:base_url 配置、max_tokens 上限与 ZDR 请求头写法
大数据·人工智能·gpt·ai
whyfail5 天前
开发平替实录:ZCode + 火山 Coding Plan + GLM-5.3-Flash,打不过 GPT-5.6-Sol,但只差一口气的成本
gpt·codex·glm·智谱·zcode
沉默王二5 天前
Codex 最新焚决发布,快!
gpt·agent·ai编程
技灵AI5 天前
ChatGPT Images 2.5 深度解读:延迟减半、Sketch 草图与 Flare/Sunburst 双模型 API
人工智能·gpt·aigc·音视频·images2.5
程序员无隅6 天前
Harness Learn Engineering :用初始化、交接记录与恢复验证,让 Coding Agent 换个会话也能接着干
gpt·ai