当前位置:   article > 正文

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

textgenerationstreamresponse

默认使用的模型是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"))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/828632
推荐阅读
相关标签
  

闽ICP备14008679号