使用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"))