When I remove x = x.squeeze(1) from forward the loss function throws an exception just like,
ValueError: Target size (torch.Size([32])) must be the same as input size (torch.Size([32, 1]))

I have added batch normalization, weight initialization and updated layers so problem solved. thank you @ptrblck