Weighting training instances

Is there a nice way to add custom weights to instances? So far, I’ve been weighting the losses directly after computing them via criterion(outputs, labels).

However, if possible, I’d like to weight each instance before the training.

1 Like

Hi, many losses support class - wise weighting. Check out CrossEntropyLoss for instance.

Hi,

I’m aware we can add weights to loss functions, but I am curious if it’s possible to add weights directly to the training instances. I’m aware the end result would be the same though, however, adding weights to dataset is more convenient to me.

Hi,

the only way to do some kind ‘sample - weighting’ is by setting reduction='none' (you’ll get the individual loss values) and multiply them with your custom sample - weight what you should therefore provide. (This is actually the same as what is mentioned in this thread.) But perhaps this is what you’ve already done.
Other than that, I cannot think of an approach.

Regards.

1 Like

Yeah, that’s what I’ve been doing so far. I guess there is no other way of doing. Thank you for your help.

1 Like