From Word Counts to Embeddings
Compare bag of words, TF-IDF, and learned word vectors.
artificial intelligence, nlp, tf-idf, embeddingsCount terms
Consider two notes: D1 is “red red fox” and D2 is “red dog”. With vocabulary
[red, fox, dog], a bag-of-words count gives D1 [2, 1, 0] and D2
[1, 0, 1]. It is easy to compare counts, but “dog bites person” and
“person bites dog” have the same counts despite different meanings.
Weight by document frequency
One TF-IDF convention multiplies term frequency (TF) by
idf(t) = ln(N / df(t)), where N is the number of documents and df is the
number containing term t. Here N is 2. “red” appears in both, so its IDF is
ln(2/2) = 0; “fox” occurs in one, giving ln(2) ≈ 0.693. With raw counts,
D1's “fox” weight is about 0.693. Other implementations smooth or normalise
these values, so state the convention.
See the reasoning
Follow the example one step at a time
Compute one TF-IDF weight using the lesson's stated convention. This is a prepared teaching demonstration, not live code execution.
Count documents
D1: red red fox D2: red dog N=2; df(red)=2; df(fox)=1
Document frequency counts documents containing the term, not occurrences.
Learn a vector
An embedding is a numerical vector learned so useful relationships are available to a model. Word2Vec learns from local word contexts, for example by predicting nearby words or a word from context. GloVe learns vectors from global word co-occurrence statistics. These classic word vectors typically assign one vector per word, unlike contextual models that can represent the same word differently in different sentences.
Similarity is not truth or a definition. Corpus choice, polysemy, rare words and stereotypes can distort a representation. Evaluate on the intended language, population and task rather than assuming nearby vectors are fair.
Reflect on the concept
Four fixed questions to reinforce the reasoning. Answers are not saved or scored.
