Download ESG-BERT permanently

#4
by BMU - opened

I currently use ESG-BERT in the following way:

from transformers import pipeline
pl = pipeline("text-classification", model="nbroad/ESG-BERT", return_all_scores=True)
pl("This is the input text.")

As explained in https://huggingface.co./transformers/v4.10.1/quicktour.html: "When typing this command for the first time, a pretrained model and its tokenizer are downloaded and cached".

Now, I would like to download the model once and forever, so that I don't need to do it every time I use the model.
How can I do this?
Could I still access it using pipeline? How?

BMU changed discussion status to closed
BMU changed discussion status to open

Answer:

  1. Download files in https://huggingface.co./nbroad/ESG-BERT/tree/main into a directory into your local machine.
  2. You can still use pipeline. But "nbroad/ESG-BERT" should be substituted by the path to the directory where you saved the model files.

from transformers import pipeline
pl = pipeline("text-classification", model="path_to_directory_where_you_saved_the_model_files", return_all_scores=True)
pl("This is the input text.")

BMU changed discussion status to closed

Hi @BMU ,

It looks like you figured it out. For the future, it is probably easiest to do the following:

from transformers import pipeline
pl = pipeline("text-classification", model="nbroad/ESG-BERT", return_all_scores=True)
pl.save_pretrained('saved_pipeline')

Sign up or log in to comment