def _attention_pool(question_emb, question_mask):
  """Reduce variable length question embeddings to fixed length via attention.

  Args:
    question_emb: <float32> [batch_size, max_question_len, hidden_size]
    question_mask: <float32> [batch_size, max_question_len]

  Returns:
    pooled_emb: <float32> [batch_size, hidden_size]
  """
  # [batch_size, max_question_len, 1]
  attention_scores = tf.layers.dense(question_emb, 1)
  attention_scores += tf.expand_dims(tf.log(question_mask), -1)
  attention_weights = tf.nn.softmax(attention_scores, 1)

  # [batch_size, 1, hidden_size]
  pooled_emb = tf.matmul(attention_weights, question_emb, transpose_a=True)

  # [batch_size, hidden_size]
  pooled_emb = tf.squeeze(pooled_emb, 1)
  return pooled_emb
Reduce variable length question embeddings to fixed length via attention.

  Args:
    question_emb: <float32> [batch_size, max_question_len, hidden_size]
    question_mask: <float32> [batch_size, max_question_len]

  Returns:
    pooled_emb: <float32> [batch_size, hidden_size]
  
language/question_answering/decatt_docreader/layers/document_reader.py