import tensorflow as tf

        vocab_dist: [batch_size, vsize]
        attn_dist: [batch_size, passage_length]
        p_gen: [batch_size, 1]
        passage_word_idx: [batch_size, passage_length]
        passage_mask: [batch_size, passage_length]
        '''
        input_shape = tf.shape(vocab_dist)
        batch_size = input_shape[0]
        vsize = input_shape[1]
        passage_length = tf.shape(passage_word_idx)[1]

        with tf.variable_scope('final_distribution'):
            vocab_dist = p_gen * vocab_dist
            attn_dist = (1.0-p_gen) * attn_dist

            # Concatenate some zeros to each vocabulary dist, to hold the probabilities for phrases
            extended_vsize = vsize
            if self.max_phrase_size is not None:
                extended_vsize += self.max_phrase_size
                extra_zeros = tf.zeros((batch_size, self.max_phrase_size))
                vocab_dist = tf.concat(values=[vocab_dist, extra_zeros], axis=1) # [batch_size, extended_vsize]
                if self.options.add_first_word_prob_for_phrase: # add prob of the first word to each phrase
