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.
0 of 8 stages complete
1 · Watch

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.

Encodings, parts 5–7 — the curse of dimensionality, embeddings, cosine similarity
Clustering→Embeddings, parts 5–6 — soft clustering vs embedding learning
Intro to LLMs, parts 2–3 — tokens and byte-pair encoding
Code walkthrough: PyTorch embeddings 01
Code walkthrough: PyTorch embeddings 02
Code walkthrough: PyTorch embeddings 03
Code walkthrough: PyTorch embeddings 04

Visual shorts

Short silent animations, one idea each. Press play, or open one full screen. All visual shorts

Skip-gram training pairs · full screen
TF-IDF · full screen
2 · Listen

Orientation audio

Text into vectors, counting into embeddings — the road that ends at transformers.

3 · Read & play

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.

Figure · Similarity is geometry

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
4 · Code

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.

5 · Practice

Exercise

Attempt the exercise before opening the solution — the attempt is where the learning happens.

6 · Check

Knowledge check

The quiz is self-graded and open-book. If a question surprises you, the corresponding lecture part is the fastest fix.

7 · Go deeper

Reference and discussion

8 · Done

Finish the module

Complete the stages above, then claim the finish here.