Consider:
"The cat sat on the mat because it was tired.” To understand what “it” refers to, an AI needs to connect it with the cat. Transformers are designed to identify relationships like this using a mechanism called attention.
Before a Transformer can process text, the text is broken into smaller pieces called tokens.
For example:
"I love coding"
might become:
["I", "love", "coding"]
A token doesn't always have to be a complete word. Long or unusual words can be split into multiple tokens.The tokens are then converted into numbers so that the computer can process them.
"I" → 102
"love" → 581
"coding" → 927
These numbers are called token IDs.
Attention is the heart of the Transformer. It allows the model to determine which tokens are important when interpreting another token.
For example:
"The dog chased the ball because it was moving."
The model can use attention to determine which earlier words are relevant to understanding “it.”
The basic idea is:
"When I'm processing this word, which other words should I pay attention to?”