Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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}]
like image 363
Nithin Reddy Avatar asked Sep 04 '25 01:09

Nithin Reddy


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')
like image 185
cronoik Avatar answered Sep 07 '25 18:09

cronoik