# Weighted learning

**URL:** <https://discuss.pytorch.org/t/weighted-learning/1772>\
**Category:** Uncategorized\
**Created:** [April 10, 2017, 4:14am UTC](https://discuss.pytorch.org/t/weighted-learning/1772 "2017-04-10T04:14:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![foreverkeen](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/f/e36b37/32.png) [@foreverkeen](https://discuss.pytorch.org/u/foreverkeen)\
**Post date:** [April 10, 2017, 4:14am UTC](https://discuss.pytorch.org/t/weighted-learning/1772/1 "2017-04-10T04:14:45Z")

</div>

Do anyone know how can I do weighted learning([e.g.In](http://e.g.In) sklean.svm.svc ,the parameter ‘class\_weight’ allow you to assign different weight to different class ) in CNN with cross entropy loss?Thanks very much!

---

<div class="post-metadata">

**Author:** ![Henderake](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/h/3bc359/32.png) [@Henderake](https://discuss.pytorch.org/u/Henderake)\
**Post date:** [April 10, 2017, 5:40am UTC](https://discuss.pytorch.org/t/weighted-learning/1772/2 "2017-04-10T05:40:05Z")

</div>

Just pass the weights as an argument to [torch.nn.CrossEntropyLoss](http://pytorch.org/docs/nn.html#crossentropyloss)

---

<div class="post-metadata">

**Author:** ![chilango](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/c/e47c2d/32.png) [@chilango](https://discuss.pytorch.org/u/chilango)\
**Post date:** [August 3, 2017, 5:21pm UTC](https://discuss.pytorch.org/t/weighted-learning/1772/3 "2017-08-03T17:21:48Z")

</div>

Are the weights simply the proportion of cases in each class? Or is it the inverse of this?

---

<div class="post-metadata">

**Author:** ![kkorovesis](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kkorovesis/32/1645_2.png) [@kkorovesis](https://discuss.pytorch.org/u/kkorovesis)\
**Post date:** [March 5, 2018, 6:54pm UTC](https://discuss.pytorch.org/t/weighted-learning/1772/4 "2018-03-05T18:54:38Z")

</div>

I am on the same boat. Don’t know what weights to put.

---

<div class="post-metadata">

**Author:** ![hamidfarhid](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/hamidfarhid/32/3784_2.png) [@hamidfarhid](https://discuss.pytorch.org/u/hamidfarhid)\
**Post date:** [July 16, 2018, 3:05pm UTC](https://discuss.pytorch.org/t/weighted-learning/1772/5 "2018-07-16T15:05:28Z")

</div>

Hi All,

Did you get any update on this? Is there any sample code for this?

Thanks
