<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_cost(self, labels, logits):
 """ Build the graph for cost from the logits if logits are provided. If predictions are provided, logits are extracted from the operation. """

    op = logits.op
    if "softmax" in str(op).lower():
      logits, = op.inputs

    with tf.variable_scope('costs'):
      xent = tf.nn.softmax_cross_entropy_with_logits(
          logits=logits, labels=labels)
      cost = tf.reduce_mean(xent, name='xent')
      cost += self._decay()
      cost = cost

    return cost