CourseNatural Language Processing: The Complete Course · Module 7: Sequence Models and Transformers with Hugging Face · part 48 of 73
Part 48 · Module 7: Sequence Models and Transformers with Hugging Face

Lesson 2: Attention, and words that change with their neighbours

37 min read·14 Oct 2026
Module 7 · Lesson 2 · About 55 minutes · Needs: basic Python and NumPy; Module 6 (word vectors, cosine similarity) helps; Lesson 1 of this module helps but is not required

The situation

It is Monday 19 October 2026, project week 7. Rosa asks whether a transformer would route the inbox better than Module 4's TF-IDF model. Before fine-tuning one in Lesson 4, you need to know what is inside it.

One message runs through the lesson: HT35 from the hand-written test set (simulated), "Charged twice. £45 and £45. Fix it.", labelled returns_refund. Beside it sits a battery twin, added in this lesson: "My battery charged to 80% then died." To a word-count model, both contain the same word.

HT35 AND A BATTERY TWIN Charged twice. £45 and £45. Fix it. My battery charged to 80% then died. returns_refund (money) warranty_fault (battery) TF-IDF column "charged" one column, both meanings
To a word-count model, "charged" in a refund complaint and "charged" in a battery fault are the same column (red: the failure this lesson fixes).

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.