# Getting error when fine-tuning Transformer model: Expected sequence or array-like, got \<class 'transformers.trainer\_utils.EvalPrediction'\>

**URL:** <https://discuss.huggingface.co/t/getting-error-when-fine-tuning-transformer-model-expected-sequence-or-array-like-got-class-transformers-trainer-utils-evalprediction/28515>\
**Category:** Beginners\
**Created:** [December 27, 2022, 2:27pm UTC](https://discuss.huggingface.co/t/getting-error-when-fine-tuning-transformer-model-expected-sequence-or-array-like-got-class-transformers-trainer-utils-evalprediction/28515 "2022-12-27T14:27:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hassanashas](https://avatars.discourse-cdn.com/v4/letter/h/59ef9b/32.png) [@hassanashas](https://discuss.huggingface.co/u/hassanashas)\
**Post date:** [December 27, 2022, 2:27pm UTC](https://discuss.huggingface.co/t/getting-error-when-fine-tuning-transformer-model-expected-sequence-or-array-like-got-class-transformers-trainer-utils-evalprediction/28515/1 "2022-12-27T14:27:12Z")

</div>

Hi, I am trying to implement Model from Hugging Face transformer library following this Youtube video: [Simple Training with the 🤗 Transformers Trainer - YouTube](https://www.youtube.com/watch?v=u--UVvH-LIQ)

I have followed along all the steps but for some reason, I get an error when I try to execute the **trainer.train() command**. This is the error I am getting,

`TypeError: Expected sequence or array-like, got <class 'transformers.trainer_utils.EvalPrediction'>`

Full error details are as follows,

```auto
The following columns in the evaluation set don't have a corresponding argument in `BertForSequenceClassification.forward` and have been ignored: label_text, text. If label_text, text are not expected by `BertForSequenceClassification.forward`, you can safely ignore this message.
*****Running Evaluation*****
  Num examples = 2000
  Batch size = 64
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-147-3435b262f1ae> in <module>
----> 1 trainer.train()

13 frames
/usr/local/lib/python3.8/dist-packages/sklearn/utils/validation.py in _num_samples(x)
    263 x = np.asarray(x)
    264 else:
--> 265 raise TypeError(message)
    266 
    267 if hasattr(x, "shape") and x.shape is not None:

TypeError: Expected sequence or array-like, got <class 'transformers.trainer_utils.EvalPrediction'>

```

Anyone who knows what could be the possible reason behind this error? If needed, you can access my Google Colab Notebook here. The Colab Notebook contains all the code that I did (it is same as the code shown in the video): **[Google Colab](https://colab.research.google.com/drive/1-4QuKsqe-w0EBA95D-gz8ch3l3FytVpX?usp=sharing)**

If you would like to know my training\_arguments and compute\_metrics function, then I am also sharing them below,

```auto
def compute_metrics(pred):
  labels = pred.label_ids
  preds = pred.predictions.argmax(-1)
  f1 = f1_score(labels, pred, average='weighted')
  return {"f1": f1}

```

```auto
batch_size = 64 

logging_steps = len(emotion_dataset['train'])
output_dir = "minlm-finetuned-emotion"
training_args = TrainingArguments(output_dir = output_dir, 
                                  num_train_epochs=5, 
                                  learning_rate=2e-5,
                                  per_device_train_batch_size=batch_size,
                                  per_device_eval_batch_size=batch_size,
                                  weight_decay=0.01, 
                                  evaluation_strategy="epoch",
                                  logging_steps=logging_steps,
                                  fp16=True,
                                  push_to_hub=True
                                  )

```

```auto
trainer = WeightedLossTrainer(model=model, 
                              args=training_args,
                              compute_metrics=compute_metrics,
                              train_dataset=emotion_dataset['train'],
                              eval_dataset=emotion_dataset['validation'],
                              tokenizer=tokenizer)

```

```auto

trainer.train()

```
