Skip to main content

TF-IDF Calculator

Builds a term-by-document TF-IDF weight matrix from pasted documents, with smooth or classic IDF and optional L2 normalisation, plus the top terms for each document.

For learning TF-IDF or checking a text-processing pipeline.

Last updatedHow we build & check our tools
Results will appear here once you enter your values.

What you get

Enter one document per line, choose an IDF variant and decide whether to L2 normalise. The tool returns a term-by-document matrix with document frequency and IDF for each term, and a card per document listing its top terms.

  • Matrix: one row per distinct term, one column per document, with df and IDF shown.
  • Top terms: up to five highest positive weights per document, ties broken alphabetically.
  • Limits: up to 100 nonblank lines, 500 distinct terms and 100,000 characters. Each document needs at least one word or number.

Worked example with the default inputs

Documents: Cats chase mice / Dogs chase cats / Cats sleep indoors. N = 3, smooth IDF, L2 normalised.

  • IDF: cats (in all 3) = 1.0000, chase (in 2) = 1.2877, and mice, dogs, sleep and indoors (each in 1) = 1.6931.
  • Document 1 top terms: mice 0.7203, chase 0.5478, cats 0.4254.
  • Document 3 top terms: indoors and sleep 0.6525 each, cats 0.3854.
  • Classic, no normalisation: cats gets IDF 0 and drops out; chase is 0.4055; the single-document terms are 1.0986, giving a weight of 0.3662 each (1/3 × 1.0986).

Rare words score highest and the word that appears everywhere scores lowest, which is the point of the IDF factor.

Limits and sources

  • Tiny corpus: IDF comes from the pasted lines only, so weights from three documents say little about a real corpus.
  • No linguistic processing: cat and cats are different terms.
  • Not a relevance judgement: a high weight means a word is distinctive in this set, not that it is important or correct.

Sources: Manning, C. D., Raghavan, P. and Schütze, H. (2008), Introduction to Information Retrieval, Cambridge University Press, chapter 6. scikit-learn documentation for TfidfTransformer and TfidfVectorizer.

Frequently Asked Questions

Common questions about the TF-IDF Calculator

Term frequency is the term's count divided by the document's token count. IDF depends on the variant: smooth is ln((1 + N) / (1 + df)) + 1, the scikit-learn form, and classic is ln(N / df), where N is the document count and df the number of documents containing the term. The weight is TF times IDF, optionally scaled so each document column has unit Euclidean length.

From the same team

Stop paying per token — route AI requests to your own GPU

Wide Area AI is a local-first AI gateway: repeated requests hit an edge cache, the rest run free on your own hardware, and the cloud is only a failover. OpenAI-compatible endpoint, free tier.

Start routing — free

Explore More Tools

Explore these related tools for your next step.

ai
ai
ai
ai
ai
ai