# Trainer API to log both Training and Validation Metrics

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrainer-api-to-log-both-training-and-validation-metrics%2F7785%3E%5C
**Category:** 🤗Transformers\
**Created:** [June 30, 2021, 11:41pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrainer-api-to-log-both-training-and-validation-metrics%2F7785 "2021-06-30T23:41:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![muralidandu](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@muralidandu](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmuralidandu)%5C
**Post date:** [June 30, 2021, 11:41pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrainer-api-to-log-both-training-and-validation-metrics%2F7785%2F1 "2021-06-30T23:41:06Z")

</div>

I am fine-tuning for a classification task - I am trying to replicate (and potentially replace) my native PyTorch training and evaluation loops with the Trainer API.

I usually log metrics for both training and validation across each batch/epoch.

Here is what I can achieve with Trainer API.  
 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/4/4c40d3673b45129ab8b21ef1902c988a5cb32fcf.png)

The accuracy and F1 are of validation sets and I want to also see the same set of metrics at each step for training data as well. Can someone guide on how I can achieve this?

Thanks.

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsgugger)%5C
**Post date:** [July 1, 2021, 12:40pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrainer-api-to-log-both-training-and-validation-metrics%2F7785%2F2 "2021-07-01T12:40:12Z")

</div>

This is not implemented in the `Trainer`. You can manually `evaluate` yourself at the end of training on any dataset you want (training set included).

---

<div class="post-metadata">

**Author:** ![muralidandu](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@muralidandu](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmuralidandu)%5C
**Post date:** [July 1, 2021, 6:44pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrainer-api-to-log-both-training-and-validation-metrics%2F7785%2F3 "2021-07-01T18:44:34Z")

</div>

Thanks for the reply @sgugger . Since loss may not be directly related to certain metrics, I was hoping to see where the metrics trend starts overfitting and make decisions based on that. Do you think this is a valid use case to think about adding this to the API in the future?
