Unable to load model offline
I downloaded the model files using git lfs and pointed AutoConfig to the model file and tokenizer to JSON.
However, when I run the code I get the below error -
File "/home/harshad/.cache/pypoetry/virtualenvs/tgeb2c-1dT1tncl-py3.10/lib/python3.10/site-packages/transformers/configuration_utils.py", line 652, in _get_config_dict
raise EnvironmentError(
OSError: It looks like the config file at 'roberta/pytorch_model.bin' is not a valid JSON file.
Directory:
-project-app-folder
-main.py
-roberta
-.bin
-.json
Code:
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
Load model & tokenizer
roberta_model = AutoModelForQuestionAnswering.from_pretrained('roberta/pytorch_model.bin')
roberta_tokenizer = AutoTokenizer.from_pretrained('roberta/tokenizer_config.json')
nlp = pipeline("question-answering", model=roberta_model, tokenizer=roberta_tokenizer)
QA_input = {"question": question, "context": context}
res = nlp(QA_input)
Hi @hb0313 thanks for your interest in downloading our model! I think you need to make a slight modification to your loading code. I believe AutoModelForQuestionAnswering.from_pretrained()
and AutoTokenizer.from_pretrained()
expect the directory containing the model and not the .bin
and .json
files.
So your code might look something like this:
roberta_model = AutoModelForQuestionAnswering.from_pretrained('directory_containing_model/')
roberta_tokenizer = AutoTokenizer.from_pretrained('directory_containing_model/')
You can find more information on how AutoModelForQuestionAnswering.from_pretrained()
works in HF's docs: https://huggingface.co/transformers/v3.0.2/model_doc/auto.html#transformers.AutoModelForQuestionAnswering.from_pretrained