RuntimeError: The size of tensor a (1447) must match the size of tensor b (2) at non-singleton dimension 0

When i define weight in BCELoss I got this error. How to resolve it? I have 2 classes.
criterion=nn.BCELoss(weight=torch.FloatTensor([2.0, 1.0]))
RuntimeError: The size of tensor a (1447) must match the size of tensor b (2) at non-singleton dimension 0

From the docs:

weight (Tensor, optional) – a manual rescaling weight given to the loss of each batch element. If given, has to be a Tensor of size nbatch.

so you would have to provide a weight value for each sample in the batch.