← Natural language processing
Lesson 2 of 4
Text as numbers
Watch, read the card, then practise. Bag of words and TF-IDF · Word embeddings
The video for this lesson is being recorded.
Meanwhile, the notes below and the 60-second cards cover the same ideas.
Practise this topicBag of words and TF-IDF
Bag-of-words counts each word in a document. TF-IDF also lowers the weight of words that appear everywhere.
Remember: TF-IDF + logistic regression is a strong, cheap baseline.
Word embeddings
Embeddings turn words into vectors, so words with similar meanings sit close together.
Remember: Close vectors = similar meaning.
Try the example in Code Lab
import math tf = 2 / 10 # 2 times in a 10-word document idf = math.log10(100 / 10) # in 10 of 100 documents print(round(tf * idf, 2))