'Tests Attention layer with a  given score type'

def _test_layer(self):

    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):
        np.testing.assert_array_equal(batch[idx:], np.zeros_like(batch[idx:]))
    scores_sum = np.sum(scores_, axis=1)
    np.testing.assert_array_almost_equal(scores_sum, np.ones([self.batch_size]))
