Creating loss function for each layers