49. What Transformers Are (Text and Sequences)
49.1 Why Sequences Need Attention
Why. Text and sequences are not grids like images. Meaning depends on order and long-range links: “not good” ≠ “good.” Transformers handle that with attention.
What. A transformer block lets each token look at other tokens and decide what matters (“attention”). Stacked blocks power modern NLP and are the backbone idea behind ChatGPT-style models (full apps live in the Gen AI course).
How.
Spot a sequence problem
- Reviews, SMS, support tickets, Marathi/English mix captions.
- Order matters.
- You need context beyond a single word bag (TF-IDF still useful — Chapter 52).
print("bag-of-words ignores order; attention can use order + context")
Ravindra Bagale's Tip
A transformer works like smart focus: for each word, it decides which other words it should pay attention to. It is not magic, because these attention weights are learned from data during training.
Ravindra Bagale's Tip – मराठी
Transformer एका smart focus सारखं काम करतो: प्रत्येक word साठी तो ठरवतो की इतर कोणत्या words कडे लक्ष द्यायचं. यात काही magic नाही, कारण हे attention weights training दरम्यान data मधून शिकले जातात.
Ravindra Bagale's Tip – हिंदी
Transformer एक smart focus की तरह काम करता है: हर word के लिए वह तय करता है कि किन दूसरे words पर ध्यान देना है. इसमें कोई magic नहीं है, क्योंकि ये attention weights training के दौरान data से सीखे जाते हैं.