# "compute\_loss" function

**URL:** <https://discuss.huggingface.co/t/compute-loss-function/8649>\
**Category:** Beginners\
**Created:** [July 24, 2021, 8:09am UTC](https://discuss.huggingface.co/t/compute-loss-function/8649 "2021-07-24T08:09:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinurad13](https://avatars.discourse-cdn.com/v4/letter/v/e274bd/32.png) [@vinurad13](https://discuss.huggingface.co/u/vinurad13)\
**Post date:** [July 24, 2021, 8:09am UTC](https://discuss.huggingface.co/t/compute-loss-function/8649/1 "2021-07-24T08:09:58Z")

</div>

Could someone give some insight to the “model.compute\_loss” function which is used when fine-tuning the models without the trainer API (e.g- Keras native training). How does it work (i.e.- for different tasks how it’s adapted.)? It says that it takes the first element of the output, how is the loss calculated then?

---

<div class="post-metadata">

**Author:** ![vinurad13](https://avatars.discourse-cdn.com/v4/letter/v/e274bd/32.png) [@vinurad13](https://discuss.huggingface.co/u/vinurad13)\
**Post date:** [July 26, 2021, 3:40am UTC](https://discuss.huggingface.co/t/compute-loss-function/8649/2 "2021-07-26T03:40:38Z")

</div>

as shown in here in Huggingface documentation, [Fine-tuning with custom datasets — transformers 4.7.0 documentation](https://huggingface.co/transformers/custom_datasets.html)
