parameters: (features, labels, mode, params, config=None)
return_statement: return model_fn_ops
docstring: A model_fn for linear models that use the SDCA optimizer.
  
    Args:
      features: A dict of `Tensor` keyed by column name.
      labels: `Tensor` of shape [batch_size, 1] or [batch_size] labels of
        dtype `int32` or `int64` with values in the set {0, 1}.
      mode: Defines whether this is training, evaluation or prediction.
        See `ModeKeys`.
      params: A dict of hyperparameters.
        The following hyperparameters are expected:
        * head: A `Head` instance. Type must be one of `_BinarySvmHead`,
            `_RegressionHead` or `_BinaryLogisticHead`.
        * feature_columns: An iterable containing all the feature columns used by
            the model.
        * l1_regularization: Global (across all examples) L1-regularization
            parameter.
        * l2_regularization: Global (across all examples) L2-regularization
            parameter.
        * num_loss_partitions: Number of partitions of the global loss function
            optimized by `SDCAOptimizer`.
        * weight_column_name: A string defining the weight feature column, or
            None if there are no weights.
        * update_weights_hook: A `SessionRunHook` object or None. Used to update
            model weights.
      config: `RunConfig` object to configure the runtime settings.
  
    Returns:
      A `ModelFnOps` instance.
  
    Raises:
      ValueError: If the type of head is not one of `_BinarySvmHead`,
        `_RegressionHead` or `_MultiClassHead`.
      ValueError: If mode is not any of the `ModeKeys`.
docstring_summary: A model_fn for linear models that use the SDCA optimizer.
docstring_tokens: A model_fn for linear models that use the SDCA optimizer .
function: def sdca_model_fn(features, labels, mode, params, config=None):
    """A model_fn for linear models that use the SDCA optimizer.
  
    Args:
      features: A dict of `Tensor` keyed by column name.
      labels: `Tensor` of shape [batch_size, 1] or [batch_size] labels of
        dtype `int32` or `int64` with values in the set {0, 1}.
      mode: Defines whether this is training, evaluation or prediction.
        See `ModeKeys`.
      params: A dict of hyperparameters.
        The following hyperparameters are expected:
        * head: A `Head` instance. Type must be one of `_BinarySvmHead`,
            `_RegressionHead` or `_BinaryLogisticHead`.
        * feature_columns: An iterable containing all the feature columns used by
            the model.
        * l1_regularization: Global (across all examples) L1-regularization
            parameter.
        * l2_regularization: Global (across all examples) L2-regularization
            parameter.
        * num_loss_partitions: Number of partitions of the global loss function
            optimized by `SDCAOptimizer`.
        * weight_column_name: A string defining the weight feature column, or
            None if there are no weights.
        * update_weights_hook: A `SessionRunHook` object or None. Used to update
            model weights.
      config: `RunConfig` object to configure the runtime settings.
  
    Returns:
      A `ModelFnOps` instance.
  
    Raises:
      ValueError: If the type of head is not one of `_BinarySvmHead`,
        `_RegressionHead` or `_MultiClassHead`.
      ValueError: If mode is not any of the `ModeKeys`.
    """
    head = params["head"]
    feature_columns = params["feature_columns"]
    example_id_column = params["example_id_column"]
    l1_regularization = params["l1_regularization"]
    l2_regularization = params["l2_regularization"]
    num_loss_partitions = params["num_loss_partitions"]
    weight_column_name = params["weight_column_name"]
    update_weights_hook = params.get("update_weights_hook", None)
    partitioner = params["partitioner"]
  
    loss_type = None
    if isinstance(head, head_lib._BinarySvmHead):  # pylint: disable=protected-access
      loss_type = "hinge_loss"
    elif isinstance(head, head_lib._BinaryLogisticHead):  # pylint: disable=protected-access
      loss_type = "logistic_loss"
    elif isinstance(head, head_lib._RegressionHead):  # pylint: disable=protected-access
      loss_type = "squared_loss"
    else:
      raise ValueError("Unsupported head type: {}".format(type(head)))
  
    assert head.logits_dimension == 1, (
        "SDCA only applies to logits_dimension=1.")
  
    # Update num_loss_partitions based on number of workers.
    n_loss_partitions = num_loss_partitions or max(1, config.num_worker_replicas)
    optimizer = sdca_optimizer.SDCAOptimizer(
        example_id_column=example_id_column,
        num_loss_partitions=n_loss_partitions,
        symmetric_l1_regularization=l1_regularization,
        symmetric_l2_regularization=l2_regularization,
        partitioner=partitioner)
  
    parent_scope = "linear"
  
    with variable_scope.variable_scope(
        values=features.values(), name_or_scope=parent_scope,
        partitioner=partitioner) as scope:
      features = features.copy()
      features.update(layers.transform_features(features, feature_columns))
      logits, columns_to_variables, bias = (
          layers.weighted_sum_from_feature_columns(
              columns_to_tensors=features,
              feature_columns=feature_columns,
              num_outputs=1,
              scope=scope))
  
      _add_bias_column(feature_columns, features, bias, columns_to_variables)
  
    def _train_op_fn(unused_loss):
      global_step = training_util.get_global_step()
      sdca_model, train_op = optimizer.get_train_step(
          columns_to_variables, weight_column_name, loss_type, features, labels,
          global_step)
      if update_weights_hook is not None:
        update_weights_hook.set_parameters(sdca_model, train_op)
      return train_op
  
    model_fn_ops = head.create_model_fn_ops(
        features=features,
        labels=labels,
        mode=mode,
        train_op_fn=_train_op_fn,
        logits=logits)
    if update_weights_hook is not None:
      return model_fn_ops._replace(training_chief_hooks=(
          model_fn_ops.training_chief_hooks + [update_weights_hook]))
    return model_fn_ops
function_tokens: def sdca_model_fn ( features , labels , mode , params , config = None ) : head = params [ "head" ] feature_columns = params [ "feature_columns" ] example_id_column = params [ "example_id_column" ] l1_regularization = params [ "l1_regularization" ] l2_regularization = params [ "l2_regularization" ] num_loss_partitions = params [ "num_loss_partitions" ] weight_column_name = params [ "weight_column_name" ] update_weights_hook = params . get ( "update_weights_hook" , None ) partitioner = params [ "partitioner" ] loss_type = None if isinstance ( head , head_lib . _BinarySvmHead ) : # pylint: disable=protected-access loss_type = "hinge_loss" elif isinstance ( head , head_lib . _BinaryLogisticHead ) : # pylint: disable=protected-access loss_type = "logistic_loss" elif isinstance ( head , head_lib . _RegressionHead ) : # pylint: disable=protected-access loss_type = "squared_loss" else : raise ValueError ( "Unsupported head type: {}" . format ( type ( head ) ) ) assert head . logits_dimension == 1 , ( "SDCA only applies to logits_dimension=1." ) # Update num_loss_partitions based on number of workers. n_loss_partitions = num_loss_partitions or max ( 1 , config . num_worker_replicas ) optimizer = sdca_optimizer . SDCAOptimizer ( example_id_column = example_id_column , num_loss_partitions = n_loss_partitions , symmetric_l1_regularization = l1_regularization , symmetric_l2_regularization = l2_regularization , partitioner = partitioner ) parent_scope = "linear" with variable_scope . variable_scope ( values = features . values ( ) , name_or_scope = parent_scope , partitioner = partitioner ) as scope : features = features . copy ( ) features . update ( layers . transform_features ( features , feature_columns ) ) logits , columns_to_variables , bias = ( layers . weighted_sum_from_feature_columns ( columns_to_tensors = features , feature_columns = feature_columns , num_outputs = 1 , scope = scope ) ) _add_bias_column ( feature_columns , features , bias , columns_to_variables ) def _train_op_fn ( unused_loss ) : global_step = training_util . get_global_step ( ) sdca_model , train_op = optimizer . get_train_step ( columns_to_variables , weight_column_name , loss_type , features , labels , global_step ) if update_weights_hook is not None : update_weights_hook . set_parameters ( sdca_model , train_op ) return train_op model_fn_ops = head . create_model_fn_ops ( features = features , labels = labels , mode = mode , train_op_fn = _train_op_fn , logits = logits ) if update_weights_hook is not None : return model_fn_ops . _replace ( training_chief_hooks = ( model_fn_ops . training_chief_hooks + [ update_weights_hook ] ) ) return model_fn_ops