code: def _length_penalty(sequence_lengths, penalty_factor):
      """Calculates the length penalty. See https://arxiv.org/abs/1609.08144.
  
      Returns the length penalty tensor:
      ```
      [(5+sequence_lengths)/6]**penalty_factor
      ```
      where all operations are performed element-wise.
  
      Args:
        sequence_lengths: `Tensor`, the sequence lengths of each hypotheses.
        penalty_factor: A scalar that weights the length penalty.
  
      Returns:
        If the penalty is `0`, returns the scalar `1.0`.  Otherwise returns
        the length penalty factor, a tensor with the same shape as
        `sequence_lengths`.
      """
      penalty_factor = tf.convert_to_tensor(
          penalty_factor, name="penalty_factor"
      )
      penalty_factor.set_shape(())  # penalty should be a scalar.
      static_penalty = tf.get_static_value(penalty_factor)
      if static_penalty is not None and static_penalty == 0:
          return 1.0
      return tf.math.divide(
          (5.0 + tf.cast(sequence_lengths, tf.float32))
          ** penalty_factor,
          (5.0 + 1.0) ** penalty_factor,
      )
  
imports: import collections
  import numpy
  import tensorflow
  from tensorflow_addons import options
  from tensorflow_addons.seq2seq import attention_wrapper
  from tensorflow_addons.seq2seq import decoder
  from tensorflow_addons.utils import keras_utils
  from tensorflow_addons.utils.resource_loader import LazySO
  from tensorflow_addons.utils.types import FloatTensorLike, TensorLike, Number
  from typeguard import typechecked
  from typing import Callable, Optional
label_desc: Use image node_id 14 for calling a global function with example usage: _length_penalty(sequence_lengths, penalty_factor) and returns: tf, int