def sent_to_ner(ner_model, sent, tag="<NE>"):
    """
    Args:
        - ner_model is an object of StanfordNERTagger as usually
          returned by load_stanford('ner').
        - sent is the sentence, broken up into a list of its words,
          that shall have it's named entities replaced with tag.
        - tag is the tag with which to replace the entities. Usually
          this will be <NE>.
    Returns:
        - sent with tag instead of the named entities.

    This function takes an input sentence analyzes it with the NER
    tagger and replaces any word that is not tokenized with 'O' (the
    trivial object) with <NE>. Examples for that are in the 3class
    classifier with 'PERSON', 'LOCATION', 'ORGANIZATION'.
    """
    # first let the tagger run
    ner_tagged = ner_model.tag(sent)
    # extract all indices of words that are not tagged with 'O'
    idx_lst = [i for i, word_ner in enumerate(ner_tagged)
               if word_ner[1] != 'O']
    output = sent
    replaced = []
    for idx in idx_lst:
        # insert the tag
        output[idx] = tag
        replaced.append(ner_tagged[idx][0])
    return (output, replaced)