Open Google Translate and select Marwadi. Type a sentence the way your grandmother says it at the dinner table, and Google Translate can translate it into English.
In June 2024, Google added 110 languages to Translate, including Marwadi and Awadhi. Google’s PaLM 2 model helped make this possible. It uses the Transformer architecture, the foundation behind many modern AI language models. This guide gives you transformer architecture explained in simple terms, starting from tokens.
The Transformer was introduced in a 2017 research paper called Attention Is All You Need. Unlike older models that processed words one after another, Transformer models process multiple tokens in parallel during training. This makes training on large datasets more efficient while allowing the model to understand how tokens relate to each other using attention.
Next, we cover tokens, embeddings, positional information, attention, Transformer blocks, encoders and decoders.
Transformer Architecture Explained: What Is a Transformer in AI?
A Transformer is a type of neural network that helps AI understand and generate language. It looks at how different parts of a sentence relate to each other instead of processing each word only in sequence. It uses a mechanism called attention to do this.
Think of reading a WhatsApp message where the meaning of one word depends on the words around it. A Transformer does something similar. It uses the surrounding context to understand what each token means in a sentence.
Today, the Transformer architecture supports large language models, chatbots, coding assistants and systems that work with images and audio.
To understand how a Transformer works, you need three basic ideas: tokens break text into smaller pieces, embeddings turn those pieces into numerical representations, and attention helps the model connect information across them. Let’s look at each step.
How Does a Transformer Break Text Into Tokens?
A Transformer cannot work directly with text. It first needs to break the text into smaller pieces called tokens. A tool called a tokenizer does this job.
A token can be a complete word like “apple”, part of a word, or a punctuation mark. For example, “playing” might split into “play” and “ing”. Similarly, “Jaipur’s” might be split into “Jaipur”, and “‘s”.
Why break words into smaller pieces? Because language has millions of words, names and spellings. A model cannot store every possible word separately. Smaller pieces help it process unfamiliar words and understand different word forms.
Once the text is split, the tokenizer gives each token a number called a token ID. For example, “Jaipur is pink” becomes a list of numbers that the Transformer can process.

Tokens also affect how much text a model can handle. AI models measure text limits in tokens, not words. Hindi sentences can use more tokens than English sentences of similar length, depending on the tokenizer. Try the OpenAI tokenizer to see how it splits different sentences.
How Do Embeddings Represent Meaning and Word Order?
A token ID is just a number. It tells the Transformer which token it is, but not what that token means. Embeddings help the model understand it.
An embedding turns each token into a list of numbers called a vector. These numbers represent information the model learns during training. Tokens with similar meanings can have similar representations. For example, “apple” and “mango” may have more similar representations than “apple” and “car”.
These numerical representations can also be stored and searched using a vector database. Read more about how vector databases store embeddings to understand how AI applications retrieve information based on semantic similarity.
The Transformer uses these embeddings as the starting point. As tokens pass through its layers, the model updates their representations using the surrounding context.
But word meaning is not the only thing that matters. Word order is also important. Look at these two sentences:
- “The boy kicked the ball.”
- “The ball kicked the boy.”
Both sentences use the same words, but they mean different things. The model needs to know the order of words to understand what is happening.
This is where positional information comes in. The original Transformer added positional encodings to token embeddings to show each token’s position. Newer models may use other methods, such as rotary position embeddings (RoPE), but the goal remains the same: help the model understand word order.
You can see how embeddings and positional encodings work together in The Illustrated Transformer. You can see how embeddings and positional encodings work together in The Illustrated Transformer. In practical RAG applications, embedding models convert text into vectors to help retrieve relevant information from a knowledge base. Explore Hugging Face embeddings in RAG to understand how these models work in a retrieval-based AI system.
How Does the Attention Mechanism Decide What Matters?
Consider these two sentences:
“The girl placed the glass on the table because it was clean.”
“The girl placed the glass on the table because it was empty.”
In the first sentence, “it” refers to the table. In the second, it refers to the glass. The surrounding words help us understand what “it” means. The attention mechanism helps a Transformer make these connections.
Through self-attention, each token looks at other tokens in the same sentence to identify which ones are important for understanding its meaning. This helps the model connect words even when they are far apart.
The remaining Query, Key, Value explanation can stay unchanged. However, update the numerical example to:
For example, when processing “it” in the first sentence, the model might assign an attention weight of 0.7 to “table” and 0.1 to “glass”, with the remaining weight distributed across other tokens.

A single attention operation may not capture every useful relationship in a sentence. That’s why Transformers use multi-head attention. It runs several attention operations in parallel, each with its own learned Query, Key and Value projections. Together, these heads can capture different relationships between tokens.
The base Transformer model used eight attention heads in each layer, while the big model used 16. You can see how the process works in the 2017 paper, Attention Is All You Need, which introduced the architecture.
What Happens Inside a Transformer Block?
A Transformer block has two main parts: self-attention and a feed-forward network.

Self-attention helps each token connect with other relevant tokens in a sentence. The feed-forward network then processes the information each token has collected.
Two more parts help the block work properly:
- Residual connections add the original information back after each step. This helps the model keep useful information as it processes text.
- Layer normalization keeps the values inside the model more stable, which helps during training.
A Transformer uses many of these blocks, one after another. Each block processes the information and passes it to the next one. As a result, the model builds a better understanding of the input. The original Transformer had six encoder blocks and six decoder blocks. GPT-3 used 96 Transformer layers.
In chatbot-style models such as GPT, the final layer predicts what token should come next. The model adds that token to the text and predicts the next one. It repeats this process until it finishes the response.
Encoder, Decoder or Both: How Transformer Models Differ
The original Transformer had two main parts: an encoder and a decoder. The encoder reads the input and builds a representation of it. The decoder uses that information to produce the output one token at a time.
This design works well for translation. The encoder processes a Hindi sentence, and the decoder uses it to generate the English translation.
Later, researchers started using each part separately. This led to three main types of Transformer models.
1. Encoder-Only Models
Encoder-only models focus on understanding text. They look at the words around each token to understand its context.
BERT is a well-known example. It works well for tasks such as sentiment analysis, spam detection and search ranking. Google’s original BERT research paper explains how the model learns from both sides of a word.
2. Decoder-Only Models
Decoder-only models focus on generating text. They predict one token at a time, using the tokens that came before it.
They use masked self-attention, which prevents each token from looking at future tokens. This is why they generate text from left to right, one token at a time.
The GPT family follows this design. These models power many chatbots and can write emails, answer questions and generate code.
3. Encoder-Decoder Models
These models use both parts. The encoder understands the input, and the decoder turns that information into new text.
T5 and BART are popular examples. They work well for tasks such as translation, summarisation and rewriting. You can read more in the T5 research paper.
The basic difference is simple: encoders understand text, decoders generate text, and encoder-decoder models do both.
| Follow Us for Daily Tech Tips |
|
Practical AI Learning at TISA-TECH
Understanding Transformers is a good starting point for learning modern AI. To go further, students need to understand Python programming, machine learning and neural networks.
At TISA-TECH, students can build these foundations through Advanced AI learning, where they explore concepts behind modern AI systems and how they work.
Students can also gain practical exposure through AI and software development internships, where they can apply their knowledge to real tasks.
The goal is to move beyond simply using AI tools and start understanding how the technology behind them works.
Conclusion
Transformers turn text into tokens, represent them through embeddings and use attention to understand how those tokens relate to each other. Repeated Transformer blocks build on this information to help models understand or generate text.
Understanding these steps makes it easier to see how models like BERT and GPT work and why the Transformer architecture plays such an important role in modern AI.
FAQs Section
Ans. A Transformer is a neural network architecture, while an LLM is a language model trained to understand and generate text. Many popular LLMs, including GPT models, use the Transformer architecture.
Ans. Attention helps a Transformer identify which other tokens are relevant to the current token. This allows the model to understand relationships between words and use context when processing text.
Ans. Encoder-only models such as BERT focus on understanding text. Decoder-only models such as GPT focus on generating text one token at a time.
Ans. Transformers use embeddings to represent tokens as numbers and attention to connect them with surrounding context. This helps models understand how word meaning changes depending on the sentence.
Ans. Python is commonly used to build and work with Transformer models. Libraries such as PyTorch and Hugging Face Transformers help developers create, train and use these models.