code: def attention(
      targets_shifted, inputs_encoded, norm_fn, hparams, bias=None
  ):
      """Complete attention layer with preprocessing."""
      separabilities = [hparams.separability, hparams.separability]
      if hparams.separability < 0:
          separabilities = [
              hparams.separability - 1,
              hparams.separability,
          ]
      targets_timed = common_layers.subseparable_conv_block(
          common_layers.add_timing_signal(targets_shifted),
          hparams.hidden_size,
          [((1, 1), (5, 1)), ((4, 1), (5, 1))],
          normalizer_fn=norm_fn,
          padding="LEFT",
          separabilities=separabilities,
          name="targets_time",
      )
      if hparams.attention_type == "transformer":
          targets_timed = tf.squeeze(targets_timed, 2)
          target_shape = tf.shape(targets_timed)
          targets_segment = tf.zeros([target_shape[0], target_shape[1]])
          target_attention_bias = (
              common_attention.attention_bias_lower_triangle(
                  target_shape[1]
              )
          )
          inputs_encoded = common_layers.flatten4d3d(inputs_encoded)
          # TODO(jbaccash): use input bias parameter. This code seems to assume fixed
          # size inputs.
          inputs_attention_bias = tf.zeros(
              [
                  tf.shape(inputs_encoded)[0],
                  hparams.num_heads,
                  tf.shape(targets_segment)[1],
                  tf.shape(inputs_encoded)[1],
              ]
          )
  
          qv = common_attention.multihead_attention(
              targets_timed,
              None,
              target_attention_bias,
              hparams.hidden_size,
              hparams.hidden_size,
              hparams.hidden_size,
              hparams.num_heads,
              hparams.attention_dropout,
              name="self_attention",
          )
          qv = common_attention.multihead_attention(
              qv,
              inputs_encoded,
              inputs_attention_bias,
              hparams.hidden_size,
              hparams.hidden_size,
              hparams.hidden_size,
              hparams.num_heads,
              hparams.attention_dropout,
              name="encdec_attention",
          )
          return tf.expand_dims(qv, 2)
      else:
          raise ValueError(
              "Unsupported attention_type: %s" % hparams.attention_type
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from six.moves import range
  from six.moves import zip
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: attention(targets_shifted, inputs_encoded, norm_fn, hparams, bias) and returns: tf