Weight Class Setting

I want to set weight loss for balancing data. I write

import torch
from sklearn.utils import compute_class_weight
class_weight = torch.from_numpy(compute_class_weight(‘balanced’,np.unique(train_data[‘bi_target’]),train_data[‘bi_target’]))

learn = text_classifier_learner(data_clas, AWD_LSTM, drop_mult=0.5,pretrained = True)
learn.loss_func = cal_loss
learn.fit_one_cycle(1, 1e-1)

but fastai raise a problem
“ValueError: Target and input must have the same number of elements. target nelement (32) != input nelement (64)”

How can I set class weight to balanced the class?