Hi, my training set is very unbalanced, I mean big time. I use the sklearn.utils.class_weight.compute_class_weight() to get the weights of the classes and get the following coefficients: array([20.98221801, 21.80828959, 20.86804102, 0.25916362]). So we have 3 equally weighted classes and 1 very overwhelming.
As far as I understand, there is no need to normalize the weights for the WeightedRandomSampler():
# define the array of weights same shape as data
weights = np.empty_like(train_targets, dtype=np.float32)

# project the weights along the training set
for i in range(weights.shape[0]):
    weights[i] = class_weights[train_targets[i]]
weights = torch.from_numpy(weights)

Then I am trying to return indices only from the dataloader, so I have:
data = Data()

weighted_sampler = WeightedRandomSampler(weights=weights, num_samples=len(train_targets), replacement=True)

# define dataloader
dataloader = DataLoader(data, sampler=weighted_sampler, batch_size=64, drop_last=True)

However, the dataloader is still heavily unbalanced:
for index in dataloader:
    print(index.numpy())
    print(targets[index])
    break