ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

使用huggingface的pipeline进行文本生成Text Generation

使用huggingface的pipeline进行文本生成Text Generation

默认使用的模型是gpt2,会下载到本地的~/.cache/huggingface/目录下,
第一次运行会自动下载,第二次运行直接从本地加载,
可以尝试断网之后运行,也一样的会出结果.

先安装以下:

pip install huggingface_hub

pip install transformers

pip install --upgrade pip

pip install tensorflow

from transformers import pipeline
from huggingface_hub.hf_api import HfFolder
HfFolder.save_token('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')
pipe = pipeline("text-generation", num_return_sequences=2)
print(pipe("In this course, we will teach you how to"))
返回列表