# "compute\_loss" function

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcompute-loss-function%2F8649%3E%5C
**Category:** Beginners\
**Created:** [July 24, 2021, 8:09am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcompute-loss-function%2F8649 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvinurad13)%5C
**Post date:** [July 24, 2021, 8:09am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcompute-loss-function%2F8649%2F1 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvinurad13)%5C
**Post date:** [July 26, 2021, 3:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcompute-loss-function%2F8649%2F2 "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)
