Skip to content
ML to LLMs
Labs / NLP Lab

TF-IDF calculator

Edit a corpus and see term frequency, document frequency, IDF, and TF-IDF for every word.

Theory and worked examples: From text to vectors

TF-IDF lab

Edit the corpus (one document per line). Click any cell to see its calculation. Formula: TF × ln(N / DF), with raw counts for TF.

d1
d2
d3
d4
IDF1.390.691.391.391.391.391.391.390.291.391.391.391.391.390.001.39

Cosine similarity between documents (TF-IDF vectors)

d1d2d3d4
d11.000.020.000.09
d20.021.000.000.01
d30.000.001.000.00
d40.090.010.001.00

Documents sharing no rare words score 0, even if they mean similar things. Embeddings fix that; see the next lesson.

Worked calculation for “model” in document 2: TF=1,  DF=3,  IDF=ln⁡(4/3)=0.288,  TF-IDF=1×0.288=0.288\text{TF} = 1,\; \text{DF} = 3,\; \text{IDF} = \ln(4/3) = 0.288,\; \text{TF-IDF} = 1 \times 0.288 = 0.288

Words that are frequent in one document but rare across the corpus get the highest weights.