def dot_attention(inputs, memory, mask, att_size, keep_prob=<NUM_LIT:1.0>, scope="<STR_LIT>"):
with tf.variable_scope(scope):<EOL><INDENT>BS, IL, IH = tf.unstack(tf.shape(inputs))<EOL>BS, ML, MH = tf.unstack(tf.shape(memory))<EOL>d_inputs = tf.nn.dropout(inputs, keep_prob=keep_prob, noise_shape=[BS, <NUM_LIT:1>, IH])<EOL>d_memory = tf.nn.dropout(memory, keep_prob=keep_prob, noise_shape=[BS, <NUM_LIT:1>, MH])<EOL>with tf.variable_scope("<STR_LIT>"):<EOL><INDENT>inputs_att = tf.layers.dense(d_inputs, att_size, use_bias=False, activation=tf.nn.relu)<EOL>memory_att = tf.layers.dense(d_memory, att_size, use_bias=False, activation=tf.nn.relu)<EOL>logits = tf.matmul(inputs_att, tf.transpose(memory_att, [<NUM_LIT:0>, <NUM_LIT:2>, <NUM_LIT:1>])) / (att_size ** <NUM_LIT:0.5>)<EOL>mask = tf.tile(tf.expand_dims(mask, axis=<NUM_LIT:1>), [<NUM_LIT:1>, IL, <NUM_LIT:1>])<EOL>att_weights = tf.nn.softmax(softmax_mask(logits, mask))<EOL>outputs = tf.matmul(att_weights, memory)<EOL>res = tf.concat([inputs, outputs], axis=<NUM_LIT:2>)<EOL><DEDENT>with tf.variable_scope("<STR_LIT>"):<EOL><INDENT>dim = res.get_shape().as_list()[-<NUM_LIT:1>]<EOL>d_res = tf.nn.dropout(res, keep_prob=keep_prob, noise_shape=[BS, <NUM_LIT:1>, IH + MH])<EOL>gate = tf.layers.dense(d_res, dim, use_bias=False, activation=tf.nn.sigmoid)<EOL>return res * gate<EOL><DEDENT><DEDENT>
Computes attention vector for each item in inputs:
       attention vector is a weighted sum of memory items.
       Dot product between input and memory vector is used as similarity measure.

       Gate mechanism is applied to attention vectors to produce output.

    Args:
        inputs: Tensor [batch_size x input_len x feature_size]
        memory: Tensor [batch_size x memory_len x feature_size]
        mask: inputs mask
        att_size: hidden size of attention
        keep_prob: dropout keep_prob
        scope:

    Returns:
        attention vectors [batch_size x input_len x (feature_size + feature_size)]