def get_tf_idf_filter(sfile_filter, min_tf_idf):
    """
    This function returns a filter which alters the record_dict by removing any
    tokens whose tf_idf is below min_tf_idf. Given a token t and a document d
    in a corpus of documents D, tf_idf is given by the following formula:

        tf_idf(t, d, D) = tf(t, d) x idf(t, D),

    where

        (1) tf(t, d) is the number of times the term t shows up in the document
            d,
        (2) idf(t, D) = log (N / M), where N is the total number of documents
            in D and M is the number of documents in D which contain the token
            t. The logarithm is base e.

    The idf of each token as been previously computed and is passed in by
    sfile_filter and hence this filter need only compute the tf to do the
    filtering.

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

    Parameters
    ----------
    sfile_filter : instance of SFileFilter
    min_tf_idf : numeric

    Returns
    -------
    tf_idf_filter : function
    """
    idf = sfile_filter.idf
    def tf_idf_filter(record_dict):
        feature_values = record_dict['feature_values']
        tokens = feature_values.keys()
        for token in tokens:
            if idf[token] * feature_values[token] < min_tf_idf:
                del feature_values[token]
        keep_doc = True
        return keep_doc
    return tf_idf_filter