import tensorflow as tf

            batch_nums = tf.expand_dims(batch_nums, axis=1) # shape (batch_size, 1)
            batch_nums = tf.tile(batch_nums, [1, passage_length]) # shape (batch_size, passage_length)
            step_nums = tf.range(0, limit=passage_length) # [passage_length]
            step_nums = tf.expand_dims(step_nums, axis=0) # shape (1, passage_length)
            step_nums = tf.tile(step_nums, [batch_size, 1]) # shape (batch_size, passage_length)
            indices = tf.stack((batch_nums, step_nums, passage_word_idx), axis=2) # shape (batch_size, passage_length, 3)
            indices = tf.reshape(indices, [-1, 3]) #[batch_size * passage_length, 3]
            indices = tf.cast(indices, tf.int64)

            shape = [batch_size, passage_length, extended_vsize]
            shape = tf.cast(shape, tf.int64)

            attn_dist = tf.reshape(attn_dist, shape=[-1]) # [batch_size*passage_length]
            one_hot_spare_rep = tf.SparseTensor(indices=indices, values=attn_dist, dense_shape=shape) # [batch_size, passage_length, extended_vsize]

            if passage_mask is not None:
                passage_mask = tf.expand_dims(passage_mask, axis=-1)
                one_hot_spare_rep = one_hot_spare_rep * passage_mask

            one_hot_spare_rep = tf.sparse_reduce_sum(one_hot_spare_rep, axis=1) # [batch_size, extended_vsize]
            vocab_dist = tf.add(vocab_dist, one_hot_spare_rep)

            if self.options.add_first_word_prob_for_phrase:
                vocab_dist = tf.nn.softmax(vocab_dist) # normalize

        return vocab_dist # [batch_size, extended_vsize]
