How to download hugging face sentiment-analysis pipeline to use it offline?

Viewed 1217

How to download hugging face sentiment-analysis pipeline to use it offline? I'm unable to use hugging face sentiment analysis pipeline without internet. How to download that pipeline?

The basic code for sentiment analysis using hugging face is

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.')

And the output is

[{'label': 'POSITIVE', 'score': 0.9997795224189758}]
1 Answers

Use the save_pretrained() method to save the configs, model weights and vocabulary:

classifier.save_pretrained('/some/directory')  

and load it by specifying the tokenizer and model parameter:

from transformers import pipeline

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