class_docstr: Basic attention cell wrapper.
  
  Implementation based on https://arxiv.org/abs/1601.06733.
class_docstr_tok: ["Basic","attention","cell","wrapper",".","Implementation","based","on","https",":","\/\/arxiv.org\/abs\/1601.06733","."]
code: def _attention(self, query, attn_states):
      conv2d = tf.nn.conv2d
      reduce_sum = tf.math.reduce_sum
      softmax = tf.nn.softmax
      tanh = tf.math.tanh
  
      with tf.variable_scope("attention"):
          k = tf.get_variable(
              "attn_w", [1, 1, self._attn_size, self._attn_vec_size]
          )
          v = tf.get_variable("attn_v", [self._attn_vec_size])
          hidden = tf.reshape(
              attn_states, [-1, self._attn_length, 1, self._attn_size]
          )
          hidden_features = conv2d(hidden, k, [1, 1, 1, 1], "SAME")
          if self._linear3 is None:
              self._linear3 = _Linear(query, self._attn_vec_size, True)
          y = self._linear3(query)
          y = tf.reshape(y, [-1, 1, 1, self._attn_vec_size])
          s = reduce_sum(v * tanh(hidden_features + y), [2, 3])
          a = softmax(s)
          d = reduce_sum(
              tf.reshape(a, [-1, self._attn_length, 1, 1]) * hidden,
              [1, 2],
          )
          new_attns = tf.reshape(d, [-1, self._attn_size])
          new_attn_states = tf.slice(
              attn_states, [0, 1, 0], [-1, -1, -1]
          )
          return new_attns, new_attn_states
  
imports: import tensorflow.compat.v1
  import tf_slim
  from tensorflow.python.ops import gen_nn_ops
label_desc: Use image node_id 5 for calling the AttentionCellWrapper obj's underlying member method code with example usage: obj._attention(query, attn_states) and returns: new_attns,  new_attn_states