def ner_to_sent(sent, replaced, tag="<NE>"):
    """
    Args:
        - sent is the sentence that has the NER tags in them instead of
          the actual named entities.
        - replaced is the corresponding list of named entities that
          will be inserted in the order of appearance for the tags.
        - tag is the tag that was used to replace the named entities.

    Returns:
        - sent but with it's original named entities

    Raises:
        - ValueError if the amount of <NE> and the length of the
          replacement list do not match.

    This function serves to convert the result from sent_to_ner back to
    a sentence with the named entities in it.
    """
    if len(replaced) != sent.count(tag):
        raise ValueError("The wrong replaced list has been provided"
                         " to ner_to_sent.")

    for i, word in enumerate(sent):
        if word == tag:
            # pop makes sure that every replacement is inserted exactly
            # once
            sent[i] = replaced.pop(0)
    return sent