def save_predictions(args, predictions, output_file, text_file, idx_file, output_word_prediction=False):
    with open(text_file, 'r') as text_reader, open(idx_file, 'r') as idx_reader:
        text = text_reader.readlines()
        index = idx_reader.readlines()
        assert (len(text) == len(index))
    with open(output_file, 'w') as writer:
        example_id = 0
        prev_id = int(index[0])
        for (line, idx) in zip(text, index):
            if ((line == '') or (line == '\n')):
                example_id += 1
            else:
                cur_id = int(idx)
                output_line = ('\n' if (cur_id != prev_id) else '')
                if output_word_prediction:
                    output_line += (line.split()[0] + '\t')
                output_line += (predictions[example_id].pop(0) + '\n')
                writer.write(output_line)
                prev_id = cur_id
def save_predictions(args, predictions, output_file, text_file, idx_file, output_word_prediction=False):
    with open(text_file, 'r') as text_reader, open(idx_file, 'r') as idx_reader:
        text = text_reader.readlines()
        index = idx_reader.readlines()
        assert (len(text) == len(index))
    with open(output_file, 'w') as writer:
        example_id = 0
        prev_id = int(index[0])
        for (line, idx) in zip(text, index):
            if ((line == ) or (line == '\n')):
                example_id += 1
            else:
                cur_id = int(idx)
                output_line = ('\n' if (cur_id != prev_id) else )
                if output_word_prediction:
                    output_line += (line.split()[0] + '\t')
                output_line += (predictions[example_id].pop(0) + '\n')
                writer.write(output_line)
                prev_id = cur_id