QUESTION 6 OF 10

How does TF-IDF weight words?

Reveal the answer and explore the explanation.

06
Medium

How does TF-IDF weight words?

Answer
Answer

Weights term frequency by inverse document frequency to emphasize discriminative terms.

Practical example

Downweight words appearing in almost every document.

PythonRelated concept example
from sklearn.feature_extraction.text import TfidfVectorizer
v = TfidfVectorizer()
X = v.fit_transform(['ai helps', 'ai learns'])
print(v.get_feature_names_out())

The vectorizer learns vocabulary and IDF weights from its fit corpus.

Reference: Further reading ↗

Last 30 min revisionHigh-yield interview Q&As