class_docstr: Layer that compute attention for BiMPM model.
  
  For detailed information, see Bilateral Multi-Perspective Matching for
  Natural Language Sentences, section 3.2.
  
  Reference:
  https://github.com/zhiguowang/BiMPM/blob/master/src/layer_utils.py#L145-L196
  
  Examples:
      >>> import matchzoo as mz
      >>> layer = mz.contrib.layers.AttentionLayer(att_dim=50)
      >>> layer.compute_output_shape([(32, 10, 100), (32, 40, 100)])
      (32, 10, 40)
class_docstr_tok: ["Layer","that","compute","attention","for","BiMPM","model",".","For","detailed","information",",","see","Bilateral","Multi-Perspective","Matching","for","Natural","Language","Sentences",",","section","3.2",".","Reference",":","https",":","\/\/github.com\/zhiguowang\/BiMPM\/blob\/master\/src\/layer_utils.py","#","L145-L196","Examples",":",">",">",">","import","matchzoo","as","mz",">",">",">","layer","=","mz.contrib.layers.AttentionLayer","(","att_dim=50",")",">",">",">","layer.compute_output_shape","(","[","(","32",",","10",",","100",")",",","(","32",",","40",",","100",")","]",")","(","32",",","10",",","40",")"]
docstr: Calculate attention.
  
  :param x: [reps_lt, reps_rt]
  :return attn_prob: [b, s_lt, s_rt]
docstr_tok: ["Calculate","attention",".",":","param","x",":","[","reps_lt",",","reps_rt","]",":","return","attn_prob",":","[","b",",","s_lt",",","s_rt","]"]
code: def call(self, x: list, **kwargs):
      """
      Calculate attention.
  
      :param x: [reps_lt, reps_rt]
      :return attn_prob: [b, s_lt, s_rt]
      """
  
      if not isinstance(x, list):
          raise ValueError(
              "A attention layer should be called "
              "on a list of inputs."
          )
  
      reps_lt, reps_rt = x
  
      attn_w1 = self.attn_w1
      attn_w1 = tf.expand_dims(tf.expand_dims(attn_w1, axis=0), axis=0)
      # => [1, 1, d, a]
  
      reps_lt = tf.expand_dims(reps_lt, axis=-1)
      attn_reps_lt = tf.reduce_sum(reps_lt * attn_w1, axis=2)
      # => [b, s_lt, d, -1]
  
      attn_w2 = self.attn_w2
      attn_w2 = tf.expand_dims(tf.expand_dims(attn_w2, axis=0), axis=0)
      # => [1, 1, d, a]
  
      reps_rt = tf.expand_dims(reps_rt, axis=-1)
      attn_reps_rt = tf.reduce_sum(
          reps_rt * attn_w2, axis=2
      )  # [b, s_rt, d, -1]
  
      attn_reps_lt = tf.tanh(attn_reps_lt)  # [b, s_lt, a]
      attn_reps_rt = tf.tanh(attn_reps_rt)  # [b, s_rt, a]
  
      # diagonal_W
      attn_reps_lt = attn_reps_lt * self.diagonal_W  # [b, s_lt, a]
      attn_reps_rt = tf.transpose(attn_reps_rt, (0, 2, 1))
      # => [b, a, s_rt]
  
      attn_value = K.batch_dot(
          attn_reps_lt, attn_reps_rt
      )  # [b, s_lt, s_rt]
  
      # Softmax operation
      attn_prob = tf.nn.softmax(attn_value)  # [b, s_lt, s_rt]
  
      # TODO(tjf) remove diagonal or not for normalization
      # if remove_diagonal: attn_value = attn_value * diagonal
  
      if len(x) == 4:
          mask_lt, mask_rt = x[2], x[3]
          attn_prob *= tf.expand_dims(mask_lt, axis=2)
          attn_prob *= tf.expand_dims(mask_rt, axis=1)
  
      return attn_prob
  
file_path: MatchZoo/matchzoo/contrib/layers/attention_layer.py
imports: import tensorflow
  from keras import backend
  from keras.engine import Layer
label_desc: Use image node_id 5 for calling the AttentionLayer obj's underlying member method code with example usage: obj.call(x) and returns: attn_prob