parameters: (targets, loss_fns, output_shapes)
docstring: Does validation on the compatibility of targets and loss functions.
  
    This helps prevent users from using loss functions incorrectly.
  
    Arguments:
        targets: list of Numpy arrays of targets.
        loss_fns: list of loss functions.
        output_shapes: list of shapes of model outputs.
  
    Raises:
        ValueError: if a loss function or target array
            is incompatible with an output.
docstring_summary: Does validation on the compatibility of targets and loss functions.
docstring_tokens: Does validation on the compatibility of targets and loss functions .
function: def _check_loss_and_target_compatibility(targets, loss_fns, output_shapes):
    """Does validation on the compatibility of targets and loss functions.
  
    This helps prevent users from using loss functions incorrectly.
  
    Arguments:
        targets: list of Numpy arrays of targets.
        loss_fns: list of loss functions.
        output_shapes: list of shapes of model outputs.
  
    Raises:
        ValueError: if a loss function or target array
            is incompatible with an output.
    """
    key_losses = {
        'mean_squared_error', 'binary_crossentropy', 'categorical_crossentropy'
    }
    for y, loss, shape in zip(targets, loss_fns, output_shapes):
      if loss is None:
        continue
      if loss.__name__ == 'categorical_crossentropy':
        if y.shape[-1] == 1:
          raise ValueError('You are passing a target array of shape ' + str(
              y.shape) + ' while using as loss `categorical_crossentropy`. '
                           '`categorical_crossentropy` expects '
                           'targets to be binary matrices (1s and 0s) '
                           'of shape (samples, classes). '
                           'If your targets are integer classes, '
                           'you can convert them to the expected format via:\n'
                           '```\n'
                           'from keras.utils.np_utils import to_categorical\n'
                           'y_binary = to_categorical(y_int)\n'
                           '```\n'
                           '\n'
                           'Alternatively, you can use the loss function '
                           '`sparse_categorical_crossentropy` instead, '
                           'which does expect integer targets.')
      if loss.__name__ in key_losses:
        for target_dim, out_dim in zip(y.shape[1:], shape[1:]):
          if out_dim is not None and target_dim != out_dim:
            raise ValueError('A target array with shape ' + str(y.shape) +
                             ' was passed for an output of shape ' + str(shape) +
                             ' while using as loss `' + loss.__name__ + '`. '
                             'This loss expects '
                             'targets to have the same shape '
                             'as the output.')
function_tokens: def _check_loss_and_target_compatibility ( targets , loss_fns , output_shapes ) : key_losses = { 'mean_squared_error' , 'binary_crossentropy' , 'categorical_crossentropy' } for y , loss , shape in zip ( targets , loss_fns , output_shapes ) : if loss is None : continue if loss . __name__ == 'categorical_crossentropy' : if y . shape [ - 1 ] == 1 : raise ValueError ( 'You are passing a target array of shape ' + str ( y . shape ) + ' while using as loss `categorical_crossentropy`. ' '`categorical_crossentropy` expects ' 'targets to be binary matrices (1s and 0s) ' 'of shape (samples, classes). ' 'If your targets are integer classes, ' 'you can convert them to the expected format via:\n' '```\n' 'from keras.utils.np_utils import to_categorical\n' 'y_binary = to_categorical(y_int)\n' '```\n' '\n' 'Alternatively, you can use the loss function ' '`sparse_categorical_crossentropy` instead, ' 'which does expect integer targets.' ) if loss . __name__ in key_losses : for target_dim , out_dim in zip ( y . shape [ 1 : ] , shape [ 1 : ] ) : if out_dim is not None and target_dim != out_dim : raise ValueError ( 'A target array with shape ' + str ( y . shape ) + ' was passed for an output of shape ' + str ( shape ) + ' while using as loss `' + loss . __name__ + '`. ' 'This loss expects ' 'targets to have the same shape ' 'as the output.' )