WeightedRandomSampler is used to provide weights to each sample, which is used during the sampling process of selecting the data samples for each batch.
The higher the weight assigned to a particular index, the more likely this data sample will be used in a batch.
To created batches of balanced classes, you would therefore assign a higher weight to samples from the minority class, and a lower weight to samples from the majority class.



 Er_Hall:

Also is it ok that I used both WeightedRandomSampler with reduction = mean?


Yes, the reduction is independent from the sampling strategy.