2

如何下载拥抱脸情绪分析管道以离线使用?我无法在没有互联网的情况下使用拥抱面部情绪分析管道。如何下载该管道?

使用拥抱脸进行情感分析的基本代码是

from transformers import pipeline
classifier = pipeline('sentiment-analysis') #This code will download the pipeline
classifier('We are very happy to show you the  Transformers library.')

输出是

[{'label': 'POSITIVE', 'score': 0.9997795224189758}]
4

1 回答 1

2

使用save_pretrained()方法保存配置、模型权重和词汇:

classifier.save_pretrained('/some/directory')  

并通过指定标记器和模型参数来加载它:

from transformers import pipeline

c2 = pipeline(task = 'sentiment-analysis', model='/some/directory', tokenizer='/some/directory')
于 2021-04-01T15:15:39.617 回答