def preprocess_examples(examples, mode='train'):
    """
    For training set and dev set, treat each utterance of the first speaker as 
    the response, and concatenate the goal, knowledge and the dialog’s previous 
    utterances as the history. In this way, multiple history-response pairs 
    are constructed.
    """
    if mode == 'test':
        return examples
    new_examples = []
    for example in examples:
        conversation = example['conversation']
        for i in range(0, len(conversation), 2):
            new_examples.append({
                'goal': example['goal'],
                'knowledge': example['knowledge'],
                'history': conversation[:i],
                'response': conversation[i]
            })
    return new_examples