# Own loss function for multi class classifikation

**URL:** <https://discuss.pytorch.org/t/own-loss-function-for-multi-class-classifikation/115448>\
**Category:** autograd\
**Created:** [March 20, 2021, 5:31pm UTC](https://discuss.pytorch.org/t/own-loss-function-for-multi-class-classifikation/115448 "2021-03-20T17:31:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![KFrank](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/ecb155/32.png) [@KFrank](https://discuss.pytorch.org/u/KFrank)\
**Post date:** [March 21, 2021, 2:02am UTC](https://discuss.pytorch.org/t/own-loss-function-for-multi-class-classifikation/115448/2 "2021-03-21T02:02:13Z")

</div>

Hi roxor!

> [@roxor](#):
>
> I want to penalize some missclassification stronger than others.

One approach is to use cross-entropy with probabilistic or _soft_ targets.

This post has further discussion and details:

> [@Label smoothing for only a subset of classes](https://discuss.pytorch.org/t/label-smoothing-for-only-a-subset-of-classes/114208/2):
>
> Hi macazinc! Here’s what I think you’re asking: You have a multi-class (30 classes) classification problem. You know that for most of your classes, your ground-truth target labels are correct, but your labels sometimes mix up two of your classes, say 4 and 9, Let’s say that a sample labelled 4 is actually a 9 25% of the time, and that a sample labelled 9 is actually a 4 10% of the time. You will (most likely) want to use cross-entropy loss, but pytorch only provides a version that tak…

Best.

K. Frank

---

_[View the full topic](https://discuss.pytorch.org/t/own-loss-function-for-multi-class-classifikation/115448)._
