# WeightedRandomSampler for dataset balance

**URL:** <https://discuss.pytorch.org/t/weightedrandomsampler-for-dataset-balance/37437>\
**Category:** Uncategorized\
**Created:** [February 17, 2019, 11:25am UTC](https://discuss.pytorch.org/t/weightedrandomsampler-for-dataset-balance/37437 "2019-02-17T11:25:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [February 18, 2019, 1:29am UTC](https://discuss.pytorch.org/t/weightedrandomsampler-for-dataset-balance/37437/2 "2019-02-18T01:29:05Z")

</div>

`weights` should be given as sample weights (i.e. each sample in your `Dataset` will get a weight) not as class weights. Have a look at [this small code snippet](https://discuss.pytorch.org/t/some-problems-with-weightedrandomsampler/23242/2?u=ptrblck) to see an example.

---

_[View the full topic](https://discuss.pytorch.org/t/weightedrandomsampler-for-dataset-balance/37437)._
