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)
  • 输出结果
相关推荐
狮子座明仔5 小时前
REDSearcher:如何用30B参数的小模型,在深度搜索上击败GPT-o3和Gemini?
人工智能·gpt·深度学习·microsoft·语言模型·自然语言处理
智算菩萨1 天前
2026年春节后,AI大模型格局彻底变了——Claude 4.6、GPT-5.2与六大国产模型全面横评
人工智能·gpt·ai编程
Learner__Q3 天前
GPT模型入门教程:从原理到实现
python·gpt
五月君_4 天前
除夕夜炸场!Qwen 3.5 正式发布:激活仅 17B,性能硬刚 GPT-5.2?
gpt
向量引擎小橙6 天前
视觉艺术的“奇点”:深度拆解 Gemini-3-Pro-Image-Preview 绘画模型,看这只“香蕉”如何重塑 AI 创作逻辑!
人工智能·python·gpt·深度学习·llama
阿乐艾官6 天前
【MBR与GPT分区】
gpt
相思半8 天前
告别聊天机器人!2026 智能体元年:Claude 4.6 vs GPT-5.3 vs OpenClaw 全方位对比
人工智能·gpt·深度学习·claude·codex·智能体·seedance
冬奇Lab8 天前
一天一个开源项目(第22篇):nanochat - 百元级「最好的 ChatGPT」,Karpathy 的极简 LLM 训练套件
人工智能·gpt·chatgpt
赛博鲁迅8 天前
dify添加中转站模型教程
人工智能·gpt·aigc·ai编程·dify·ai-native
向量引擎小橙8 天前
从“对话助手”到“数字架构师”:Claude 4.6 Opus 如何凭一己之力,终结全球程序员的“CRUD 焦虑”?
人工智能·python·gpt·深度学习