Defining loss and optimizer