parameters: (
      model,
      x,
      y=None,
      sample_weight=None,
      class_weight=None,
      reset_metrics=True)
return_statement: return outputs
docstring: Runs a single gradient update on a single batch of data.
  
    Arguments:
        model: The model to train.
        x: Input data. It could be:
          - A Numpy array (or array-like), or a list of arrays
              (in case the model has multiple inputs).
          - A TensorFlow tensor, or a list of tensors
              (in case the model has multiple inputs).
          - A dict mapping input names to the corresponding array/tensors,
              if the model has named inputs.
          - A `tf.data` dataset.
        y: Target data. Like the input data `x`, it could be either Numpy
          array(s) or TensorFlow tensor(s). It should be consistent with `x`
          (you cannot have Numpy inputs and tensor targets, or inversely). If
          `x` is a dataset `y` should not be specified
          (since targets will be obtained from the iterator).
        sample_weight: Optional array of the same length as x, containing
          weights to apply to the model's loss for each sample. In the case of
          temporal data, you can pass a 2D array with shape (samples,
          sequence_length), to apply a different weight to every timestep of
          every sample. In this case you should make sure to specify
          sample_weight_mode="temporal" in compile(). This argument is not
          supported when `x` is a dataset.
        class_weight: Optional dictionary mapping class indices (integers) to a
          weight (float) to apply to the model's loss for the samples from this
          class during training. This can be useful to tell the model to "pay
          more attention" to samples from an under-represented class.
        reset_metrics: If `True`, the metrics returned will be only for this
          batch. If `False`, the metrics will be statefully accumulated across
          batches.
  
    Returns:
        Scalar training loss
        (if the model has a single output and no metrics)
        or list of scalars (if the model has multiple outputs
        and/or metrics). The attribute `model.metrics_names` will give you
        the display labels for the scalar outputs.
  
    Raises:
      ValueError: In case of invalid user-provided arguments.
docstring_summary: Runs a single gradient update on a single batch of data.
docstring_tokens: Runs a single gradient update on a single batch of data .
function: def train_on_batch(
      model,
      x,
      y=None,
      sample_weight=None,
      class_weight=None,
      reset_metrics=True):
    """Runs a single gradient update on a single batch of data.
  
    Arguments:
        model: The model to train.
        x: Input data. It could be:
          - A Numpy array (or array-like), or a list of arrays
              (in case the model has multiple inputs).
          - A TensorFlow tensor, or a list of tensors
              (in case the model has multiple inputs).
          - A dict mapping input names to the corresponding array/tensors,
              if the model has named inputs.
          - A `tf.data` dataset.
        y: Target data. Like the input data `x`, it could be either Numpy
          array(s) or TensorFlow tensor(s). It should be consistent with `x`
          (you cannot have Numpy inputs and tensor targets, or inversely). If
          `x` is a dataset `y` should not be specified
          (since targets will be obtained from the iterator).
        sample_weight: Optional array of the same length as x, containing
          weights to apply to the model's loss for each sample. In the case of
          temporal data, you can pass a 2D array with shape (samples,
          sequence_length), to apply a different weight to every timestep of
          every sample. In this case you should make sure to specify
          sample_weight_mode="temporal" in compile(). This argument is not
          supported when `x` is a dataset.
        class_weight: Optional dictionary mapping class indices (integers) to a
          weight (float) to apply to the model's loss for the samples from this
          class during training. This can be useful to tell the model to "pay
          more attention" to samples from an under-represented class.
        reset_metrics: If `True`, the metrics returned will be only for this
          batch. If `False`, the metrics will be statefully accumulated across
          batches.
  
    Returns:
        Scalar training loss
        (if the model has a single output and no metrics)
        or list of scalars (if the model has multiple outputs
        and/or metrics). The attribute `model.metrics_names` will give you
        the display labels for the scalar outputs.
  
    Raises:
      ValueError: In case of invalid user-provided arguments.
    """
    model._assert_compile_was_called()
  
    # TODO(scottzhu): Standardization should happen in the data handlers,
    ## not on a per batch basis in the *_on_batch methods
    # Validate and standardize user data.
    x, y, sample_weights = model._standardize_user_data(
        x, y, sample_weight=sample_weight, class_weight=class_weight,
        extract_tensors_from_dataset=True)
    batch_size = array_ops.shape(nest.flatten(x, expand_composites=True)[0])[0]
    # If `model._distribution_strategy` is True, then we are in a replica context
    # at this point because of the check above.  `train_on_batch` is being run
    # for each replica by `model._distribution_strategy` and the same code path
    # as Eager is expected to be taken.
    outputs = training_eager.train_on_batch(
        model,
        x,
        y,
        sample_weights=sample_weights,
        output_loss_metrics=model._output_loss_metrics)
  
    if reset_metrics:
      model.reset_metrics()
  
    outputs['batch_size'] = math_ops.cast(batch_size, dtypes.int64)
    return outputs
function_tokens: def train_on_batch ( model , x , y = None , sample_weight = None , class_weight = None , reset_metrics = True ) : model . _assert_compile_was_called ( ) # TODO(scottzhu): Standardization should happen in the data handlers, ## not on a per batch basis in the *_on_batch methods # Validate and standardize user data. x , y , sample_weights = model . _standardize_user_data ( x , y , sample_weight = sample_weight , class_weight = class_weight , extract_tensors_from_dataset = True ) batch_size = array_ops . shape ( nest . flatten ( x , expand_composites = True ) [ 0 ] ) [ 0 ] # If `model._distribution_strategy` is True, then we are in a replica context # at this point because of the check above.  `train_on_batch` is being run # for each replica by `model._distribution_strategy` and the same code path # as Eager is expected to be taken. outputs = training_eager . train_on_batch ( model , x , y , sample_weights = sample_weights , output_loss_metrics = model . _output_loss_metrics ) if reset_metrics : model . reset_metrics ( ) outputs [ 'batch_size' ] = math_ops . cast ( batch_size , dtypes . int64 ) return outputs