def deanonymize(sequence, ent_dict, key):
    """Deanonymizes a sequence.

    Inputs:
        sequence (list of str): List of tokens to deanonymize.
        ent_dict (dict str->(dict str->str)): Maps from tokens to the entity dictionary.
        key (str): The key to use, in this case either natural language or SQL.

    Returns:
        Deanonymized sequence of tokens.
    """
    new_sequence = []
    for token in sequence:
        if token in ent_dict:
            new_sequence.extend(ent_dict[token][key])
        else:
            new_sequence.append(token)

    return new_sequence