Module 9: Text and Embeddings
This module covers representing text for machine learning. From simple bag-of-words to learned embeddings, you will understand how to convert text into numerical features that capture meaning and enable tasks like classification and similarity.
Learning Objectives
- Create bag-of-words and TF-IDF representations from text.
- Explain the concept of word embeddings and why they capture semantics.
- Apply pre-trained embeddings (Word2Vec, GloVe) to text data.
- Build text classifiers using embedded representations.
- Understand transfer learning with sentence embeddings.
The module in two minutes
An animated overview of the module’s through-line. Watch it before the lecture — it is the map, not the territory.
Lecture shorts
Short lectures and code walkthroughs from the instructor that reinforce this module. Some open partway into a longer video — that chapter is the part matched to this module.
Visual shorts
Short silent animations, one idea each. Press play, or open one full screen. All visual shorts
Orientation audio
Text into vectors, counting into embeddings — the road that ends at transformers.
The through-line
Models eat numbers, and text is not numbers. Every technique in this module is an answer to one question: how do you turn language into vectors without losing what it means?
Bag-of-words is the bluntest answer — one column per vocabulary word, count the occurrences, ignore the order. TF-IDF sharpens it by weighting words up when they are frequent in a document and down when they are frequent everywhere, so "the" stops mattering and "gradient" starts to. N-grams recover short-range order by counting word pairs and triples as their own features. All three are built from scratch in the notebook, and all three produce long, sparse, brittle vectors: "excellent" and "outstanding" share no dimensions at all.
Embeddings are the modern answer. Give each word a short dense vector, learned from the company it keeps, and similarity becomes geometry: synonyms land near each other, and cosine similarity — the angle between vectors — measures relatedness the counting methods cannot see. Averaging word vectors gives a serviceable embedding for a whole document, enough for search and classification demos in the notebook.
This is the module where language modeling from the AI-literacy world and classical ML meet: the token-and-vector pipeline you build here by hand is, scaled a million-fold, the front end of every transformer — which is exactly where module 13 ends the course.
Twelve words, each a 2-D embedding (real ones use hundreds of dimensions; the geometry is the same). Pick any two and read the angle.
Cosine similarity is the angle between vectors: synonyms point the same way, unrelated words sit near ninety degrees, opposites past it. The second readout is the counting methods’ verdict on the same pair — bag-of-words gives two different words no shared dimensions at all, which is exactly the blindness embeddings fix. Learned from the company words keep, similarity becomes geometry.
Key concepts
- Bag-of-Words: Count word occurrences
- TF-IDF: Weight terms by importance
- Word Embeddings: Dense semantic representations
- Word2Vec: Learn embeddings from context
- Sentence Embeddings: Represent whole texts
The lecture notebook
Six parts, from scratch before any framework. Run every cell; change things and rerun — the notebook is the lecture.
In Colab: File → Save a copy in Drive keeps your work.
Exercise
Attempt the exercise before opening the solution — the attempt is where the learning happens.
Knowledge check
The quiz is self-graded and open-book. If a question surprises you, the corresponding lecture part is the fastest fix.
Reference and discussion
Finish the module
Complete the stages above, then claim the finish here.