def accuracy_rate(context,
                  penalty_loss=defaults.DEFAULT_PENALTY_LOSS,
                  constraint_loss=defaults.DEFAULT_CONSTRAINT_LOSS):
  """Creates an `Expression` for an accuracy rate.

  An accuracy rate is the number of examples within the given context on which
  the model makes a correct prediction, divided by the number of examples within
  the context.

  Please see the docstrings of accuracy_rate() in binary_rates.py and
  multiclass_rates.py for further details.

  Args:
    context: `SubsettableContext`, the block of data to use when calculating the
      rate. If this is a multiclass context, we'll calculate the multiclass
      version of the rate.
    penalty_loss: `MulticlassLoss`, the (differentiable) loss function to use
      when calculating the "penalty" approximation to the rate.
    constraint_loss: `MulticlassLoss`, the (not necessarily differentiable) loss
      function to use when calculating the "constraint" approximation to the
      rate.

  Returns:
    An `Expression` representing the accuracy rate.

  Raises:
    TypeError: if the context is not a SubsettableContext, either loss is not a
      BinaryClassificationLoss (if the context is non-multiclass) or a
      MulticlassLoss (if the context is multiclass).
    ValueError: if the context doesn't contain labels.
  """
  if _is_multiclass(context):
    return multiclass_rates.accuracy_rate(
        context=context,
        penalty_loss=penalty_loss,
        constraint_loss=constraint_loss)

  return binary_rates.accuracy_rate(
      context=context,
      penalty_loss=penalty_loss,
      constraint_loss=constraint_loss)