def get_token_to_id_filter(sfile_filter):
    """
    This function returns a filter which converts each token to a numerical id.

    This filter only affects record_dict by altering the contents of
    record_dict['feature_values'].

    Parameters
    ----------
    sfile_filter : instance of SFileFilter

    Returns
    -------
    token_to_id_filter : function
    """
    token2id = sfile_filter.token2id
    def token_to_id_filter(record_dict):
        record_dict['feature_values'] = {
            token2id[token]: value
            for token, value
            in record_dict['feature_values'].iteritems()
            if token in token2id}
        keep_doc = True
        return keep_doc
    return token_to_id_filter