liveBook · Manning

Term frequency-inverse document frequency

As explained in Machine Learning Algorithms in Depth

TF-IDF is a term-weighting technique that combines a term's frequency in a document with the inverse frequency of documents containing that term.

Term frequency–inverse document frequency (TF-IDF) weights terms by combining their frequency within a document with the inverse frequency of documents containing them. It adjusts the term-document matrix so words common across a corpus contribute less and discriminative words contribute more. section 9.1

For a corpus of D documents, let nt denote the number of documents containing term t. The inverse-document-frequency factor is log(D/nt), which approaches zero as a term appears in more documents; applying it to word counts produces smoothed weights for downstream topic modeling. section 9.1 section 9.8

TF-IDF fits into document representation as follows:

  • Represent documents with a bag-of-words term-document matrix whose columns or rows encode vocabulary-term counts. section 9.1
  • Apply inverse-document-frequency weighting to emphasize terms that distinguish documents. section 9.1
  • Extend the representation from unigrams to n-grams when larger structural units are useful. section 9.1

How Machine Learning Algorithms in Depth covers it

How deep it goes
Defines the weighting formula and its variables, but does not derive or implement the method step by step.
Examples
Uses document corpora, vocabulary-count matrices, unigrams, and n-grams as representation examples.
What it assumes
Assumes familiarity with documents, vocabulary counts, and the bag-of-words representation.
What you can do after
Apply TF-IDF to reduce common-word influence and identify terms that distinguish documents.
How it connects
Connects TF-IDF to bag-of-words models, term-document matrices, n-grams, and latent Dirichlet allocation.

Also explained in

Compare how 10 books explain term frequency-inverse document frequency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Algorithms in Depth. The section links point to the parts of the book it draws on.