code: def attention_probs_from_attn_state(attention_state):
      """Calculates the average attention probabilities.
  
      Args:
        attention_state: An instance of `AttentionWrapperState`.
  
      Returns:
        The attention probabilities in the given AttentionWrapperState.
        If there're multiple attention mechanisms, return the average value from
        all attention mechanisms.
      """
      # Attention probabilities over time steps, with shape
      # `[batch_size, beam_width, max_time]`.
      attention_probs = attention_state.alignments
      if isinstance(attention_probs, tuple):
          attention_probs = [
              tf.expand_dims(prob, -1) for prob in attention_probs
          ]
          attention_probs = tf.concat(attention_probs, -1)
          attention_probs = tf.reduce_mean(attention_probs, -1)
      return attention_probs
  
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 13 for calling a global function with example usage: attention_probs_from_attn_state(attention_state) and returns: attention_probs