# How do I evaluate a pretrained model on a test dataset?

**URL:** <https://discuss.huggingface.co/t/how-do-i-evaluate-a-pretrained-model-on-a-test-dataset/15099>\
**Category:** Beginners\
**Created:** [February 24, 2022, 4:49am UTC](https://discuss.huggingface.co/t/how-do-i-evaluate-a-pretrained-model-on-a-test-dataset/15099 "2022-02-24T04:49:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![barlen](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@barlen](https://discuss.huggingface.co/u/barlen)\
**Post date:** [February 24, 2022, 4:49am UTC](https://discuss.huggingface.co/t/how-do-i-evaluate-a-pretrained-model-on-a-test-dataset/15099/1 "2022-02-24T04:49:47Z")

</div>

Without training, how do I use a test dataset to evaluate a pretrained model?

---

<div class="post-metadata">

**Author:** ![beneyal](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/beneyal/32/27988_2.png) [@beneyal](https://discuss.huggingface.co/u/beneyal)\
**Post date:** [February 24, 2022, 5:00am UTC](https://discuss.huggingface.co/t/how-do-i-evaluate-a-pretrained-model-on-a-test-dataset/15099/2 "2022-02-24T05:00:17Z")

</div>

Hello 🙂

Assuming you’re using PyTorch, you can wrap your model inside a `Trainer` and then call `trainer.evaluate()`. An example (taken from [here](https://huggingface.co/docs/transformers/training#finetuning-in-pytorch-with-the-trainer-api)):

```python
from transformers import TrainingArguments

training_args = TrainingArguments("test_trainer"),

import numpy as np
from datasets import load_metric

metric = load_metric("accuracy")

def compute_metrics(eval_pred):
    logits, labels = eval_pred
    predictions = np.argmax(logits, axis=-1)
    return metric.compute(predictions=predictions, references=labels)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=small_train_dataset,
    eval_dataset=small_eval_dataset,
    compute_metrics=compute_metrics,
)

trainer.evaluate()

```

If you don’t want to use a `Trainer`, check out the examples [here](https://github.com/huggingface/transformers/tree/master/examples/pytorch) and check the files ending with `_no_trainer.py`.
