Python, NLP, Numpy, Scikit Learn.
balances rare terms in a large corpora of documents. The detailed mathematics can be studied in the TfIdf Wikipedia article — here is the essential summary: TF, term frequency, is the number of times a term appears inside a document, divided by the total length of the document, in pseudo code