(logits,
                  labels,
                  input_length=None,
                  label_length=None,
                  smoothing=0.0,
                  reduction=tf.losses.Reduction.SUM_BY_NONZERO_WEIGHTS)
return loss
cross entropy function for classfication and seq classfication
  :param, label_length, for seq task, this for target seq length, e.g. a b c </s>, 4
cross entropy function for classfication and seq classfication
  :param, label_length, for seq task, this for target seq length, e.g. a b c </s>, 4
cross entropy function for classfication and seq classfication : param label_length for seq task this for target seq length e . g . a b c < / s > 4
def cross_entropy(logits,
                  labels,
                  input_length=None,
                  label_length=None,
                  smoothing=0.0,
                  reduction=tf.losses.Reduction.SUM_BY_NONZERO_WEIGHTS):
  '''
  cross entropy function for classfication and seq classfication
  :param, label_length, for seq task, this for target seq length, e.g. a b c </s>, 4
  '''
  del input_length

  onehot_labels = tf.cond(
      pred=tf.equal(tf.rank(logits) - tf.rank(labels), 1),
      true_fn=lambda: tf.one_hot(labels, tf.shape(logits)[-1], dtype=tf.int32),
      false_fn=lambda: labels)

  if label_length is not None:
    max_len = tf.shape(logits)[1]
    weights = utils.len_to_mask(label_length, max_len)
  else:
    weights = 1.0

  loss = tf.losses.softmax_cross_entropy(
      onehot_labels=onehot_labels,
      logits=logits,
      weights=weights,
      label_smoothing=smoothing,
      reduction=reduction)

  return loss
def cross_entropy ( logits , labels , input_length = None , label_length = None , smoothing = 0.0 , reduction = tf . losses . Reduction . SUM_BY_NONZERO_WEIGHTS ) : del input_length onehot_labels = tf . cond ( pred = tf . equal ( tf . rank ( logits ) - tf . rank ( labels ) , 1 ) , true_fn = lambda : tf . one_hot ( labels , tf . shape ( logits ) [ - 1 ] , dtype = tf . int32 ) , false_fn = lambda : labels ) if label_length is not None : max_len = tf . shape ( logits ) [ 1 ] weights = utils . len_to_mask ( label_length , max_len ) else : weights = 1.0 loss = tf . losses . softmax_cross_entropy ( onehot_labels = onehot_labels , logits = logits , weights = weights , label_smoothing = smoothing , reduction = reduction ) return loss