'Reverses the words in each utterance inside a sequence of utterance (e.g. a dialogue)
This is used for the bidirectional encoder RNN.'

def reverse_utterances(self, seq):

    reversed_seq = numpy.copy(seq)
    for idx in range(seq.shape[1]):
        eos_indices = numpy.where((seq[:, idx] == self.eos_sym))[0]
        prev_eos_index = (-1)
        for eos_index in eos_indices:
            reversed_seq[(prev_eos_index + 1):eos_index, idx] = reversed_seq[(prev_eos_index + 1):eos_index, idx][::(-1)]
            prev_eos_index = eos_index
    return reversed_seq
