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)
  • 输出结果
相关推荐
龙的爹23332 小时前
论文 | Model-tuning Via Prompts Makes NLP Models Adversarially Robust
人工智能·gpt·深度学习·语言模型·自然语言处理·prompt
龙的爹23336 小时前
论文翻译 | Generated Knowledge Prompting for Commonsense Reasoning
人工智能·gpt·机器学习·语言模型·自然语言处理·nlp·prompt
龙的爹23336 小时前
论文翻译 | Model-tuning Via Prompts Makes NLP Models Adversarially Robust
人工智能·gpt·语言模型·自然语言处理·nlp·prompt
玄奕子10 小时前
GPT对话知识库——在STM32的平台下,通过SPI读取和写入Flash的步骤。
stm32·单片机·gpt·嵌入式·嵌入式驱动
龙的爹23331 天前
论文翻译 | LLaMA-Adapter :具有零初始化注意的语言模型的有效微调
人工智能·gpt·语言模型·自然语言处理·nlp·prompt·llama
罗曼蒂克在消亡1 天前
github项目——gpt-pilot自动创建应用
gpt·github·github项目
wgggfiy2 天前
chatgpt学术科研prompt模板有哪些?chatgpt的学术prompt有哪些?学术gpt,学术科研
论文阅读·人工智能·gpt·chatgpt·prompt·aigc
Ephemeroptera2 天前
通过python-api使用openai的gpt
人工智能·python·gpt
DC10202 天前
GPT 的工作原理:深入解析
java·开发语言·gpt
BIGSHU09233 天前
GPT带我学-设计模式16-原型模式
gpt·设计模式·原型模式