TheophileBlard / french-sentiment-analysis-with-bert

How good is BERT ? Comparing BERT to other state-of-the-art approaches on a French sentiment analysis dataset
MIT License
146 stars 35 forks source link

First steps .. #39

Open Guiraud opened 1 year ago

Guiraud commented 1 year ago

Hi I'm trying to use your transformer in one of my program. Saddly I have this error message :

Traceback (most recent call last):
  File "/home/mguiraud/Documents/text-analysis-pipeline/main.py", line 11, in <module>
    from text_analysis import perform_sentiment_analysis
  File "/home/user/Documents/text-analysis-pipeline/text_analysis.py", line 10, in <module>
    model = CamembertForSequenceClassification.from_pretrained('tblard/tf-allocine', num_labels=2)
  File "/home/user/Documents/text-analysis-pipeline/env/lib/python3.10/site-packages/transformers/modeling_utils.py", line 2535, in from_pretrained
    raise EnvironmentError(
OSError: tblard/tf-allocine does not appear to have a file named pytorch_model.bin but there is a file for TensorFlow weights. Use `from_tf=True` to load this model from

WHat should I do ?

TheophileBlard commented 1 year ago

Hi @Guiraud !

This model was trained with Tensorflow and does not have PyTorch compatible weights. By default, the CamembertForSequenceClassification.from_pretrained method seems to look for PyTorch weights. As suggested, you should use from_tf=True to force loading Tensorflow weights.

Or you could directly use the TFAutoModelForSequenceClassification.from_pretrained method, which is what I do in the colab example

I hope my answer clears you up !