'Cross entropy plus L2 loss on weights and biases of the hidden layers.'

def _AddCostFunction(self, batch_size, gold_actions, logits):

    dense_golden = BatchedSparseToDense(gold_actions, self._num_actions)
    cross_entropy = tf.div(tf.reduce_sum(tf.nn.softmax_cross_entropy_with_logits(labels=dense_golden, logits=logits)), batch_size)
    regularized_params = [tf.nn.l2_loss(p) for (k, p) in self.params.items() if (k.startswith('weights') or k.startswith('bias'))]
    l2_loss = ((0.0001 * tf.add_n(regularized_params)) if regularized_params else 0)
    return {'cost': tf.add(cross_entropy, l2_loss, name='cost')}
