@ptrblck thank you for your help and patience with me. I have followed your link.  I converted the one-hot encoded to class indices.
labels = np.argmax(train_labels.loc[:, 'none':'both'].values, axis=1)
labels = torch.from_numpy(labels)
labels
tensor([0, 0, 1,  ..., 1, 0, 0])

a = torch.unique(samples_weight)
a
tensor([0.0004, 0.0004, 0.0016, 0.0044], dtype=torch.float64)

Now the tensor has a unique weight for each of the target labels. Now for the intuition: the sampler picks the labels with higher weight more frequently in a batch than the samples with lower weight? So, overall in a batch, the sampling is balanced irrespective of the class distribution in the dataset?
I computed the weighted random sampler from the original dataset. After that, I split the dataset into the train and validation set. For both sets, the same sampler should be used. right? As it gives is weight is computed from overall distribution in the original set.