def attention(inputs, state, att_size, mask, scope="<STR_LIT>"):
with tf.variable_scope(scope):<EOL><INDENT>u = tf.concat([tf.tile(tf.expand_dims(state, axis=<NUM_LIT:1>), [<NUM_LIT:1>, tf.shape(inputs)[<NUM_LIT:1>], <NUM_LIT:1>]), inputs], axis=<NUM_LIT:2>)<EOL>logits = tf.layers.dense(tf.layers.dense(u, att_size, activation=tf.nn.tanh), <NUM_LIT:1>, use_bias=False)<EOL>logits = softmax_mask(tf.squeeze(logits, [<NUM_LIT:2>]), mask)<EOL>att_weights = tf.expand_dims(tf.nn.softmax(logits), axis=<NUM_LIT:2>)<EOL>res = tf.reduce_sum(att_weights * inputs, axis=<NUM_LIT:1>)<EOL>return res, logits<EOL><DEDENT>
Computes weighted sum of inputs conditioned on state