I found the following worked. I had to reshape the target tensor to the required dimension (N):
x = Variable(batch['x'])
y_temp = batch['y'].numpy().ravel()
y_batch = torch.from_numpy(y_temp)
y = Variable(y_batch)