# Trainer API to log both Training and Validation Metrics

**URL:** <https://discuss.huggingface.co/t/trainer-api-to-log-both-training-and-validation-metrics/7785>\
**Category:** 🤗Transformers\
**Created:** [June 30, 2021, 11:41pm UTC](https://discuss.huggingface.co/t/trainer-api-to-log-both-training-and-validation-metrics/7785 "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](https://discuss.huggingface.co/u/muralidandu)\
**Post date:** [June 30, 2021, 11:41pm UTC](https://discuss.huggingface.co/t/trainer-api-to-log-both-training-and-validation-metrics/7785/1 "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](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [July 1, 2021, 12:40pm UTC](https://discuss.huggingface.co/t/trainer-api-to-log-both-training-and-validation-metrics/7785/2 "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](https://discuss.huggingface.co/u/muralidandu)\
**Post date:** [July 1, 2021, 6:44pm UTC](https://discuss.huggingface.co/t/trainer-api-to-log-both-training-and-validation-metrics/7785/3 "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?
