I have unbalanced data and i want to use BCEwithLogitLoss with weight factor for minority classes. Total samples in each classes are,

`samples = torch.FloatTensor([74891,11865,194148,98997,29350,104203,130637,30649,141300,164775,176567,16267,148950,1536,12022,22100,1566,67277,74877])`

and I have devised a formula for the calculation of weight factor as `max(1,log2(majority_class/class_samples))`

which gives somehow the values which seems fine to me as well. but when I am trying to implement this with pytorch it gives me error as,

```
step1 = torch.log2(torch.max(samples)/samples)
step2 = torch.max(1,step1)
```

error at step2 as `Dimension out of range (expected to be in range of [-1, 0], but got 1)`

final weights should be

`weights= torch.FloatTensor([1.37429258667969,4.03237283987156,1,1,2.7257244370681,1, 1,2.66324493724027,1,1,1,3.57713673021635,1,6.98183481923172, 4.01340801523125,3.13503857078672, 6.95392882266183,1.52897156569056,1.37456230692208])`

Lastly this formula is fine? or can anyone suggest me any better formula or improvement to this? Thanks alot in advance,