LLM Learning Hub

workspace/llm-course/home

TF-IDF

TF-IDF (Term Frequency–Inverse Document Frequency) weights words by how often they appear in a document versus across the corpus, highlighting distinctive words. It improves on raw bag-of-words counts.

What is TF-IDF?

TF-IDF (Term Frequency–Inverse Document Frequency) weights words by how often they appear in a document versus across the corpus, highlighting distinctive words. It improves on raw bag-of-words counts.

TF-IDF (Term Frequency–Inverse Document Frequency) weights words by how often they appear in a document versus across the corpus, highlighting distinctive words. It improves on raw bag-of-words counts.

Where is it used?

TF-IDF powers search engines (Elasticsearch, Lucene) and document clustering; it remains a strong sparse baseline for retrieval before dense embedding methods.

How to build it

Use `TfidfVectorizer().fit_transform(docs)`, inspect the sparse matrix, and build a cosine-similarity document retriever to compare against a dense embedding retriever.