# Log Perplexity using Trainer

**URL:** <https://discuss.huggingface.co/t/log-perplexity-using-trainer/4947>\
**Category:** 🤗Transformers\
**Created:** [March 22, 2021, 9:10pm UTC](https://discuss.huggingface.co/t/log-perplexity-using-trainer/4947 "2021-03-22T21:10:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonschoe](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/simonschoe/32/20951_2.png) [@simonschoe](https://discuss.huggingface.co/u/simonschoe)\
**Post date:** [March 22, 2021, 9:10pm UTC](https://discuss.huggingface.co/t/log-perplexity-using-trainer/4947/1 "2021-03-22T21:10:40Z")

</div>

Hi there,  
I am wondering, what would be the optimal solution to also report and log `perplexity` during the training loop via the `Trainer` API. How would the corresponding `compute_metrics` function look like. So far I tried without success since I am not 100% sure how the `EvalPrediction` output would look like.  
Thanks in advance 🙂  
Simon

---

<div class="post-metadata">

**Author:** ![simonschoe](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/simonschoe/32/20951_2.png) [@simonschoe](https://discuss.huggingface.co/u/simonschoe)\
**Post date:** [March 27, 2021, 3:55pm UTC](https://discuss.huggingface.co/t/log-perplexity-using-trainer/4947/2 "2021-03-27T15:55:05Z")

</div>

This brings me to an adjacent question: How would a `compute_metrics` function look like that can also report the relative change `perplexity` respectively `train_loss`? I would be super grateful if anyone could provide a little guidance!

---

<div class="post-metadata">

**Author:** ![alihan](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@alihan](https://discuss.huggingface.co/u/alihan)\
**Post date:** [October 9, 2021, 2:53pm UTC](https://discuss.huggingface.co/t/log-perplexity-using-trainer/4947/3 "2021-10-09T14:53:54Z")

</div>

Hi, I am also looking very forward to see how it is possible to utilize perplexity during execution oc compute\_metrixs() while finetuning pretrained models for MLM or CLM
