huggingface-transformers 快速上手demo 官网pipeline例程使用方法 20230328

这个文章主要是对官网例程的一个补充。2023.03.28最新,别看更老的文章了,官网日新月异,老的文章会误导你

官网教程:

https://huggingface.co/course/zh-CN/chapter1/3?fw=pt

官网安装:

https://huggingface.co/course/zh-CN/chapter0/1?fw=pt

 

官网教程有一处必须指出:否则新手会困惑!看这个教程的肯定是新手啊。

from transformers import pipeline

classifier = pipeline("sentiment-analysis")
classifier("I've been waiting for a HuggingFace course my whole life.")

 

这不算一个完整程序,因为没有打印输出!  你要手动print一下结果才行 

 

from transformers import pipeline

classifier = pipeline("sentiment-analysis")
print(classifier("I've been waiting for a HuggingFace course my whole life."))

 

classifier 的返回值要print,你才能看到官网展示的输出!

[{'label': 'POSITIVE', 'score': 0.9598048329353333}]

你也许还会看到这个打印:

No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english and revision af0f99b (https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english).
Using a pipeline without specifying a model name and revision in production is not recommended.

 

posted @ 2023-03-28 23:27  园友1683564  阅读(316)  评论(0编辑  收藏  举报