# Difference between using or not compute\_metric

**URL:** <https://discuss.huggingface.co/t/difference-between-using-or-not-compute-metric/63668>\
**Category:** Beginners\
**Created:** [November 27, 2023, 8:20am UTC](https://discuss.huggingface.co/t/difference-between-using-or-not-compute-metric/63668 "2023-11-27T08:20:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nnhwin](https://avatars.discourse-cdn.com/v4/letter/n/c0e974/32.png) [@nnhwin](https://discuss.huggingface.co/u/nnhwin)\
**Post date:** [November 27, 2023, 8:20am UTC](https://discuss.huggingface.co/t/difference-between-using-or-not-compute-metric/63668/1 "2023-11-27T08:20:27Z")

</div>

Hello, I am newbie in HF and I found there are two different implementations as follows:

def compute\_metrics(eval\_pred):  
logits, labels = eval\_pred  
predictions = np.argmax(logits, axis=-1)  
return metric.compute(predictions=predictions, references=labels)

In train API, some codes call compute\_metrics while some does not. What is the differnce between using and no using this metrics function. Can you please explain how it can effect the system predictions??

trainer = Trainer(  
model=model,  
args=training\_args,  
train\_dataset=dataset\_train,  
eval\_dataset=dataset\_test,  
**#compute\_metrics=compute\_metrics,**  
callbacks=[EarlyStoppingCallback(early\_stopping\_patience=1)]  
)

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](https://discuss.huggingface.co/u/panigrah)\
**Post date:** [November 27, 2023, 8:48am UTC](https://discuss.huggingface.co/t/difference-between-using-or-not-compute-metric/63668/2 "2023-11-27T08:48:17Z")

</div>

Compute metrics is to help track how the training is performing. It does not affect the training itself.  
So think of it is a reporting function that calculates extended metrics to help you evaluate the quality of training. You can then use the metrics it reports to fine tune the training.

see this example here.

> **[Fine-tuning a model with the Trainer API - Hugging Face NLP Course](https://huggingface.co/learn/nlp-course/en/chapter3/3?fw=pt#evaluation)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![nnhwin](https://avatars.discourse-cdn.com/v4/letter/n/c0e974/32.png) [@nnhwin](https://discuss.huggingface.co/u/nnhwin)\
**Post date:** [November 27, 2023, 9:33am UTC](https://discuss.huggingface.co/t/difference-between-using-or-not-compute-metric/63668/3 "2023-11-27T09:33:55Z")

</div>

thank you so much
