parameters: (features, labels, mode, params, config=None)
docstring: A model_fn for linear models that use a gradient-based optimizer.
  
    Args:
      features: `Tensor` or dict of `Tensor` (depends on data passed to `fit`).
      labels: `Tensor` of shape [batch_size, 1] or [batch_size] labels of
        dtype `int32` or `int64` in the range `[0, n_classes)`.
      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.
        * feature_columns: An iterable containing all the feature columns used by
            the model.
        * optimizer: string, `Optimizer` object, or callable that defines the
            optimizer to use for training. If `None`, will use a FTRL optimizer.
        * gradient_clip_norm: A float > 0. If provided, gradients are
            clipped to their global norm with this clipping ratio.
        * joint_weights: If True, the weights for all columns will be stored in a
          single (possibly partitioned) variable. It's more efficient, but it's
          incompatible with SDCAOptimizer, and requires all feature columns are
          sparse and use the 'sum' combiner.
      config: `RunConfig` object to configure the runtime settings.
  
    Returns:
      A `ModelFnOps` instance.
  
    Raises:
      ValueError: If mode is not any of the `ModeKeys`.
docstring_summary: A model_fn for linear models that use a gradient-based optimizer.
docstring_tokens: A model_fn for linear models that use a gradient - based optimizer .
function: def _linear_model_fn(features, labels, mode, params, config=None):
    """A model_fn for linear models that use a gradient-based optimizer.
  
    Args:
      features: `Tensor` or dict of `Tensor` (depends on data passed to `fit`).
      labels: `Tensor` of shape [batch_size, 1] or [batch_size] labels of
        dtype `int32` or `int64` in the range `[0, n_classes)`.
      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.
        * feature_columns: An iterable containing all the feature columns used by
            the model.
        * optimizer: string, `Optimizer` object, or callable that defines the
            optimizer to use for training. If `None`, will use a FTRL optimizer.
        * gradient_clip_norm: A float > 0. If provided, gradients are
            clipped to their global norm with this clipping ratio.
        * joint_weights: If True, the weights for all columns will be stored in a
          single (possibly partitioned) variable. It's more efficient, but it's
          incompatible with SDCAOptimizer, and requires all feature columns are
          sparse and use the 'sum' combiner.
      config: `RunConfig` object to configure the runtime settings.
  
    Returns:
      A `ModelFnOps` instance.
  
    Raises:
      ValueError: If mode is not any of the `ModeKeys`.
    """
    head = params["head"]
    feature_columns = params["feature_columns"]
    optimizer = params.get("optimizer") or _get_default_optimizer(feature_columns)
    gradient_clip_norm = params.get("gradient_clip_norm", None)
    num_ps_replicas = config.num_ps_replicas if config else 0
    joint_weights = params.get("joint_weights", False)
  
    if not isinstance(features, dict):
      features = {"": features}
  
    parent_scope = "linear"
    partitioner = partitioned_variables.min_max_variable_partitioner(
        max_partitions=num_ps_replicas,
        min_slice_size=64 << 20)
  
    with variable_scope.variable_scope(
        parent_scope,
        values=tuple(six.itervalues(features)),
        partitioner=partitioner) as scope:
      if all([isinstance(fc, feature_column._FeatureColumn)  # pylint: disable=protected-access
              for fc in feature_columns]):
        if joint_weights:
          layer_fn = layers.joint_weighted_sum_from_feature_columns
        else:
          layer_fn = layers.weighted_sum_from_feature_columns
        logits, _, _ = layer_fn(
            columns_to_tensors=features,
            feature_columns=feature_columns,
            num_outputs=head.logits_dimension,
            weight_collections=[parent_scope],
            scope=scope)
      else:
        logits = fc_core.linear_model(
            features=features,
            feature_columns=feature_columns,
            units=head.logits_dimension,
            weight_collections=[parent_scope])
  
      def _train_op_fn(loss):
        global_step = contrib_variables.get_global_step()
        my_vars = ops.get_collection(parent_scope)
        grads = gradients.gradients(loss, my_vars)
        if gradient_clip_norm:
          grads, _ = clip_ops.clip_by_global_norm(grads, gradient_clip_norm)
        return (_get_optimizer(optimizer).apply_gradients(
            zip(grads, my_vars), global_step=global_step))
  
      return head.create_model_fn_ops(
          features=features,
          mode=mode,
          labels=labels,
          train_op_fn=_train_op_fn,
          logits=logits)
function_tokens: def _linear_model_fn ( features , labels , mode , params , config = None ) : head = params [ "head" ] feature_columns = params [ "feature_columns" ] optimizer = params . get ( "optimizer" ) or _get_default_optimizer ( feature_columns ) gradient_clip_norm = params . get ( "gradient_clip_norm" , None ) num_ps_replicas = config . num_ps_replicas if config else 0 joint_weights = params . get ( "joint_weights" , False ) if not isinstance ( features , dict ) : features = { "" : features } parent_scope = "linear" partitioner = partitioned_variables . min_max_variable_partitioner ( max_partitions = num_ps_replicas , min_slice_size = 64 << 20 ) with variable_scope . variable_scope ( parent_scope , values = tuple ( six . itervalues ( features ) ) , partitioner = partitioner ) as scope : if all ( [ isinstance ( fc , feature_column . _FeatureColumn ) # pylint: disable=protected-access for fc in feature_columns ] ) : if joint_weights : layer_fn = layers . joint_weighted_sum_from_feature_columns else : layer_fn = layers . weighted_sum_from_feature_columns logits , _ , _ = layer_fn ( columns_to_tensors = features , feature_columns = feature_columns , num_outputs = head . logits_dimension , weight_collections = [ parent_scope ] , scope = scope ) else : logits = fc_core . linear_model ( features = features , feature_columns = feature_columns , units = head . logits_dimension , weight_collections = [ parent_scope ] ) def _train_op_fn ( loss ) : global_step = contrib_variables . get_global_step ( ) my_vars = ops . get_collection ( parent_scope ) grads = gradients . gradients ( loss , my_vars ) if gradient_clip_norm : grads , _ = clip_ops . clip_by_global_norm ( grads , gradient_clip_norm ) return ( _get_optimizer ( optimizer ) . apply_gradients ( zip ( grads , my_vars ) , global_step = global_step ) ) return head . create_model_fn_ops ( features = features , mode = mode , labels = labels , train_op_fn = _train_op_fn , logits = logits )