parameters: (
      cell_type,
      num_units,
      target_column,
      problem_type,
      prediction_type,
      optimizer,
      sequence_feature_columns,
      context_feature_columns=None,
      predict_probabilities=False,
      learning_rate=None,
      gradient_clipping_norm=None,
      dropout_keep_probabilities=None,
      sequence_length_key=rnn_common.RNNKeys.SEQUENCE_LENGTH_KEY,
      dtype=dtypes.float32,
      parallel_iterations=None,
      swap_memory=True,
      name='DynamicRNNModel')
return_statement: return _dynamic_rnn_model_fn
docstring: Creates an RNN model function for an `Estimator`.
  
    The model function returns an instance of `ModelFnOps`. When
    `problem_type == ProblemType.CLASSIFICATION` and
    `predict_probabilities == True`, the returned `ModelFnOps` includes an output
    alternative containing the classes and their associated probabilities. When
    `predict_probabilities == False`, only the classes are included. When
    `problem_type == ProblemType.LINEAR_REGRESSION`, the output alternative
    contains only the predicted values.
  
    Args:
      cell_type: A string, a subclass of `RNNCell` or an instance of an `RNNCell`.
      num_units: A single `int` or a list of `int`s. The size of the `RNNCell`s.
      target_column: An initialized `TargetColumn`, used to calculate prediction
        and loss.
      problem_type: `ProblemType.CLASSIFICATION` or
        `ProblemType.LINEAR_REGRESSION`.
      prediction_type: `PredictionType.SINGLE_VALUE` or
        `PredictionType.MULTIPLE_VALUE`.
      optimizer: A subclass of `Optimizer`, an instance of an `Optimizer` or a
        string.
      sequence_feature_columns: An iterable containing all the feature columns
        describing sequence features. All items in the set should be instances
        of classes derived from `FeatureColumn`.
      context_feature_columns: An iterable containing all the feature columns
        describing context features, i.e., features that apply across all time
        steps. All items in the set should be instances of classes derived from
        `FeatureColumn`.
      predict_probabilities: A boolean indicating whether to predict probabilities
        for all classes. Must only be used with
        `ProblemType.CLASSIFICATION`.
      learning_rate: Learning rate used for optimization. This argument has no
        effect if `optimizer` is an instance of an `Optimizer`.
      gradient_clipping_norm: A float. Gradients will be clipped to this value.
      dropout_keep_probabilities: a list of dropout keep probabilities or `None`.
        If a list is given, it must have length `len(num_units) + 1`.
      sequence_length_key: The key that will be used to look up sequence length in
        the `features` dict.
      dtype: The dtype of the state and output of the given `cell`.
      parallel_iterations: Number of iterations to run in parallel. Values >> 1
        use more memory but take less time, while smaller values use less memory
        but computations take longer.
      swap_memory: Transparently swap the tensors produced in forward inference
        but needed for back prop from GPU to CPU.  This allows training RNNs
        which would typically not fit on a single GPU, with very minimal (or no)
        performance penalty.
      name: A string that will be used to create a scope for the RNN.
  
    Returns:
      A model function to be passed to an `Estimator`.
  
    Raises:
      ValueError: `problem_type` is not one of
        `ProblemType.LINEAR_REGRESSION` or `ProblemType.CLASSIFICATION`.
      ValueError: `prediction_type` is not one of `PredictionType.SINGLE_VALUE`
        or `PredictionType.MULTIPLE_VALUE`.
      ValueError: `predict_probabilities` is `True` for `problem_type` other
        than `ProblemType.CLASSIFICATION`.
      ValueError: `len(dropout_keep_probabilities)` is not `len(num_units) + 1`.
docstring_summary: Creates an RNN model function for an `Estimator`.
docstring_tokens: Creates an RNN model function for an Estimator .
function: def _get_dynamic_rnn_model_fn(
      cell_type,
      num_units,
      target_column,
      problem_type,
      prediction_type,
      optimizer,
      sequence_feature_columns,
      context_feature_columns=None,
      predict_probabilities=False,
      learning_rate=None,
      gradient_clipping_norm=None,
      dropout_keep_probabilities=None,
      sequence_length_key=rnn_common.RNNKeys.SEQUENCE_LENGTH_KEY,
      dtype=dtypes.float32,
      parallel_iterations=None,
      swap_memory=True,
      name='DynamicRNNModel'):
    """Creates an RNN model function for an `Estimator`.
  
    The model function returns an instance of `ModelFnOps`. When
    `problem_type == ProblemType.CLASSIFICATION` and
    `predict_probabilities == True`, the returned `ModelFnOps` includes an output
    alternative containing the classes and their associated probabilities. When
    `predict_probabilities == False`, only the classes are included. When
    `problem_type == ProblemType.LINEAR_REGRESSION`, the output alternative
    contains only the predicted values.
  
    Args:
      cell_type: A string, a subclass of `RNNCell` or an instance of an `RNNCell`.
      num_units: A single `int` or a list of `int`s. The size of the `RNNCell`s.
      target_column: An initialized `TargetColumn`, used to calculate prediction
        and loss.
      problem_type: `ProblemType.CLASSIFICATION` or
        `ProblemType.LINEAR_REGRESSION`.
      prediction_type: `PredictionType.SINGLE_VALUE` or
        `PredictionType.MULTIPLE_VALUE`.
      optimizer: A subclass of `Optimizer`, an instance of an `Optimizer` or a
        string.
      sequence_feature_columns: An iterable containing all the feature columns
        describing sequence features. All items in the set should be instances
        of classes derived from `FeatureColumn`.
      context_feature_columns: An iterable containing all the feature columns
        describing context features, i.e., features that apply across all time
        steps. All items in the set should be instances of classes derived from
        `FeatureColumn`.
      predict_probabilities: A boolean indicating whether to predict probabilities
        for all classes. Must only be used with
        `ProblemType.CLASSIFICATION`.
      learning_rate: Learning rate used for optimization. This argument has no
        effect if `optimizer` is an instance of an `Optimizer`.
      gradient_clipping_norm: A float. Gradients will be clipped to this value.
      dropout_keep_probabilities: a list of dropout keep probabilities or `None`.
        If a list is given, it must have length `len(num_units) + 1`.
      sequence_length_key: The key that will be used to look up sequence length in
        the `features` dict.
      dtype: The dtype of the state and output of the given `cell`.
      parallel_iterations: Number of iterations to run in parallel. Values >> 1
        use more memory but take less time, while smaller values use less memory
        but computations take longer.
      swap_memory: Transparently swap the tensors produced in forward inference
        but needed for back prop from GPU to CPU.  This allows training RNNs
        which would typically not fit on a single GPU, with very minimal (or no)
        performance penalty.
      name: A string that will be used to create a scope for the RNN.
  
    Returns:
      A model function to be passed to an `Estimator`.
  
    Raises:
      ValueError: `problem_type` is not one of
        `ProblemType.LINEAR_REGRESSION` or `ProblemType.CLASSIFICATION`.
      ValueError: `prediction_type` is not one of `PredictionType.SINGLE_VALUE`
        or `PredictionType.MULTIPLE_VALUE`.
      ValueError: `predict_probabilities` is `True` for `problem_type` other
        than `ProblemType.CLASSIFICATION`.
      ValueError: `len(dropout_keep_probabilities)` is not `len(num_units) + 1`.
    """
    if problem_type not in (constants.ProblemType.CLASSIFICATION,
                            constants.ProblemType.LINEAR_REGRESSION):
      raise ValueError(
          'problem_type must be ProblemType.LINEAR_REGRESSION or '
          'ProblemType.CLASSIFICATION; got {}'.
          format(problem_type))
    if prediction_type not in (rnn_common.PredictionType.SINGLE_VALUE,
                               rnn_common.PredictionType.MULTIPLE_VALUE):
      raise ValueError(
          'prediction_type must be PredictionType.MULTIPLE_VALUEs or '
          'PredictionType.SINGLE_VALUE; got {}'.
          format(prediction_type))
    if (problem_type != constants.ProblemType.CLASSIFICATION
        and predict_probabilities):
      raise ValueError(
          'predict_probabilities can only be set to True for problem_type'
          ' ProblemType.CLASSIFICATION; got {}.'.format(problem_type))
    def _dynamic_rnn_model_fn(features, labels, mode):
      """The model to be passed to an `Estimator`."""
      with ops.name_scope(name):
        sequence_length = features.get(sequence_length_key)
        sequence_input = build_sequence_input(features,
                                              sequence_feature_columns,
                                              context_feature_columns)
        dropout = (dropout_keep_probabilities
                   if mode == model_fn.ModeKeys.TRAIN
                   else None)
        # This class promises to use the cell type selected by that function.
        cell = rnn_common.construct_rnn_cell(num_units, cell_type, dropout)
        initial_state = dict_to_state_tuple(features, cell)
        rnn_activations, final_state = construct_rnn(
            initial_state,
            sequence_input,
            cell,
            target_column.num_label_columns,
            dtype=dtype,
            parallel_iterations=parallel_iterations,
            swap_memory=swap_memory)
  
        loss = None  # Created below for modes TRAIN and EVAL.
        if prediction_type == rnn_common.PredictionType.MULTIPLE_VALUE:
          prediction_dict = rnn_common.multi_value_predictions(
              rnn_activations, target_column, problem_type, predict_probabilities)
          if mode != model_fn.ModeKeys.INFER:
            loss = _multi_value_loss(
                rnn_activations, labels, sequence_length, target_column, features)
        elif prediction_type == rnn_common.PredictionType.SINGLE_VALUE:
          prediction_dict = _single_value_predictions(
              rnn_activations, sequence_length, target_column,
              problem_type, predict_probabilities)
          if mode != model_fn.ModeKeys.INFER:
            loss = _single_value_loss(
                rnn_activations, labels, sequence_length, target_column, features)
        state_dict = state_tuple_to_dict(final_state)
        prediction_dict.update(state_dict)
  
        eval_metric_ops = None
        if mode != model_fn.ModeKeys.INFER:
          eval_metric_ops = rnn_common.get_eval_metric_ops(
              problem_type, prediction_type, sequence_length, prediction_dict,
              labels)
  
        train_op = None
        if mode == model_fn.ModeKeys.TRAIN:
          train_op = optimizers.optimize_loss(
              loss=loss,
              global_step=None,  # Get it internally.
              learning_rate=learning_rate,
              optimizer=optimizer,
              clip_gradients=gradient_clipping_norm,
              summaries=optimizers.OPTIMIZER_SUMMARIES)
  
      output_alternatives = _get_output_alternatives(prediction_type,
                                                     problem_type,
                                                     prediction_dict)
  
      return model_fn.ModelFnOps(mode=mode,
                                 predictions=prediction_dict,
                                 loss=loss,
                                 train_op=train_op,
                                 eval_metric_ops=eval_metric_ops,
                                 output_alternatives=output_alternatives)
    return _dynamic_rnn_model_fn
function_tokens: def _get_dynamic_rnn_model_fn ( cell_type , num_units , target_column , problem_type , prediction_type , optimizer , sequence_feature_columns , context_feature_columns = None , predict_probabilities = False , learning_rate = None , gradient_clipping_norm = None , dropout_keep_probabilities = None , sequence_length_key = rnn_common . RNNKeys . SEQUENCE_LENGTH_KEY , dtype = dtypes . float32 , parallel_iterations = None , swap_memory = True , name = 'DynamicRNNModel' ) : if problem_type not in ( constants . ProblemType . CLASSIFICATION , constants . ProblemType . LINEAR_REGRESSION ) : raise ValueError ( 'problem_type must be ProblemType.LINEAR_REGRESSION or ' 'ProblemType.CLASSIFICATION; got {}' . format ( problem_type ) ) if prediction_type not in ( rnn_common . PredictionType . SINGLE_VALUE , rnn_common . PredictionType . MULTIPLE_VALUE ) : raise ValueError ( 'prediction_type must be PredictionType.MULTIPLE_VALUEs or ' 'PredictionType.SINGLE_VALUE; got {}' . format ( prediction_type ) ) if ( problem_type != constants . ProblemType . CLASSIFICATION and predict_probabilities ) : raise ValueError ( 'predict_probabilities can only be set to True for problem_type' ' ProblemType.CLASSIFICATION; got {}.' . format ( problem_type ) ) def _dynamic_rnn_model_fn ( features , labels , mode ) : """The model to be passed to an `Estimator`.""" with ops . name_scope ( name ) : sequence_length = features . get ( sequence_length_key ) sequence_input = build_sequence_input ( features , sequence_feature_columns , context_feature_columns ) dropout = ( dropout_keep_probabilities if mode == model_fn . ModeKeys . TRAIN else None ) # This class promises to use the cell type selected by that function. cell = rnn_common . construct_rnn_cell ( num_units , cell_type , dropout ) initial_state = dict_to_state_tuple ( features , cell ) rnn_activations , final_state = construct_rnn ( initial_state , sequence_input , cell , target_column . num_label_columns , dtype = dtype , parallel_iterations = parallel_iterations , swap_memory = swap_memory ) loss = None # Created below for modes TRAIN and EVAL. if prediction_type == rnn_common . PredictionType . MULTIPLE_VALUE : prediction_dict = rnn_common . multi_value_predictions ( rnn_activations , target_column , problem_type , predict_probabilities ) if mode != model_fn . ModeKeys . INFER : loss = _multi_value_loss ( rnn_activations , labels , sequence_length , target_column , features ) elif prediction_type == rnn_common . PredictionType . SINGLE_VALUE : prediction_dict = _single_value_predictions ( rnn_activations , sequence_length , target_column , problem_type , predict_probabilities ) if mode != model_fn . ModeKeys . INFER : loss = _single_value_loss ( rnn_activations , labels , sequence_length , target_column , features ) state_dict = state_tuple_to_dict ( final_state ) prediction_dict . update ( state_dict ) eval_metric_ops = None if mode != model_fn . ModeKeys . INFER : eval_metric_ops = rnn_common . get_eval_metric_ops ( problem_type , prediction_type , sequence_length , prediction_dict , labels ) train_op = None if mode == model_fn . ModeKeys . TRAIN : train_op = optimizers . optimize_loss ( loss = loss , global_step = None , # Get it internally. learning_rate = learning_rate , optimizer = optimizer , clip_gradients = gradient_clipping_norm , summaries = optimizers . OPTIMIZER_SUMMARIES ) output_alternatives = _get_output_alternatives ( prediction_type , problem_type , prediction_dict ) return model_fn . ModelFnOps ( mode = mode , predictions = prediction_dict , loss = loss , train_op = train_op , eval_metric_ops = eval_metric_ops , output_alternatives = output_alternatives ) return _dynamic_rnn_model_fn