如何下载拥抱脸情感分析管道以离线使用?

问题描述 投票:0回答: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}]
deep-learning nlp huggingface-transformers huggingface-tokenizers
2个回答
3
投票

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

classifier.save_pretrained('/some/directory')  

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

from transformers import pipeline

c2 = pipeline(task = 'sentiment-analysis', model='/some/directory', tokenizer='/some/directory')

0
投票

这是另一种处理方法:

import os
from transformers import pipeline

if os.path.isdir('hf_cache/'):
    summarizer = pipeline(task='sentiment-analysis',
                          model_kwargs={"cache_dir": 'hf_cache/', 'local_files_only': True})
else:
    summarizer = pipeline(task='sentiment-analysis',
                          model_kwargs={"cache_dir": 'hf_cache/', 'force_download': True})

查看 from_pretrained 参数。

© www.soinside.com 2019 - 2024. All rights reserved.