parameters: (estimator, metric_fn)
return_statement: return estimator_lib.Estimator(
        model_fn=new_model_fn,
        model_dir=estimator.model_dir,
        config=estimator.config)
docstring: Creates a new ${tf.estimator.Estimator} which has given metrics.
  
    Example:
  
    ```python
      def my_auc(labels, predictions):
        return {'auc': tf.metrics.auc(labels, predictions['logistic'])}
  
      estimator = tf.estimator.DNNClassifier(...)
      estimator = tf.contrib.estimator.add_metrics(estimator, my_auc)
      estimator.train(...)
      estimator.evaluate(...)
    ```
    Example usage of custom metric which uses features:
  
    ```python
      def my_auc(features, labels, predictions):
        return {'auc': tf.metrics.auc(
          labels, predictions['logistic'], weights=features['weight'])}
  
      estimator = tf.estimator.DNNClassifier(...)
      estimator = tf.contrib.estimator.add_metrics(estimator, my_auc)
      estimator.train(...)
      estimator.evaluate(...)
    ```
  
    Args:
      estimator: A ${tf.estimator.Estimator} object.
      metric_fn: A function which should obey the following signature:
        - Args: can only have following four arguments in any order:
          * predictions: Predictions `Tensor` or dict of `Tensor` created by given
            `estimator`.
          * features: Input `dict` of `Tensor` objects created by `input_fn` which
            is given to `estimator.evaluate` as an argument.
          * labels:  Labels `Tensor` or dict of `Tensor` created by `input_fn`
            which is given to `estimator.evaluate` as an argument.
          * config: config attribute of the `estimator`.
         - Returns:
           Dict of metric results keyed by name. Final metrics are a union of this
           and `estimator's` existing metrics. If there is a name conflict between
           this and `estimator`s existing metrics, this will override the existing
           one. The values of the dict are the results of calling a metric
           function, namely a `(metric_tensor, update_op)` tuple.
  
    Returns:
        A new ${tf.estimator.Estimator} which has a union of original metrics with
          given ones.
docstring_summary: Creates a new ${tf.estimator.Estimator} which has given metrics.
docstring_tokens: Creates a new $ { tf . estimator . Estimator } which has given metrics .
function: def add_metrics(estimator, metric_fn):
    """Creates a new ${tf.estimator.Estimator} which has given metrics.
  
    Example:
  
    ```python
      def my_auc(labels, predictions):
        return {'auc': tf.metrics.auc(labels, predictions['logistic'])}
  
      estimator = tf.estimator.DNNClassifier(...)
      estimator = tf.contrib.estimator.add_metrics(estimator, my_auc)
      estimator.train(...)
      estimator.evaluate(...)
    ```
    Example usage of custom metric which uses features:
  
    ```python
      def my_auc(features, labels, predictions):
        return {'auc': tf.metrics.auc(
          labels, predictions['logistic'], weights=features['weight'])}
  
      estimator = tf.estimator.DNNClassifier(...)
      estimator = tf.contrib.estimator.add_metrics(estimator, my_auc)
      estimator.train(...)
      estimator.evaluate(...)
    ```
  
    Args:
      estimator: A ${tf.estimator.Estimator} object.
      metric_fn: A function which should obey the following signature:
        - Args: can only have following four arguments in any order:
          * predictions: Predictions `Tensor` or dict of `Tensor` created by given
            `estimator`.
          * features: Input `dict` of `Tensor` objects created by `input_fn` which
            is given to `estimator.evaluate` as an argument.
          * labels:  Labels `Tensor` or dict of `Tensor` created by `input_fn`
            which is given to `estimator.evaluate` as an argument.
          * config: config attribute of the `estimator`.
         - Returns:
           Dict of metric results keyed by name. Final metrics are a union of this
           and `estimator's` existing metrics. If there is a name conflict between
           this and `estimator`s existing metrics, this will override the existing
           one. The values of the dict are the results of calling a metric
           function, namely a `(metric_tensor, update_op)` tuple.
  
    Returns:
        A new ${tf.estimator.Estimator} which has a union of original metrics with
          given ones.
    """
    _verify_metric_fn_args(metric_fn)
  
    def new_model_fn(features, labels, mode, config):
      spec = estimator.model_fn(features, labels, mode, config)
      if mode != model_fn_lib.ModeKeys.EVAL:
        return spec
      new_metrics = _call_metric_fn(metric_fn, features, labels, spec.predictions,
                                    config)
      all_metrics = spec.eval_metric_ops or {}
      all_metrics.update(new_metrics)
      return spec._replace(eval_metric_ops=all_metrics)
  
    return estimator_lib.Estimator(
        model_fn=new_model_fn,
        model_dir=estimator.model_dir,
        config=estimator.config)
function_tokens: def add_metrics ( estimator , metric_fn ) : _verify_metric_fn_args ( metric_fn ) def new_model_fn ( features , labels , mode , config ) : spec = estimator . model_fn ( features , labels , mode , config ) if mode != model_fn_lib . ModeKeys . EVAL : return spec new_metrics = _call_metric_fn ( metric_fn , features , labels , spec . predictions , config ) all_metrics = spec . eval_metric_ops or { } all_metrics . update ( new_metrics ) return spec . _replace ( eval_metric_ops = all_metrics ) return estimator_lib . Estimator ( model_fn = new_model_fn , model_dir = estimator . model_dir , config = estimator . config )