AAI101 · Introduction to AI and Prompt Engineering · Unit 3
Generative AI and Large Language Models
Unit Scope & Exam Weightage: This unit moves from analysing data to creating content: text, images, code, audio and video. It explains what a large language model is, how it is trained, how tokens, context windows and temperature shape its output, and how image tools such as Stable Diffusion, Midjourney and DALL-E work. The two 2026-27 model papers carry 8 clusters worth 32 marks: short questions on audio, video and LLMs, 7-mark explanations of Tokens and context window, and 5-mark applications of Midjourney and DALL-E.
Front Page: Importance-Wise Topic Roadmap (2026-27 Model Papers)
| Priority | Topic (Exact Syllabus) | PYQs Asked | Marks Weightage | Tag |
|---|---|---|---|---|
| 1 | Tokens | 1 (2026-27 MP-S1) |
7m × 1 | High-Yield 7m |
| 2 | context window | 1 (2026-27 MP-S2) |
7m × 1 | High-Yield Numerical |
| 3 | Midjourney | 1 (2026-27 MP-S1) |
5m × 1 | Application |
| 4 | DALL-E (concept + demo) | 1 (2026-27 MP-S2) |
5m × 1 | Comparison |
| 5 | video | 2 (MP-S1, MP-S2) |
2m × 2 | Repeated Short |
| 6 | Large Language Models (LLMs) — what they are | 1 (2026-27 MP-S2) |
2m × 1 | Short |
| 7 | audio | 1 (2026-27 MP-S1) |
2m × 1 | Short |
| 8 | What is Generative AI — AI that creates text, images, code, Large Language Models (LLMs) — how they are trained (concept), temperature — simple explanation | 0 direct | — | Core Concept / Predicted |
| 9 | Popular LLMs — ChatGPT (OpenAI), Gemini (Google), Claude (Anthropic), Llama (Meta), Multimodal AI — text + image + voice in one model (GPT-4o, Gemini concept), AI image generation — Stable Diffusion | Integrated in #3, #4 | — | Tool Awareness |
| 10 | Limitations of LLMs — hallucination, knowledge cutoff, bias, Responsible use — academic integrity, plagiarism, AI-generated content disclosure Class Activity | 0 direct | — | Ethics / Predicted |
2-Hour Last-Night Survival Checklist:
- Token answer in three moves: tokens are sub-word pieces; text → token IDs → vectors → model predicts the next token; one token ≈ 4 English characters, so
prompt engineering≈ 2–3 tokens. Add a context-budget calculation to make the 7m answer concrete. - Context-window formula: available answer tokens = window − prompt − retrieved text − safety margin. For 4096 − 1800 − 1500 − 100 = 696 tokens left; write this subtraction in the exam.
- Audio/video 2m definitions: audio generation = model produces waveforms/speech from text or prompt (text-to-speech, music); video generation = model produces a sequence of consistent frames over time. Give one tool example each.
- Image-tool comparison: DALL-E/Midjourney are prompt-driven image generators; Stable Diffusion is an open diffusion model often run locally; the neighbouring idea "image classifier" only labels a picture, it does not create one. Keep this table ready.
- Limitations + ethics in one line each: hallucination = confident false answer; knowledge cutoff = training data ends at a date; bias = patterns of training data repeated; responsible use = verify, cite, disclose AI assistance, never submit unverified AI text as your own.
1. What is Generative AI
Definition (2 Marks): Generative AI is AI that creates new content — text, images, code, audio or video — from a prompt, rather than only classifying or predicting a label. It learns the statistical structure of examples and samples a new output that resembles that structure.
| Output type | What is generated | Representative tool / use |
|---|---|---|
| Text | Explanation, summary, story, report | ChatGPT, Gemini, Claude |
| Images | Picture from a description | Midjourney, DALL-E, Stable Diffusion |
| Code | Function, test case, script | ChatGPT, GitHub Copilot |
| audio | Speech, sound effect, music | Text-to-speech voice assistants; music models |
| video | Short clip or animation | Text-to-video models, generative video editing |
Mechanism in one line: prompt → tokens → model predicts a sequence of output tokens (or image/video patches) → decoded into text, pixels or sound.
Examiner Tip: The word "new" matters. A classifier that says "cat" is not generative; a model that draws a cat not present in the training set is. Examiners also award a point for naming at least three output modalities.
2. Large Language Models (LLMs) — what they are and how they are trained
LLM (2 Marks): A Large Language Model is a neural network, usually based on the Transformer architecture, with billions of parameters trained on very large text collections. Its job is to estimate the probability of the next token given the previous tokens, which lets it continue, summarise, translate and answer.
2.1 Concept-Level Training Pipeline
%%{init: {'theme': 'base', 'look': 'handDrawn', 'themeVariables': {'fontFamily': "'Nunito', sans-serif", 'fontSize': '16px', 'primaryColor': '#EFEAD6', 'primaryBorderColor': '#0F766E', 'lineColor': '#23211C'}}}%%
flowchart LR
A["Collect text corpus<br/>books, web, code"] --> B["Tokenise + clean"]
B --> C["Pre-train:<br/>predict next token"]
C --> D["Fine-tune on instructions<br/>+ human feedback"]
D --> E["Deploy behind<br/>chat interface / API"]
- Pre-training: the model sees huge text and repeatedly guesses the next token; each wrong guess adjusts weights. No human writes the answers.
- Fine-tuning / alignment: instruction-answer pairs and human feedback teach it to follow requests and refuse harmful ones.
- Inference: at use time, the model only predicts tokens; it does not look up a database unless a retrieval tool is connected.
Syllabus career connect: Every professional today uses at least one Generative AI tool; Understanding how LLMs work makes students better users and future developers. An engineer who knows the token-prediction mechanism can judge when an output is plausible but wrong instead of accepting it blindly.
2.2 Popular LLMs (Exam Awareness)
| Model | Organisation | Notable point |
|---|---|---|
| ChatGPT (OpenAI) | OpenAI | Conversational assistant; GPT-4o accepts text, image and voice |
| Gemini (Google) | Multimodal model integrated with Google services | |
| Claude (Anthropic) | Anthropic | Long-context assistant, emphasis on careful responses |
| Llama (Meta) | Meta | Open-weight family, widely used for local research and apps |
2.3 Multimodal AI — text + image + voice in one model (GPT-4o, Gemini concept)
A multimodal model converts different input types into a shared token-like representation: an image is split into patches, speech into audio frames, text into sub-word tokens. One network then reasons over the combined sequence. Example: point a phone camera at a circuit board and ask "Which component is burnt?" — the answer uses both the photo and the question.
3. Tokens, context window and temperature
Token: the small unit of text an LLM reads and writes. It may be a word, part of a word or punctuation. Example: unhappy may split into un + happy; prompt engineering into prompt + engineer + ing.
3.1 Tokenisation Worked Example
Text: "The pump is faulty."
| Possible tokens | Count |
|---|---|
The, pump, is, fault, y, . |
6 |
Each token is converted to an integer ID and then to a vector. The model does not see letters; it sees the sequence of IDs and predicts the next ID.
3.2 Context Window
Context window = maximum number of tokens the model can consider in one request (prompt + previous chat + inserted documents + its own answer). If content exceeds it, the earliest tokens are dropped or truncated.
Worked budget: window = 4096 tokens; system instruction = 300 tokens; user question = 1500 tokens; retrieved engineering manual extract = 1500 tokens; reserve for answer = 100 tokens.
If a 2000-token manual is inserted instead, only 196 tokens remain and the answer would be cut off — the practical reason to summarise long documents first.
3.3 Temperature — simple explanation
Temperature scales the model's scores before probabilities are computed. Low makes the highest-probability token dominate (focused, repetitive); high flattens the distribution (creative, riskier).
| Score for three candidate next words | probability | probability | probability |
|---|---|---|---|
| A = 2.0 | 0.864 | 0.659 | 0.502 |
| B = 1.0 | 0.117 | 0.242 | 0.304 |
| C = 0.1 | 0.019 | 0.099 | 0.194 |
Values obtained from softmax(score/T). Exam conclusion: use – for factual engineering answers, – for brainstorming.
Examiner Tip: Never say temperature "makes the model smarter". It only changes the randomness of token selection; knowledge comes from training.
4. AI image generation — Stable Diffusion, Midjourney, DALL-E (concept + demo)
Diffusion idea: the model is trained by adding noise to images and learning to reverse that noise. At generation time it starts from random noise and repeatedly denoises it under the guidance of the text prompt until an image appears.
| Tool | Access style | Strength | Exam phrase |
|---|---|---|---|
| Stable Diffusion | Open model, can run locally | Control, custom models | "Open diffusion model" |
| Midjourney | Prompt service, strong aesthetics | Stylised concept art and diagrams | "Prompt-driven image generator" |
| DALL-E (concept + demo) | Prompt service integrated with chat tools | Good prompt adherence, editable edits | "Text-to-image generation from a natural-language prompt" |
Demo workflow: write prompt → generator samples noise → denoising guided by prompt → image returned → user refines prompt (add material, lighting, viewpoint) and regenerates.
| Generated image task | Weak prompt | Better prompt |
|---|---|---|
| Bridge crack illustration | "draw a bridge" | "side view of a concrete bridge girder, one visible diagonal crack, daylight, labelled technical sketch" |
| Fabric defect sample | "bad cloth" | "woven cotton fabric with a single broken-thread defect, top-down view, neutral lighting" |
Examiner Tip: For 5 marks, give the tool's definition, the diffusion mechanism in three steps, one worked prompt with the required result, and one limitation (hands/text may be distorted).
5. Limitations of LLMs and responsible use
| Limitation | What it means | Engineering example | Safe response |
|---|---|---|---|
| hallucination | Confident, invented answer | Citing a non-existent IS code clause | Verify against the actual standard |
| knowledge cutoff | Training data ends at a date | Unaware of a new 2026 code amendment | Supply current data or search tool |
| bias | Training patterns repeated | Assuming a "typical" patient profile | Check affected groups and state assumptions |
| Privacy | Prompt may contain sensitive data | Sharing client structural drawings | Remove identifiers before prompting |
| Academic integrity / plagiarism | AI text presented as one's own | Copying an entire assignment answer | Disclose AI use and write own analysis |
Responsible-use checklist for students: (1) verify every factual claim; (2) show the prompt used; (3) disclose AI-generated content where required; (4) do not paste confidential data; (5) take responsibility for the final answer.
5.1 Class Activity: Students interact with ChatGPT/Gemini/Claude
The syllabus frames this as an AI-generated content disclosure Class Activity: Students interact with ChatGPT/Gemini/Claude, observe how different inputs give different outputs, and identify one hallucination example. Ask the same branch question (e.g., "What is the typical compressive strength of M30 concrete at 28 days?") to three tools, note differences, then deliberately ask a question with a false premise ("Which IS code mandates a 3 mm crack limit for all bridges?"). Explain that the model completed a plausible pattern rather than checking a rule, and record which tool output was disclosed as AI-generated.
Examiner Tip: The phrase "verify, disclose, do not paste confidential data" is worth marks in any 5m/7m ethics question. Link hallucination to the next-token objective: the model optimises plausibility, not truth.
Solved Exam-Ready Questions (Verbatim Model-Paper Wording)
Solved Q1 (2026-27 Model Paper (Set 1), 2 Marks)
Q: "Define audio and state its role in Generative AI and Large Language Models."
Solution:
- Definition: In generative AI, audio is an output modality consisting of generated speech, sound or music — a waveform produced from a text prompt or another audio input.
- Role: It extends generative models beyond text so a model can speak an answer (voice assistant), clone a chosen voice with permission, or create soundtracks. In LLMs it is the final decoding step of speech interfaces: text tokens → acoustic features → audio waveform.
Solved Q2 (2026-27 Model Paper (Set 1), 2 Marks)
Q: "Define video and state its role in Generative AI and Large Language Models."
Solution:
- Definition: Video is a time-ordered sequence of images; generative video models create new frames whose content remains consistent across time from a text or image prompt.
- Role: It adds the time dimension to generation: useful for animation, simulation of a machine sequence, and short explanatory clips; in multimodal LLMs it can also be an input that the model describes.
Solved Q3 (2026-27 Model Paper (Set 1), 7 Marks)
Q: "Explain Tokens with its definition, mechanism, and one worked application from Generative AI and Large Language Models."
Solution:
- Definition (1m): A token is the smallest text unit processed by an LLM — a word, sub-word or punctuation mark; text is converted to token IDs before the model sees it.
- Mechanism (3m): tokeniser splits the prompt → each token ID becomes a vector embedding → the Transformer predicts the probability of the next token → one token is chosen → appended to the sequence → repeat until a stop condition. Tokens also determine billing and context-window usage; roughly 4 English characters ≈ 1 token.
- Worked application (2m): Prompt "The pump is faulty." tokenises as
The | pump | is | fault | y | .= 6 tokens. With a 4096-token window and 300+1500+1500 tokens already consumed, only 696 tokens remain for the answer (Section 3.2); the user therefore asks for a 100-word reply instead of a full manual. - Result (1m): Token control lets a student predict cost, avoid truncation and design shorter prompts.
Solved Q4 (2026-27 Model Paper (Set 1), 5 Marks)
Q: "Apply Midjourney to an examination problem from Generative AI and Large Language Models: state the rule, show the working, and report the result."
Solution:
- Rule: Midjourney converts a descriptive prompt into an image by guided diffusion; prompt specificity (subject, view, style, constraints) controls the result. Refine the prompt when the output misses the requirement.
- Working: Task = produce a labelled teaching image of a bridge crack. Draft 1: "bridge" → generic bridge, no crack. Draft 2: "side view of concrete girder with one diagonal crack, daylight, technical sketch" → crack appears but no label. Draft 3: add "thin arrow label 'flexural crack', plain white background". Generate and inspect each draft.
- Result: Draft 3 satisfies the examiner's requirement; the image is a generated illustration, so it must be disclosed and must not be presented as a photograph of a real structure.
Solved Q5 (2026-27 Model Paper (Set 2), 2 Marks)
Q: "List the two scored features of video expected in Generative AI and Large Language Models."
Solution:
- A video is a sequence of frames with temporal consistency; a generative video model creates those frames from a prompt rather than recording them.
- It can serve both as output (animated explanation, simulation) and as input to a multimodal model (the model interprets actions in a clip).
Solved Q6 (2026-27 Model Paper (Set 2), 2 Marks)
Q: "List the two scored features of Large Language Models (LLMs) — what they are expected in Generative AI and Large Language Models."
Solution:
- An LLM is a large neural network (usually Transformer-based) trained on massive text to predict the next token.
- It generates new language — answers, summaries, translations, code — from a prompt; examples are ChatGPT, Gemini, Claude and Llama.
Solved Q7 (2026-27 Model Paper (Set 2), 7 Marks)
Q: "Derive or outline context window step by step, include a suitable comparison, and state the examiner result for Generative AI and Large Language Models."
Solution:
- Step 1 — Define: the context window is the maximum token count the model can attend to in one request, including prompt, history, inserted documents and its reply.
- Step 2 — List consumers: system message, user question, retrieved text, previous turns, reserved answer tokens.
- Step 3 — Calculate: with a 4096-token window, 300 system + 1500 user + 1500 document + 100 reserve → 696 tokens free for the answer.
- Step 4 — Show overflow: inserting a 2000-token document leaves only 196 tokens; earlier content is dropped, so instructions placed at the very beginning may be lost.
- Step 5 — Compare: a small window (e.g., 2K) is cheap but forgets long chats; a large window (e.g., 32K+) handles manuals but costs more and can dilute attention to key lines.
- Step 6 — Mitigation: summarise long documents, retrieve only relevant passages, and place the vital instruction near the end.
- Examiner result: Context-window management determines whether the full relevant information reaches the model; exceeding it causes truncation and wrong answers.
Solved Q8 (2026-27 Model Paper (Set 2), 5 Marks)
Q: "Compare the use of DALL-E (concept + demo) with one neighbouring idea in Generative AI and Large Language Models, then solve a short case."
Solution:
- Comparison: DALL-E creates a new image from a text prompt using diffusion; the neighbouring idea "image classification" (Unit 2 CNN) only assigns a label to an existing image. Generation produces pixels; classification produces a class score. Both use learned visual features, but their outputs are opposite in direction.
- Short case: A civil student needs a diagram of a reinforced beam section for a class slide. With DALL-E: prompt "cross-section of RC beam, four longitudinal bars, stirrups, clean labelled diagram" → new image; the student checks bar count. With a classifier: upload a photo of a real beam → output "beam section". Only DALL-E supplies the missing illustration.
- Result: Use generation when the asset does not exist; use classification when you need to interpret an asset you already have. Disclose the generated figure.
Practice Questions (Self-Test)
- (2 Marks) Give one example each of generative text, image, code, audio and video output.
- (2 Marks) State the difference between pre-training and fine-tuning of an LLM.
- (5 Marks) Tokenise the sentence "The valve is leaking." and explain why token count matters.
- (5 Marks) A model has an 8192-token window; instruction 500, chat history 2000, document 4000. How many tokens remain for the answer? (Ans: 1592 before reserve.)
- (7 Marks) Explain hallucination, knowledge cutoff and bias with one example each, and give three responsible-use rules.
- (7 Marks — Predicted) Explain how a multimodal model can help an ECE student inspect a defective circuit-board photograph, naming the input stages and one failure mode.