Understanding Tokens, Embeddings and the Transformer Architecture
This lesson explains how generative language models turn text into numbers, process those numbers with a transformer and turn the result back into text. The three building blocks, tokens, embeddings and attention, explain how models use context and why they are measured and billed in tokens.
Learning outcomes
After completing this lesson, you will be able to:
- Explain what tokens are and how the context window is measured.
- Explain how embeddings represent meaning as vectors.
- Describe how attention lets a transformer use context.
- Estimate whether a document fits in a model's context window.
Tokens
A model does not read words directly. A tokenizer splits text into tokens, which are common words, parts of words, punctuation or spaces, and maps each to an integer ID. Frequent words are usually one token; rare or long words are split into several. In English, 100 tokens correspond to roughly 75 words, but the ratio differs between languages.
Tokens matter in practice because models have a context window, the maximum number of tokens they can consider at once (the prompt plus the response), and because Foundry Models pricing and quota are measured in tokens: input tokens in the prompt, output tokens in the response and tokens per minute (TPM) for deployment quota.
The following diagram shows a sentence split into tokens and what a context window must hold.

Counting in tokens
Embeddings
An embedding is a vector, a list of numbers, that represents the meaning of a token, sentence or document as a position in a many-dimensional space. Items with similar meaning have vectors that are close together, which is measured with cosine similarity. Inside a language model, each token ID is converted to an embedding before processing, and the model's layers refine these vectors to reflect context, so that bank in river bank and bank account end up with different representations.
Separate embedding models, such as text-embedding-3-small, produce one vector for a whole piece of text. Applications store these vectors to find similar content, which is the basis of semantic search and of retrieval-augmented generation (RAG), where relevant passages are found and added to a prompt.
The following diagram shows embeddings as positions in a space and how search uses them.

The transformer and attention
Most modern language models use the transformer architecture. Its key mechanism, attention (more precisely self-attention), lets the model calculate, for each token, how much every other token in the context should influence its representation. In The trophy did not fit in the suitcase because it was too big, attention helps the model relate it to trophy. Attention runs over all tokens in parallel, which made it practical to train very large models on very large datasets.
The original transformer had an encoder, which builds representations of input, and a decoder, which generates output. Generative models such as GPT are decoder-only: they generate text one token at a time, each time attending to the prompt and to everything generated so far. Embedding models are encoder-style models that produce representations rather than text.
Embeddings and attention at work
Estimating tokens and context
A developer wants a model to summarize 300-page contracts in one request. The chosen model has a 128,000-token context window. Each page has about 500 words.
300 pages × 500 words is 150,000 words, which is about 200,000 tokens, more than the context window before any instructions or output are added.
The developer can choose a model with a larger context window, summarize the contract in sections and then combine the section summaries, or retrieve only the clauses relevant to a question. Raising the maximum output tokens would not help, because the limit is on the total of input and output.
What is an embedding?
Show answer
A vector of numbers that represents meaning, so that texts with similar meanings are placed close together.
Exam Tips
Remember for the exam
- Models process tokens; about 100 tokens equal 75 English words.
- The context window limits prompt plus response, measured in tokens.
- Embeddings are vectors that place similar meanings close together.
- Attention lets each token use the relevant context; GPT models are decoder-only transformers.