Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 6 of 30
❮Prev Next❯

How Generative AI Models Work

Module 1: AI Concepts ⏱ 9 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    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 needed

    Exam 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.

    Azure portal: Tune a model in the chat playground Change temperature and max tokens and compare the answers.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    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
    1. Set temperature 0.2 and ask for a product slogan. Send it three times: the answers are almost identical.
    2. Now temperature 1.3. Each answer is different and more playful, because the model samples less likely tokens.
    3. Set Max output tokens to 12 and ask for a paragraph. It stops mid-sentence with finish reason length.
    4. 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.

    😟 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
    🛠️ Solved with: Generative AI

    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.

    ▶ Explainer video See it in motion 7 steps · 1 min 11 sec

    An animation that splits a sentence into tokens, shows each token as a number, counts characters against tokens, adds input and output tokens into a bill, fills a context window, and compares token counts for English and Hindi.
    Read the video script
    1. Your text goes inA language model never sees your words as words. First, your text gets chopped into tokens.
    2. Text becomes tokensA token can be a whole word, part of a word, or a punctuation mark. Unbelievable splits into three pieces.
    3. Each token is a numberEach token maps to a number in the model's vocabulary. The model only ever works with these numbers.
    4. 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.
    5. 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.
    6. 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.
    7. 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.
    ▶ Explainer video See it in motion 7 steps · 1 min 9 sec

    An animation of a language model completing “The Taj Mahal is in”: tokens become embeddings, attention links “in” to “Taj Mahal”, the model scores possible next tokens with Agra at 86 percent, appends it and repeats, then a temperature dial flattens the scores, and a warning explains hallucination and grounding.
    Read the video script
    1. It starts with your promptYou type a prompt. The model splits it into tokens, just like we saw before.
    2. Tokens become embeddingsEach token is turned into an embedding, a list of numbers that captures its meaning. Similar words end up with similar numbers.
    3. 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'.
    4. Score every possible next tokenThen it scores every possible next token. Agra is by far the most likely.
    5. 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.
    6. 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.
    7. 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. 1 Tokens

      The prompt is split into small chunks of text.

    2. 2 Embeddings

      Each token becomes a vector that captures meaning.

    3. 3 Attention

      Transformer layers work out how tokens relate.

    4. 4 Next token

      The model scores every possible next token and picks one.

    5. 5 Repeat

      The new token is added and the loop runs again.

    One prompt's journey through a language model

    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.

    TaskTemperature
    Answering from a policy, writing code, extracting factsLow (around 0 to 0.3)
    Everyday chat and summariesMiddle (around 0.7)
    Brainstorming slogans or story ideasHigher (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

    Travel

    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.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    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.

    Question 1

    Question 1 of 5

    How does a large language model generate a response to a prompt?

    Question 2

    Question 2 of 5

    Which component of the transformer architecture enables a model to determine how strongly each token in a sentence relates to the other tokens?

    Question 3

    Question 3 of 5

    An internal HR chatbot gives confident answers about leave entitlement that do not match the company's published policy.

    What should you do to reduce these incorrect answers?

    Question 4

    Question 4 of 5 · Select 2

    Which TWO statements about embeddings are correct?

    Question 5

    Question 5 of 5

    During a long conversation, a chat application stops taking into account details that the user provided at the start of the conversation.

    What is the most likely cause?

    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. 1.What is a token?Show

      A small chunk of text the model reads and writes, about four characters of English on average.

    2. 2.Which part of a transformer works out how words relate to each other?Show

      Attention.

    3. 3.What does a model actually predict at each step?Show

      The next token.

    4. 4.Which setting would you lower for more predictable answers?Show

      Temperature.

    5. 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

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.