totalLossFunction = function totalLossFunction() {
	        var feeds = [];

	        for (var i = 0; i < _this5.inputs.length; ++i) {
	          feeds.push({
	            key: _this5.inputs[i],
	            value: inputs[i]
	          });
	        }

	        var feedDict = new FeedDict(feeds);

	        var outputs = execute(_this5.outputs, feedDict, {
	          'training': true
	        }); // TODO(cais): Take care of the case of multiple outputs from a
	        //   single layer?


	        var totalLoss;

	        for (var _i5 = 0; _i5 < _this5.lossFunctions.length; ++_i5) {
	          var lossFunction = _this5.lossFunctions[_i5];
	          var loss = lossFunction(targets[_i5], outputs[_i5]);

	          if (sampleWeights[_i5] != null) {
	            loss = computeWeightedLoss$1(loss, sampleWeights[_i5]);
	          } // TODO(cais): push Scalar instead.


	          var meanLoss = mean(loss); // TODO(cais): Use a scope() instead, to avoid ownership.

	          lossValues.push(meanLoss);

	          if (_i5 === 0) {
	            totalLoss = loss;
	          } else {
	            totalLoss = add$1(totalLoss, loss);
	          }
	        } // Compute the metrics.
	        // TODO(cais): These should probably be calculated outside
	        //   totalLossFunction to benefit speed?


	        for (var _i6 = 0; _i6 < _this5.metricsTensors.length; ++_i6) {
	          var weightedMetric = void 0;

	          if (_this5.outputs.length > 1 && _i6 < _this5.outputs.length) {
	            weightedMetric = lossValues[_i6];
	          } else {
	            var metric = _this5.metricsTensors[_i6][0];
	            var outputIndex = _this5.metricsTensors[_i6][1];
	            weightedMetric = mean(metric(targets[outputIndex], outputs[outputIndex]));
	          }

	          keep(weightedMetric); // TODO(cais): Use a scope() instead, to avoid ownership.

	          metricsValues.push(weightedMetric);
	        }

	        totalLoss = mean(totalLoss); // Add regularizer penalties.

	        _this5.calculateLosses().forEach(function (regularizerLoss) {
	          totalLoss = add$1(totalLoss, regularizerLoss);
	        });

	        return totalLoss;
	      }
Creates a function that performs the following actions:

1. computes the losses
2. sums them to get the total loss
3. call the optimizer computes the gradients of the LayersModel's
   trainable weights w.r.t. the total loss and update the variables
4. calculates the metrics
5. returns the values of the losses and metrics.