def _replace_ner(sentence, ner_dict):
    """Replace the Named Entities in a sentence

    Args:
        sentence: str, sentences to be processed
        ner_dict: dictionary of {NER_tag: word} or an empty list

    Returns:
        processed sentence
    """
    if isinstance(ner_dict, (list, tuple)):
        # the map is empty, no NER in the sentence
        return sentence

    def replace_fn(token):
        # for compatability between python2 and 3
        # upper because the NER are upper-based
        if token.upper().encode() in ner_dict.keys():
            # lower case replaced words
            return ner_dict[token.upper().encode()].decode().lower()
        else:
            return token

    return " ".join(map(replace_fn, sentence.split()))