Module 1 — Understanding Large Language Models
How Large Language Models Work
Large Language Models (LLMs) are neural networks trained on massive text datasets to predict the next word in a sequence. Understanding how they work — even at a conceptual level — is essential for effective prompting.
Tokenisation: LLMs don't read words — they process tokens, which are chunks of text (roughly ¾ of a word on average). "Understanding" becomes two tokens: "Under" + "standing." This matters because LLMs have token limits (context windows), and pricing is typically per token.
The attention mechanism (the "T" in GPT stands for Transformer) allows the model to weigh the importance of every word in relation to every other word. When generating a response to "The cat sat on the ___", the model attends to "cat," "sat," and "on" to predict "mat" or "floor." In longer texts, attention allows the model to connect related concepts across paragraphs.
Autoregressive generation: LLMs generate text one token at a time, using everything generated so far as context for predicting the next token. Each token is selected from a probability distribution over the entire vocabulary. This is why the same prompt can produce different outputs — the model samples from probabilities rather than always choosing the most likely token.
Key Models & Generation Parameters
The LLM landscape is evolving rapidly. Major models include:
GPT-4/GPT-4o (OpenAI): Strong reasoning, broad knowledge, multimodal (text + images). The benchmark for general-purpose AI.
Claude (Anthropic): Excellent at nuanced, long-form text. Known for careful, balanced responses and strong safety features.
Gemini (Google): Multimodal from the ground up (text, images, audio, video). Excels at tasks combining modalities.
LLaMA / Mistral (Meta / Mistral AI): Open-source models that can be fine-tuned and run locally, offering data privacy advantages.
Generation parameters control how the model produces text:
Temperature (0-2): Controls randomness. Low temperature (0-0.3) = deterministic, focused, factual. High temperature (0.7-1.2) = creative, diverse, unpredictable. Use low for analysis and facts; high for brainstorming and creative writing.
Top-p (nucleus sampling) (0-1): Limits token selection to those whose cumulative probability exceeds p. Top-p of 0.9 means the model considers only the top 90% most likely tokens, ignoring unlikely options.
Max tokens: Limits response length. Set it appropriately for your use case — too low truncates useful output; too high wastes resources.
Frequency/presence penalty: Reduces repetition by penalising tokens that have already appeared.
Key Takeaways
- LLMs predict the next token based on statistical patterns learned from training data
- Tokenisation, attention, and autoregressive generation are the core mechanisms
- Temperature controls the randomness-determinism trade-off in output
- Different models have different strengths — choose based on your use case
- Understanding parameters enables precise control over AI output quality
Exercises & Activities
Temperature Experiment
Use any LLM (ChatGPT, Claude, Gemini) and give it the same prompt three times with different temperature settings (if available) or ask it to respond 'creatively' vs. 'precisely.' Prompt: 'Explain quantum computing in 3 sentences.' Compare the outputs. Which temperature/style was most appropriate? When would you choose each?
LLM Fundamentals
Test your understanding of how LLMs work.
What does 'autoregressive generation' mean?
What does a low temperature setting (e.g., 0.1) produce?
Interactive AI Tutor Session
Copy this prompt and paste it into your preferred AI assistant (ChatGPT, Claude, Gemini) to begin your interactive tutoring session for this module.
"You are an LLM researcher and educator. Explain how large language models work at a conceptual level — tokenisation, the attention mechanism, and autoregressive generation. Compare major models (GPT-4, Claude, Gemini). Explain temperature and sampling parameters with examples showing how they affect output. Ask the student to experiment with different temperature settings and report their observations."
