# AttributeError: 'Flaubert For Sequence Classification' object has no attribute 'predict'

**URL:** <https://discuss.huggingface.co/t/attributeerror-flaubert-for-sequence-classification-object-has-no-attribute-predict/12927>\
**Category:** 🤗Transformers\
**Created:** [December 17, 2021, 3:04pm UTC](https://discuss.huggingface.co/t/attributeerror-flaubert-for-sequence-classification-object-has-no-attribute-predict/12927 "2021-12-17T15:04:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmakelo](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@emmakelo](https://discuss.huggingface.co/u/emmakelo)\
**Post date:** [December 17, 2021, 3:04pm UTC](https://discuss.huggingface.co/t/attributeerror-flaubert-for-sequence-classification-object-has-no-attribute-predict/12927/1 "2021-12-17T15:04:47Z")

</div>

I am trying to classify new dataset from best model after loading but I get this error:

```auto
best_model_from_training_testing = './checkpoint-900'
best_model= FlaubertForSequenceClassification.from_pretrained(best_model_from_training_testing, num_labels=3)

raw_pred, _, _ = best_model.predict(test_tokenized_dataset)         
predictedLabelOnCompanyData = np.argmax(raw_pred, axis=1)

```

```auto
Traceback (most recent call last):
  File "/16uw/test/MODULE_FMC/scriptTraitements/classifying.py", line 408, in <module>
    pred = predict(emb, test_model)
  File "/16uw/test/MODULE_FMC/scriptTraitements/classifying.py", line 279, in predict
    raw_pred, _, _ = model.predict(emb_feature)
  File "/l16uw/.conda/envs/bert/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1130, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'FlaubertForSequenceClassification' object has no attribute 'predict'

```

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [December 20, 2021, 1:51pm UTC](https://discuss.huggingface.co/t/attributeerror-flaubert-for-sequence-classification-object-has-no-attribute-predict/12927/2 "2021-12-20T13:51:53Z")

</div>

This model has no `predict` method indeed. Were you trying to use `Trainer.predict`?

---

<div class="post-metadata">

**Author:** ![emmakelo](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@emmakelo](https://discuss.huggingface.co/u/emmakelo)\
**Post date:** [December 20, 2021, 2:10pm UTC](https://discuss.huggingface.co/t/attributeerror-flaubert-for-sequence-classification-object-has-no-attribute-predict/12927/3 "2021-12-20T14:10:36Z")

</div>

Yes.Thank you, Actually I finetuned a model via training with the trainer and evaluate on a test data. Now I wanted to load my model and use it on realdata world and as I said the model output the same class for my realdata. I was wondering if I wrote the code correctly. The preprocessing/training/evaluating/testing and saving best model work but when I tried to load the model for inference on new data. The model output same class for every sentence in my dataset even when I tried with the test\_dataset I used to evaluate on. Could you help me, the model is supposed to be used by an app for professionnal usage.

```auto
best_model_from_training_testing = './checkpoint-900'
best_model= FlaubertForSequenceClassification.from_pretrained(best_model_from_training_testing, num_labels=3)
trainer = Trainer(best_model)
raw_pred, _, _ = trainer.predict(test_tokenized_dataset)         
predictedLabelOnCompanyData = np.argmax(raw_pred, axis=1)

run 1 : 1111111111111111111111111111
run2: 1111111111111111111111112222
run3: 333333333333333333333333

```

As you see the output keep changing and is not fixed , I do not know How to solve it. Any idea could be helpful. Should I still use trainer for inference ?
