Part 13 of the Generative AI Series
Welcome back! In Part 12, we learned how Large Language Models (LLMs) are trained and how they generate responses one word at a time. But learning how an LLM is built is only half the story. To use AI effectively, you also need to understand the underlying mechanics that influence every single conversation you have with ChatGPT, Gemini, or Claude. Let’s dive into the essential vocabulary of the AI era.
Every AI hallucination, creative outburst, or “forgotten” instruction can be traced directly back to how the model processes tokens within its context window and the temperature settings guiding its predictions.
1. The Prompt: Talking to AI
Imagine walking into a restaurant. If you simply say to the waiter, “Food,” they will look confused. But if you say, “I’d like one vegetarian masala dosa with coconut chutney,” they immediately understand your request.
The quality of your request dictates the quality of the response. Exactly the same thing happens with AI. A prompt is the instruction, question, or input that you provide to an AI model. Everything you type into a chatbot is a prompt (e.g., “Explain Machine Learning”, “Summarize this PDF”).
1.1 Why Prompts Matter: Bad vs. Good
Imagine asking two teachers the same question.
- Student 1: “Explain.”
- Student 2: “Explain Machine Learning to a Class 8 student using cricket examples.”
Student 2 will receive a vastly better explanation because the request is clearer. AI behaves similarly. The more context you provide, the easier it is for the model to generate a response that matches your expectations.
| Prompt Quality | Example | Why it works (or doesn't) |
|---|---|---|
| Bad Prompt | Write about AI. | Too vague; no audience, length, or purpose specified. |
| Better Prompt | Write a beginner-friendly blog explaining AI using real-life analogies. | AI now knows the audience, tone, and style. |
| Excellent Prompt | Act as a senior AI educator. Write a beginner-friendly article explaining Machine Learning for college students. Use simple English, diagrams, and a summary. | The destination is crystal clear. It provides a role, format, and specific deliverables. |
Interactive Simulation: The Prompt Upgrader
Simulation: How AI Sees Your Prompt
Click the buttons below to see how prompt quality drastically changes the AI's internal target logic and final output.
Artificial Intelligence is a branch of computer science. It is used in many things today like computers and robots. It was invented a long time ago...
2. Tokens: The Language of LLMs
In previous chapters, we briefly mentioned tokens. Let’s look closer. A token is the basic unit of text that an LLM processes. Humans read words. AI reads tokens.
2.1 Why Not Words?
Different languages have long words, short words, punctuation, emojis, and numbers. Instead of treating every word as a single rigid unit, LLMs break text into flexible pieces. This is highly efficient for the underlying math.
Example Sentence: Artificial Intelligence is amazing.
A tokenizer might break this into five tokens conceptually:
Artificial | Intelligence | is | amazing | .
However, another model’s tokenizer might split it into even smaller fragments:
Artific | ial | Intelligence | is | amaz | ing
The Furniture Analogy: Imagine shipping a large wardrobe. Instead of transporting it whole, you disassemble it into manageable pieces, and reassemble it at the destination. Tokens work similarly—AI processes manageable textual pieces rather than full sentences at once.
2.2 The Token Limit
Every LLM has a maximum number of tokens it can process in a single interaction. This is called the token limit (or maximum context length). If you exceed this limit, the AI can no longer process the request.
Interactive Simulation: The Tokenizer
Simulation: Real-Time Token Splitting
Type a sentence below to see how an AI breaks human language down into token fragments (represented by different colors).
3. The Context Window: The AI’s Working Memory
Closely related to tokens is the Context Window. The context window is the amount of recent information the model can consider while generating a response. Think of it as the model’s working memory for your current conversation.
The Notebook Analogy: Imagine solving a complex math problem. You keep notes in a 10-page notebook. Eventually, you run out of space. To write more, you have to erase the oldest pages. The context window works in a similar way. If a conversation gets too long, the earliest messages “fall out” of the window, and the AI forgets them.
This directly relates to Cognitive Load Theory. The Context Window acts as the AI’s Working Memory. If you pack the prompt with too much extraneous information (Extraneous Load), the AI struggles to process the actual task (Germane Load). When the Working Memory fills up, older data doesn’t go to Long-Term Memory—it is simply permanently dropped.
3.1 Context Window vs. Long-Term Memory
| Feature | Context Window (Working Memory) | Long-Term Memory |
|---|---|---|
| Duration | Temporary (Only lasts for the current chat session) | Persistent (If enabled by the app, e.g., ChatGPT Memories) |
| Scope | Used only during one active conversation | Can persist across entirely different conversations |
| Limitation | Strictly limited by token capacity (e.g., 128k tokens) | Managed separately by external databases or RAG |
Interactive Simulation: Sliding Context Window
Simulation: The "Forgetting" Mechanism
This AI has a tiny context window limit of 3 messages. Add messages to the chat and watch what happens to the oldest information when the limit is exceeded.
4. Temperature: How Creative Should the AI Be?
This is one of the most fascinating backend settings of an LLM. Temperature controls how predictable or creative the model’s generated responses are. It doesn’t change what the model knows; it changes how adventurous it is when choosing the next token.
The Chef Analogy:
- Chef A (Low Temperature): Always follows the recipe exactly. Consistent, safe, and highly predictable.
- Chef C (High Temperature): Experiments with entirely new flavor combinations. Highly creative, diverse, but sometimes erratic.
(Important Note: Turning up the temperature does not make the AI smarter. It just flattens the probability curve, making the AI more willing to pick less obvious words!)
4.1 Temperature Use Cases
| Use Case | Recommended Temperature | Expected Output |
|---|---|---|
| Writing Production Code / Legal Docs | Low (0.0 - 0.3) | Highly consistent, factual, predictable. |
| Drafting Emails / Articles | Medium (0.4 - 0.7) | Balanced between standard phrasing and engaging flow. |
| Brainstorming / Poetry / Storytelling | High (0.8 - 1.2+) | Highly diverse, creative, and unique. |
Interactive Simulation: The Temperature Dial
Simulation: Next Token Selection via Temperature
Prompt: "The developer sat down and started to write..."
AI Completion:
The developer sat down and started to write code.
5. Hallucinations: Confident but Incorrect
This is a critical concept to grasp for everyday AI use. A hallucination occurs when an AI model generates information that sounds highly convincing but is factually incorrect, fabricated, or unsupported.
If you ask an AI, “Who won the FIFA World Cup in 1890?” a well-behaved model will state the tournament didn’t exist then. However, a hallucinating model might confidently declare: “England won the FIFA World Cup in 1890 in a thrilling match.”
5.1 Why Do Hallucinations Happen?
Remember how LLMs work: they are mathematical engines predicting the most likely next token. They do not have an internal “truth-checker” verifying statements against a real-world database. If a prompt is ambiguous or asks about a topic outside the model’s knowledge base, the model will simply stitch together plausible-sounding tokens that structurally look like a correct answer.
5.2 How to Reduce Hallucinations:
- Prompt Specificity: Ask clear, specific questions.
- Request Citations: Ask the AI to cite its sources or base its answer only on provided text.
- Chain of Thought: Break complex questions into smaller, logical steps (“Think step-by-step”).
- Human-in-the-Loop: Always verify high-stakes information (medical, legal, financial) independently.
Interactive Simulation: Anatomy of a Hallucination
Simulation: Plausibility vs. Truth
Observe how the LLM generates a response based on Statistical Plausibility rather than Truth when tricked.
(Note: This person/event never existed)
6. Putting Everything Together: The Lifecycle of a Prompt
When you type a message to ChatGPT, all these concepts happen in a fraction of a second. Here is the complete lifecycle of a single prompt happening inside a Transformer Neural Network.
Interactive Simulation: The AI Engine Room
Simulation: Step-by-Step AI Engine Room
Step 1: The User Prompt
User types: "Explain AI simply."
The raw text string is captured by the application interface. At this stage, it is just human-readable character data. Neural networks cannot do math on raw letters, so this text must be translated into a numerical format.
7. Common Misconceptions
8. Summary Glossary Table
| Concept | Simple Meaning |
|---|---|
| Prompt | The instruction or question you give the AI. |
| Token | The basic building block (sub-word fragment) processed by the model. |
| Context Window | The amount of recent conversation history the model holds in its active working memory. |
| Token Limit | The absolute maximum number of tokens the context window can hold at once. |
| Temperature | A setting controlling how predictable (low temp) or wildly creative (high temp) the AI is. |
| Hallucination | A confident but entirely incorrect or fabricated AI response. |
Did You Know?
- Tokens cost money!When you use a commercial AI API (like OpenAI or Anthropic), you are billed per 1,000 tokens processed, not per word or per hour.
- The Context Window is growing fast! In 2022, a standard context window was 4,096 tokens (about 3,000 words). By 2024, models like Gemini 1.5 Pro supported up to 2 million tokens—enough to upload entire books and codebases at once!
9. Beginner FAQs
1. If I upload a PDF, does it use up my Context Window?
Yes. Every single word and punctuation mark in that PDF is converted to tokens and placed into the context window. If the PDF is longer than the token limit, the AI will either reject it or "forget" the beginning of the document.
2.Can I set the Temperature to 0 to prevent hallucinations?
No. Setting the temperature to 0 makes the AI completely deterministic (it will always give you the same answer to the same prompt). It reduces *some* wild hallucinations, but if the AI fundamentally lacks the factual data, it will still confidently hallucinate a deterministic, incorrect answer.
10. What’s Next?
Now that you understand the mechanics of Large Language Models—from their Transformer engines to tokens, temperature, and context windows—it’s time to explore the amazing ecosystem built around them.
In Part 14, we will look at the heavyweights. We will compare the world’s most influential Generative AI models, including ChatGPT, Gemini, Claude, Llama, Midjourney, and more. You’ll learn who built them, what their strengths are, and which model is best suited for your specific daily tasks.