I guess the target tensor has two dimensions, while only the batch dimension is expected.
The two dimensions might be introduces by the view(-1, 1) op in:
self.targets = torch.tensor([0,1,1,0], dtype=torch.int64).view(-1,1)

You could either remove dim1 via:
loss = criterion(output, target.squeeze(1))

or try to use view(-1) instead (the view might not be necessary at all).