def postprocess_output(model_output, narrative_token, dialog_token, eos_token):
    """
    Performs the reverse of preprocess_input. Removes dialog, dialog, and eos special tokens from
    model output after tokenizer decoding. Text between a narrative_token and eos_token gets
    surrounded with '***'.
    """
    #Replace those eos tokens which immediately follow a narrative_token with "***"
    narrative_token_idx = -len(narrative_token)
    while True:
        narrative_token_idx = model_output.find(narrative_token, 
                                                narrative_token_idx + len(narrative_token))
        if narrative_token_idx == -1:
            break
        eos_token_idx = model_output.find(eos_token, narrative_token_idx)
        if eos_token_idx > -1:
            model_output = (model_output[:eos_token_idx] + "***" +
                            model_output[(eos_token_idx + len(eos_token)):])
    
    #Substitute all the remaining special tokens
    model_output = (model_output.replace(narrative_token, " ***")
                    .replace(dialog_token, " ")
                    .replace(eos_token, "")
                    .strip())
    
    return model_output