How Generative AI Models Work
30-second answer
A generative AI language model splits your prompt into tokens, turns each token into an embedding (a list of numbers that captures meaning), and runs them through a transformer whose attention layers work out how the words relate. It then predicts the next token, adds it to the text and repeats until the answer is done. Settings like temperature control how adventurous each pick is, the context window limits how much text it can consider at once, and grounding it in your own data reduces hallucinations (confident but wrong answers).
Simulate it » No Azure account neededExam objective: 1.2.1 Describe how generative AI models work. (Skills measured as of April 15, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Set <strong>temperature 0.2</strong> and ask for a product slogan. Send it three times: the answers are almost identical.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Set temperature 0.2 and ask for a product slogan. Send it three times: the answers are almost identical.
- Now temperature 1.3. Each answer is different and more playful, because the model samples less likely tokens.
- Set Max output tokens to 12 and ask for a paragraph. It stops mid-sentence with finish reason length.
- Every message costs tokens (roughly 4 characters of English each), both in and out.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
A prompt goes in
You type a prompt: "Write a thank-you note to my team." The model never sees letters. First the text is cut into tokens, which are whole words or pieces of words.
🤔 What happens if…
Read this tour as text
- A prompt goes in. You type a prompt: "Write a thank-you note to my team." The model never sees letters. First the text is cut into tokens, which are whole words or pieces of words.
- Tokens become numbers. Each token becomes a long list of numbers called an embedding. Words with similar meaning get similar numbers, so "team" sits near "colleagues" and far from "banana".
- Layers of attention. The tokens flow through dozens of transformer layers. In each layer, attention lets every token look at the others to work out context, so "bank" means money in one sentence and a river in another.
- Predict the next token. At the end the model scores every possible next token and picks one. Then it adds that token to the input and predicts again, one token at a time, until the answer is finished. That is all "generation" is.
- Temperature. Temperature controls how adventurous the pick is. Low (0.1) almost always takes the top token, so answers are focused and repeatable. High (1.2) spreads the choice, so answers get more creative and less predictable.
- Context window and max tokens. A model can only "see" a limited number of tokens at once: its context window. Max output tokens caps how long the answer can be. Long chats eventually push the oldest messages out.
- Grounding beats guessing. A model only knows its training data, so it can confidently make things up (a hallucination). Grounding adds trusted data to the prompt, for example your company handbook, so the answer is based on facts you supplied.
- Bigger is not always better. Large models reason better but cost more and answer slower. Small language models are cheap and fast for simple jobs. Multimodal models also read images and audio. Pick the smallest model that does the job well.
Deploy a GPT model, chat with it in the playground, then turn the temperature and max-tokens dials and watch what changes.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
The AI gives a confident but wrong answer about your leave policy.
😊 THE SOLUTION
Understand tokens, prediction and grounding, then fix the prompt.
- Answers change every time✓ Lower the temperature
- It makes things up✓ Ground it with your own data
- It forgets earlier messages✓ Mind the context window
Start with a question
When your phone suggests the next word as you type 'Happy birth…', how does it know you mean 'birthday'?
It’s seen that pattern millions of times. “Happy birth” is almost always followed by “day”.
A generative AI model does the same thing at a vastly bigger scale. It doesn’t just guess one word for a text message. It predicts the next piece of text, then the next, then the next, until it has written a whole email, a poem or a Python function. Understanding that one idea explains most of what these models do well, and the mistakes they make.
Explain it like I’m 10
Visual: generative AI in motion
Two short videos: how text turns into tokens, and how the model writes its reply one token at a time.
Read the video script
- Your text goes inA language model never sees your words as words. First, your text gets chopped into tokens.
- Text becomes tokensA token can be a whole word, part of a word, or a punctuation mark. Unbelievable splits into three pieces.
- Each token is a numberEach token maps to a number in the model's vocabulary. The model only ever works with these numbers.
- About four characters eachIn English, a token is about four characters on average, so a hundred tokens is roughly seventy five words. Short words like these pack fewer characters into each token.
- You pay per tokenTokens are how you're billed. You pay for the tokens you send in, and for the tokens the model writes back.
- The context window has a limitEvery model also has a context window. That is the most tokens it can handle in one request, counting your prompt, the chat history and its reply together.
- Some languages use moreOne more thing. Languages like Hindi or Tamil usually need more tokens for the same meaning, so the same message can cost more.
Read the video script
- It starts with your promptYou type a prompt. The model splits it into tokens, just like we saw before.
- Tokens become embeddingsEach token is turned into an embedding, a list of numbers that captures its meaning. Similar words end up with similar numbers.
- Attention links the wordsInside the transformer, attention works out which words matter to each other. Here, the word 'in' pays most attention to 'Taj Mahal'.
- Score every possible next tokenThen it scores every possible next token. Agra is by far the most likely.
- Pick one, add it, repeatIt picks a token, adds it to the text, and runs the whole thing again for the next one. That loop is all that generation is.
- Temperature changes the pickTemperature controls how adventurous each pick is. Low temperature sticks to the likeliest token. High temperature spreads the chances out, which is good for creative writing.
- Fluent isn’t the same as trueThe model predicts what sounds right, not what has been checked. That's why it can hallucinate, and why grounding it in your own data matters.
The technical explanation
-
1 Tokens
The prompt is split into small chunks of text.
-
2 Embeddings
Each token becomes a vector that captures meaning.
-
3 Attention
Transformer layers work out how tokens relate.
-
4 Next token
The model scores every possible next token and picks one.
-
5 Repeat
The new token is added and the loop runs again.
1. Tokens
Models don’t read words, they read tokens. A token can be a whole word (“cat”), part of a word (“un” + “believ” + “able”) or punctuation. In English, one token is about four characters on average, so 100 tokens is roughly 75 words. Hindi or Tamil text usually needs more tokens for the same meaning. Tokens matter because you pay per token (input and output) and because limits are counted in tokens.
2. Embeddings
Each token is turned into an embedding: a long list of numbers (a vector). The model learns these so that words with related meanings have similar vectors. “King” sits near “queen”, and “invoice” sits near “bill”. Embedding models in Foundry produce vectors for whole sentences or documents too, which is how semantic search finds “money back” when you searched “refund”.
3. Transformers and attention
Modern language models use the transformer architecture. Its key idea is attention: for every token, the model weighs how much each other token matters. In “The bank was closed, so I couldn’t deposit the cheque”, attention links “bank” with “deposit” and “cheque”, so the model treats it as a money bank, not a river bank. Stacking many attention layers lets the model capture grammar, facts and style.
4. Next-token prediction
At the end, the model gives a probability to every token it knows. It picks one, adds it to the text and runs again. That loop is the whole “writing” process. It’s why answers stream in word by word.
5. Temperature and other settings
Temperature (0 to 2) controls how the next token is picked. Low temperature nearly always picks the top choice, so answers are focused and repeatable. High temperature takes more chances, so answers vary more. Top_p is another way to control randomness; change one or the other, not both. Max output tokens caps the answer length. Reasoning models use a reasoning effort setting instead of temperature.
| Task | Temperature |
|---|---|
| Answering from a policy, writing code, extracting facts | Low (around 0 to 0.3) |
| Everyday chat and summaries | Middle (around 0.7) |
| Brainstorming slogans or story ideas | Higher (around 1 or more) |
6. Context window
The context window is the most tokens the model can handle in one request: your system message, the chat history, any grounding documents and the answer. If a conversation grows past it, older messages have to be dropped or summarised, and the model “forgets” them.
7. Hallucination and grounding
Because the model predicts likely text, it can produce an answer that sounds right but is false. That’s a hallucination. The main fix is grounding: put trusted information in the prompt so the model answers from it. Retrieval-augmented generation (RAG) does this automatically: it uses embeddings to find the most relevant chunks of your documents and adds them to the prompt. Add a system message like “answer only from the provided sources”, a low temperature and citations, and hallucinations drop sharply.
Architect level Training versus inference
Training is when the model learns from enormous amounts of text, adjusting billions of internal weights so its next-token guesses get better. It costs a lot and happens once (plus later fine-tuning). Inference is when you send a prompt and get an answer; that’s what you pay for per token in Foundry. Your prompts at inference time don’t change the model’s weights, and prompts and completions in Foundry aren’t used to train the foundation models. If you want the model to know your data, you ground it at inference time, or in some cases fine-tune it.
Real-world business scenario
Proseware Travel, an online travel agency in Delhi
- The problem
- Its new booking assistant invented baggage rules and gave different answers to the same question, and long chats lost track of the customer's dates.
- What they used
- Grounded the assistant with RAG over airline and refund policies using an embedding model, set temperature to 0.2 for policy answers, added citations, and summarised older chat turns to stay inside the context window.
- Why that choice
- The model was guessing from training data instead of reading the policies, and high temperature made the guesses vary.
- The result
- Answers became consistent and checkable, and escalations about wrong baggage information dropped sharply.
When to use it and when not to
✓ Use it when…
- Writing, summarising, translating or rewriting text where a person can review the result.
- Answering questions over your own documents, when you ground the model in them.
- Brainstorming and drafting, where variety from a higher temperature helps.
✕ Think twice when…
- Exact calculations or lookups that a database or code can do perfectly.
- Answering from memory about facts that must be correct, with no grounding.
- Feeding huge documents in one go without checking the context window and token cost.
↔ Alternatives to consider
- **Grounding with RAG** when answers must come from your own data.
- **A purpose-built Foundry Tool** for narrow jobs like PII detection or transcription.
- **A small language model such as Phi** when the task is simple and cost or speed matters.
Test yourself with exercises
5 original practice questions in the AI-901 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner In simple words, how does a chatbot like ChatGPT or Copilot write an answer?
Model answer
It predicts the next word, or more exactly the next token, based on everything before it. Then it adds that token and predicts the next one, over and over. It learned which tokens tend to follow which by training on a huge amount of text.
Interviewer follows up
So does it understand what it's saying?
You
It captures meaning in a statistical way through embeddings and attention, which is why it's so useful. But it doesn't check facts unless you give it facts, which is why it can hallucinate.
Intermediate What is an embedding and why does it matter?
Model answer
An embedding is a vector of numbers that represents meaning. Texts about similar things end up with similar vectors, so "refund policy" and "how do I get my money back" land close together. That's what powers semantic search and RAG: you find the closest document chunks and hand them to the model.
Intermediate What does temperature do?
Model answer
It changes how the model picks among likely next tokens. At low temperature it nearly always takes the most likely one, so answers are focused and repeatable, good for facts and code. At higher temperature it takes more chances, good for brainstorming or creative writing. I'd change temperature or top_p, not both.
Scenario Your HR chatbot confidently tells staff they get 30 days of leave. The real policy says 24. How do you fix it?
Model answer
That's a hallucination. I'd ground the bot in the actual HR policy, using retrieval so the relevant section goes into the prompt, tell it in the system message to answer only from the provided documents and say when it doesn't know, lower the temperature, and show citations so staff can check.
Experienced developer What happens when a conversation goes past the model's context window?
Model answer
The model can't see what doesn't fit. Either the request fails or the app has to drop or summarise older messages, so the model forgets early details. Remember the window covers prompt plus output, so a huge prompt also leaves less room for the answer.
Quick revision
Key points
- Text is split into tokens; roughly four characters of English per token.
- Embeddings turn tokens into vectors so similar meanings sit close together.
- Transformers use attention to work out how every token relates to the others.
- The model writes by predicting the next token, again and again.
- Low temperature = focused; high temperature = varied. Grounding reduces hallucination.
Important terminology
- Token
- A small chunk of text (a word, part of a word or punctuation) that a model reads and writes; about four characters of English on average.
- Embedding
- A list of numbers (a vector) that represents the meaning of a token or text, so similar meanings sit close together.
- Transformer
- The neural network architecture behind modern language models, built around attention.
- Attention
- The mechanism that lets a model weigh how much each token in the text relates to every other token.
- Temperature
- A setting (0 to 2) that controls randomness; low values give focused, repeatable answers, high values give more varied ones.
- Context window
- The maximum number of tokens, prompt plus response, a model can handle in one request.
- Hallucination
- A fluent, confident answer that's false or not supported by the source data.
- Grounding
- Giving the model trusted data in the prompt, often by retrieval-augmented generation (RAG), so it answers from facts.
Common mistakes
- Thinking the model looks answers up in a database. Without grounding it only predicts likely text.
- Thinking a higher temperature makes answers more accurate.
Exam tips
- "Answers must be consistent and factual" = lower temperature and grounding.
- "Model gives confident but wrong answers" = hallucination; fix with grounding (RAG).
- Context window = prompt + response tokens together.
Five quick revision questions
-
1.What is a token?Show
A small chunk of text the model reads and writes, about four characters of English on average.
-
2.Which part of a transformer works out how words relate to each other?Show
Attention.
-
3.What does a model actually predict at each step?Show
The next token.
-
4.Which setting would you lower for more predictable answers?Show
Temperature.
-
5.What technique supplies trusted data in the prompt to reduce hallucination?Show
Grounding, often with retrieval-augmented generation (RAG).
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Choosing the Right AI Model
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.