Building the loss for each mini-batch