Not able to predict using Transformers Trainer class

I am learning to finetune a pre-trained model but when I am trying to test the finetuned model, I am getting this error

IndexError: tuple index out of range

this is my google colab notebook and I am using this Kaggle dataset

while debugging I found some of the observations

  1. when I pass the testing data with ‘input_ids’,‘attention_mask’ and ‘labels’, I am able to get the predicted results but when I am passing the data without labels ie. when I pass only ‘input_ids’ and ‘attention_mask’ I am getting the error.
  2. but when I pass only ‘input_ids’ and ‘attention_mask’ of the training data, I am getting the predicted value as well which I am not able to understand

I am stuck and not able to move any further, any assistance to solve the issue would be appreciated

1 Like

The error itself is commonplace and often seen if you misspell the Python code, but after searching, it appears that it may be a long-term unresolved bug or bad specification.

Hey,

If you use the ‘.predict’ method, then make sure to use the model within the Trainer. The Trainer itself is a wrapper around a model so maybe the predict in trainer is not the same that the predict in the model.

To check it you could :

test_tokens = tokenizer("I am writing this post", return_tensors = "pt" ) #check format of the tensors
trainer.model.predict(test_tokens)

It might be something else but sometimes people get confused between the Trainer class and the model itself.