code: def create_attention_mechanism(
      attention_option, num_units, memory, source_sequence_length, mode
  ):
      """Create attention mechanism based on the attention_option."""
      del mode  # unused
  
      # Mechanism
      if attention_option == "luong":
          attention_mechanism = tf.contrib.seq2seq.LuongAttention(
              num_units,
              memory,
              memory_sequence_length=source_sequence_length,
          )
      elif attention_option == "scaled_luong":
          attention_mechanism = tf.contrib.seq2seq.LuongAttention(
              num_units,
              memory,
              memory_sequence_length=source_sequence_length,
              scale=True,
          )
      elif attention_option == "bahdanau":
          attention_mechanism = tf.contrib.seq2seq.BahdanauAttention(
              num_units,
              memory,
              memory_sequence_length=source_sequence_length,
          )
      elif attention_option == "normed_bahdanau":
          attention_mechanism = tf.contrib.seq2seq.BahdanauAttention(
              num_units,
              memory,
              memory_sequence_length=source_sequence_length,
              normalize=True,
          )
      else:
          raise ValueError(
              "Unknown attention option %s" % attention_option
          )
  
      return attention_mechanism
  
file_path: nlp-architect/examples/sparse_gnmt/gnmt/attention_model.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
  from .None import model
  from .None import model_helper
label_desc: Use image node_id 1 for calling a global function with example usage: create_attention_mechanism(attention_option, num_units, memory, source_sequence_length, mode) and returns: attention_mechanism