class_docstr: Tests the AttentionLayer module.
class_docstr_tok: ["Tests","the","AttentionLayer","module","."]
docstr: Tests Attention layer with a  given score type
docstr_tok: ["Tests","Attention","layer","with","a","given","score","type"]
code: def _test_layer(self):
      """Tests Attention layer with a  given score type"""
      inputs_pl = tf.placeholder(
          tf.float32, (None, None, self.input_dim)
      )
      inputs_length_pl = tf.placeholder(tf.int32, [None])
      state_pl = tf.placeholder(tf.float32, (None, self.state_dim))
      attention_fn = self._create_layer()
      scores, context = attention_fn(
          query=state_pl,
          keys=inputs_pl,
          values=inputs_pl,
          values_length=inputs_length_pl,
      )
  
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          feed_dict = {}
          feed_dict[inputs_pl] = np.random.randn(
              self.batch_size, self.seq_len, self.input_dim
          )
          feed_dict[state_pl] = np.random.randn(
              self.batch_size, self.state_dim
          )
          feed_dict[inputs_length_pl] = np.arange(self.batch_size) + 1
          scores_, context_ = sess.run([scores, context], feed_dict)
  
      np.testing.assert_array_equal(
          scores_.shape, [self.batch_size, self.seq_len]
      )
      np.testing.assert_array_equal(
          context_.shape, [self.batch_size, self.input_dim]
      )
  
      for idx, batch in enumerate(scores_, 1):
          # All scores that are padded should be zero
          np.testing.assert_array_equal(
              batch[idx:], np.zeros_like(batch[idx:])
          )
  
      # Scores should sum to 1
      scores_sum = np.sum(scores_, axis=1)
      np.testing.assert_array_almost_equal(
          scores_sum, np.ones([self.batch_size])
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import tensorflow
  import numpy
  from seq2seq.decoders.attention import AttentionLayerDot
  from seq2seq.decoders.attention import AttentionLayerBahdanau
label_desc: Use image node_id 3 for calling the AttentionLayerTest obj's underlying member method code with example usage: obj._test_layer() without return types