# ValueError: Trainer: evaluation requires an eval\_dataset

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fvalueerror-trainer-evaluation-requires-an-eval-dataset%2F40670%3E%5C
**Category:** Beginners\
**Created:** [May 22, 2023, 9:09pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fvalueerror-trainer-evaluation-requires-an-eval-dataset%2F40670 "2023-05-22T21:09:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IvoTavares](https://avatars.discourse-cdn.com/v4/letter/i/5f9b8f/32.png) [@IvoTavares](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FIvoTavares)%5C
**Post date:** [May 22, 2023, 9:09pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fvalueerror-trainer-evaluation-requires-an-eval-dataset%2F40670%2F1 "2023-05-22T21:09:07Z")

</div>

I’m trying to do a finetuning without an evaluation dataset.  
For that, I’m using the following code:

```
    training_args = TrainingArguments(
        output_dir=resume_from_checkpoint,
        evaluation_strategy="epoch",
        per_device_train_batch_size=1,
    )
    def compute_metrics(pred: EvalPrediction):
        labels = pred.label_ids
        preds = pred.predictions.argmax(-1)
        f1 = f1_score(labels, preds, average="weighted")
        acc = accuracy_score(labels, preds, average="weighted")
        return {"accuracy": acc, "f1": f1}
    trainer = Trainer(
        model=self.nli_model,
        args=training_args,
        train_dataset=tokenized_datasets,
        compute_metrics=compute_metrics,
    )

```

However, I get `ValueError: Trainer: evaluation requires an eval_dataset.`. I thought that by default, Trainer does no evaluation… at least in the docs, I got this idea…

---

<div class="post-metadata">

**Author:** ![Guldeniz](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/guldeniz/32/16355_2.png) [@Guldeniz](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FGuldeniz)%5C
**Post date:** [May 26, 2023, 11:09am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fvalueerror-trainer-evaluation-requires-an-eval-dataset%2F40670%2F2 "2023-05-26T11:09:04Z")

</div>

Hello.

In source code [here](https://huggingface.co/transformers/v3.4.0/_modules/transformers/trainer.html),  
`get_eval_dataloader` function has this code:

```auto
if eval_dataset is None and self.eval_dataset is None:
            raise ValueError("Trainer: evaluation requires an eval_dataset.")

```

It is enforcing the requirement that an evaluation dataset must be provided for the trainer to perform evaluation. If no evaluation dataset is specified, the code will raise an error to alert the user.

In order to compute the desired metric, the trainer requires the specification of an `eval_dataset`. This dataset serves as the basis for evaluating the model’s performance.

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmariosasko)%5C
**Post date:** [May 26, 2023, 12:37pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fvalueerror-trainer-evaluation-requires-an-eval-dataset%2F40670%2F3 "2023-05-26T12:37:05Z")

</div>

You can avoid this error by not specifying `evaluation_strategy` in `TrainingArguments`.
