Skip to content
uencoder

TF-IDF

TF-IDF (term frequency-inverse document frequency) measures how important a word is to a document: words frequent in the document but rare in the corpus receive high weights.

Purpose

Distinguishes document content words from generic function words, used for retrieval ranking and feature weighting.

Mechanism

TF = the count of a word in a document; IDF = log(N/DF), where N is the total number of documents and DF is the number of documents containing the word. TF-IDF = TF × IDF. Common words (the) have low IDF; rare words have high IDF.

Use cases

  • Search engine relevance ranking
  • Document keyword extraction
  • Feature weighting for text classification
  • Content similarity in recommender systems

Examples

  • Input
    The word "the" appears in all documents
    Output
    IDF≈0, low weight

    Common words get low weights

Common errors

Failing to log-transform or normalize TF biases long documents
Use 1+log(TF) and document length normalization

Related terms

References