liveBook · Manning

Term frequency-inverse document frequency

As explained in Machine Learning System Design

A text-weighting representation that scores terms by their frequency in a document relative to their frequency across documents.

Term frequency–inverse document frequency (TF-IDF) converts text into features that machine-learning algorithms can process, weighting terms by their document frequency and broader corpus frequency. section 11.1.2

Use TF-IDF with these practical cautions:

  • Treat it as a sequential-data representation alongside bag-of-words and BM25. section 11.1.2
  • Expect it to lose word-order information; use longer N-grams to partially recover that signal. section 11.1.2
  • Consider pretrained language models such as BERT when a low-dimensional embedding representation is more suitable. section 11.1.2

Text feature generation

Represent text with TF-IDF before feeding it to an ML algorithm, while recognizing that the resulting features do not preserve word order. section 11.1.2

How Machine Learning System Design covers it

How deep it goes
Defines TF-IDF as a text representation and notes its word-order limitation, but does not derive its weighting formula.
Examples
Uses text-to-feature transformation as the concrete example and contrasts it with longer N-grams and BERT embeddings.
What it assumes
Assumes familiarity with machine-learning algorithms and introduces text as sequential data that requires feature transformation.
What you can do after
Evaluate text representation choices for ML pipelines while accounting for lost word-order information.
How it connects
Connects TF-IDF with bag-of-words, BM25, N-grams, and BERT as alternative or complementary text representations.

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 System Design. The section links point to the parts of the book it draws on.