code: def sequence_loss(
      logits,
      targets,
      weights,
      average_across_timesteps=True,
      average_across_batch=True,
      softmax_loss_function=None,
      name=None,
  ):
      """Weighted cross-entropy loss for a sequence of logits, batch-collapsed.
  
      Args:
          logits: List of 2D Tensors of shape [batch_size x num_decoder_symbols].
          targets: List of 1D batch-sized int32 Tensors of the same length as logits.
          weights: List of 1D batch-sized float-Tensors of the same length as logits.
          average_across_timesteps: If set, divide the returned cost by the total
              label weight.
          average_across_batch: If set, divide the returned cost by the batch size.
          softmax_loss_function: Function (inputs-batch, labels-batch) -> loss-batch
              to be used instead of the standard softmax (the default if this is None).
          name: Optional name for this operation, defaults to "sequence_loss".
  
      Returns:
          A scalar float Tensor: The average log-perplexity per symbol (weighted).
  
      Raises:
          ValueError: If len(logits) is different from len(targets) or len(weights).
      """
      with tf.compat.v1.name_scope(
          name, "sequence_loss", logits + targets + weights
      ):
          cost = tf.reduce_sum(
              sequence_loss_by_example(
                  logits,
                  targets,
                  weights,
                  average_across_timesteps=average_across_timesteps,
                  softmax_loss_function=softmax_loss_function,
              )
          )
          if average_across_batch:
              batch_size = tf.shape(targets[0])[0]
              return cost / tf.cast(batch_size, tf.float32)
  
          return cost
  
file_path: attention-ocr/aocr/model/seq2seq.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from six.moves import xrange
  from six.moves import zip
  import tensorflow
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import init_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.util import nest
label_desc: Use image node_id 6 for calling a global function with example usage: sequence_loss(logits, targets, weights, average_across_timesteps, average_across_batch, softmax_loss_function, name) and returns: cost, unknown