EricFillion / happy-transformer

Happy Transformer makes it easy to fine-tune and perform inference with NLP Transformer models.
http://happytransformer.com
Apache License 2.0
515 stars 66 forks source link

OSError: Unable to load weights from pytorch checkpoint file for 'SentiApp/models/DISTILBERT_sentence/' at 'SentiApp/models/DISTILBERT_sentence/pytorch_model.bin'If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True. #255

Closed Y4rd13 closed 2 years ago

Y4rd13 commented 3 years ago

@EricFillion I am getting an error that a few days ago I did not have, this happens when I try to load the model that I have saved.

Traceback

  File "/home/ubuntu/IS-API/SentiApp/DISTILBERT_sentence_predictor.py", line 14, in <module>
    happy_tc = HappyTextClassification(load_path=model_path, num_labels=10)
  File "/home/ubuntu/IS-API/env/lib/python3.8/site-packages/happytransformer/happy_text_classification.py", line 34, in __init__
    model = AutoModelForSequenceClassification.from_pretrained(load_path, config=config)
  File "/home/ubuntu/IS-API/env/lib/python3.8/site-packages/transformers/models/auto/auto_factory.py", line 384, in from_pretrained
    return model_class.from_pretrained(pretrained_model_name_or_path, *model_args, config=config, **kwargs)
  File "/home/ubuntu/IS-API/env/lib/python3.8/site-packages/transformers/modeling_utils.py", line 1285, in from_pretrained
    raise OSError(
OSError: Unable to load weights from pytorch checkpoint file for 'SentiApp/models/DISTILBERT_sentence/' at 'SentiApp/models/DISTILBERT_sentence/pytorch_model.bin'If you tried to load a PyTorch model from a TF 2.0 checkpoint, please
 set from_tf=True.

Code where the error is happening

model_path = 'SentiApp/models/DISTILBERT_sentence/'
transformer_finbert_polarity = HappyTextClassification(model_type='BERT', model_name='ProsusAI/finbert', num_labels=3)

happy_tc = HappyTextClassification(load_path=model_path, num_labels=10) # line 14
EricFillion commented 3 years ago

It appears that not all of your code is shown. Please include code on how you saved the model if you're still experiencing this issue.