GenAI & LLMs crash course

Assessment

52 questions with answers, two sample papers and an answer key, mapped to the syllabus’s assessment split. Every numeric answer is computed by the course code when the page is built; short answers are model answers from the unit PDFs.

Sample papers (questions) (PDF)171 KBSample papers (questions) (Word)16 KBAnswer key (PDF)171 KBAnswer key (Word)14 KBQuestion bank with answers (PDF)182 KBQuestion bank with answers (Word)19 KB

How the syllabus weights assessment

ComponentWeight
Internal / continuous assessment30%
Laboratory20%
Mid-semester examination15%
End-semester examination25%
Capstone / project10%

The two sample papers cover the written parts (mid-semester 15%, end-semester 25%). The laboratory part is the lab track, and the capstone is Unit 11.

The sample papers

These are samples written by the course author for study. They are not past papers of any university, and the marks are a suggestion.

Question bank

Think first, then click a question to reveal the answer.

Unit 1

Which of these models learns the distribution of the data itself, so that it can generate new samples? (1 mark, easy)
Answer. C. A VAE models p(x) (through a latent variable); the others model p(y|x) or a decision boundary.
State the difference between a discriminative and a generative model, in terms of the probabilities each one models. (1 mark, easy)
Answer. A discriminative model learns p(y|x), the label given the input; a generative model learns p(x) or p(x,y), so it can produce new x.
Name the two terms of the VAE training objective and say what each one does. (2 marks, medium)
Answer. Reconstruction term: makes the decoder rebuild the input from the latent code. KL term: keeps the encoder's latent distribution close to the prior (a standard normal), so that sampling from the prior gives valid codes.
In a GAN, the discriminator is trained to: (2 marks, medium)
Answer. C.
An autoregressive model gives the exact likelihood of a sequence but a VAE only a bound. Explain why. (4 marks, hard)
Answer. An autoregressive model factorises p(x) = prod p(x_t | x_<t) exactly. A VAE needs the integral over the latent variable, which is intractable, so it maximises the evidence lower bound (ELBO) instead.

Unit 2

Self-attention computes each output as: (1 mark, easy)
Answer. B.
A Transformer block has model width d = 768. Using 12 d^2 parameters per block (attention 4d^2 plus feed-forward 8d^2, biases ignored), how many parameters does one block have? (2 marks, medium)
Answer. 12 x 768^2 = 7,077,888.
For sequence length n = 2,048 and width d = 1,024, give the number of floating-point operations of the attention scores and weighted sum, 4 n^2 d. (2 marks, medium)
Answer. 4 x 2,048^2 x 1,024 = 17,179,869,184 (about 17.2 GFLOPs per layer).
Why are the scores divided by sqrt(d_k)? (3 marks, medium-hard)
Answer. If query and key entries have unit variance, the dot product has variance d_k. Without scaling, large d_k pushes the softmax into a saturated region with tiny gradients. Dividing by sqrt(d_k) restores unit variance.
Positional encoding is needed because: (2 marks, medium)
Answer. C.
Why can a decoder-only model generate text with a causal mask while an encoder-only model such as BERT is not used for left-to-right generation? (4 marks, hard)
Answer. The causal mask lets position t see only positions <= t, so the model is trained to predict the next token and can be sampled one token at a time. BERT sees both sides during training (masked-token prediction), so it has no left-to-right factorisation to sample from.

Unit 3

The logits are (2, 1, 0). Give the softmax probabilities at temperature T = 1 and at T = 0.5. (1 mark, easy)
Answer. T = 1: (0.665, 0.245, 0.090). T = 0.5: (0.867, 0.117, 0.016). Lower temperature sharpens the distribution.
Top-p (nucleus) sampling keeps: (1 mark, easy)
Answer. B.
Describe the byte-pair-encoding training loop in three steps. (2 marks, medium)
Answer. (1) Start with characters as tokens. (2) Count all adjacent pairs and merge the most frequent pair into a new token. (3) Repeat for the chosen number of merges; the ordered list of merges is the tokenizer.
With the rule of thumb D = 20 N and compute C = 6 N D, find the compute-optimal parameters N and tokens D for C = 1e23 FLOPs. (3 marks, medium-hard)
Answer. N = sqrt(C/120) = 2.887e+10 parameters (about 28.9 billion); D = 20 N = 5.774e+11 tokens (about 577 billion).
Using L(N,D) = 1.69 + 406.4/N^0.34 + 410.7/D^0.28, compute the predicted loss for N = 7e9 and D = 1.4e11. (4 marks, hard)
Answer. L = 2.184.

Unit 4

A few-shot prompt differs from a zero-shot prompt in that it: (1 mark, easy)
Answer. A.
Five independent samples are each correct with probability 0.7, and wrong answers do not agree with each other. What is the probability that the majority answer is correct? (2 marks, medium)
Answer. P(at least 3 of 5 correct) = 0.8369.
Why should the output of a model that is asked for JSON be validated, and what do you do when validation fails? (2 marks, medium)
Answer. The model may return malformed or wrong-type output. Validate against a schema; on failure, retry with the error message in the prompt, up to a limit, then fail loudly.
Using the 4-characters-per-token heuristic, how many tokens are in a 2000-character prompt? (1 mark, easy)
Answer. 500 tokens (a rough estimate; use the model's own tokenizer for real budgets).
A chatbot keeps only the newest messages that fit in the context window. What can silently go wrong, and how do you prevent it? (4 marks, hard)
Answer. The oldest messages are dropped first, which can remove the user's name, constraints or few-shot examples. Pin the messages that must stay (system message, key facts) and trim the rest.

Unit 5

Compared with dense embeddings, BM25 is strongest when: (1 mark, easy)
Answer. B.
Reciprocal rank fusion with k = 60 combines two rankings. A document is ranked 1st by one ranker and 3rd by the other. Give its fused score. (2 marks, medium)
Answer. 1/(60+1) + 1/(60+3) = 0.03227.
A text of 1000 characters is chunked with window 300 and overlap 50 (word boundaries respected, text of the form 'word word ...'). How many chunks result? (2 marks, medium)
Answer. 4 chunks (computed with the course's chunk_text).
Give three ways a RAG system can fail. (2 marks, medium)
Answer. Retrieval misses the relevant chunk (vocabulary mismatch, bad chunking); the context is too long or noisy so the model ignores the right passage; the model answers from memory or invents text that the context does not support; the documents are outdated.
Recall@3 is 100% but the answers are only 90% correct. Where can the missing 10% come from, and how would you find out? (4 marks, hard)
Answer. Retrieval is fine; the loss is in selection or generation (right chunk, wrong sentence or a misreading). Evaluate stage by stage: the share of questions whose top chunk contains the fact, and the share of those answered correctly (Unit 11).

Unit 6

QLoRA differs from LoRA in that the frozen base weights are stored: (1 mark, easy)
Answer. C.
A weight matrix is 4096 x 4096. How many trainable parameters does a rank-8 LoRA adapter add, and what fraction of the matrix is that? (2 marks, medium)
Answer. r (d_out + d_in) = 8 x 8192 = 65,536; the matrix has 16,777,216 entries, so the fraction is 0.39%.
How much memory do the weights of a 7-billion-parameter model need at 16 bits and at 4 bits (weights only)? (2 marks, medium)
Answer. 16 bits = 2 bytes: 14 GB. 4 bits = 0.5 bytes: 3.5 GB.
What is catastrophic forgetting and name one way to reduce it. (3 marks, medium-hard)
Answer. Fine-tuning on a narrow task overwrites earlier abilities. Reduce it with a low learning rate or few steps, LoRA (the base weights stay frozen), or mixing in general data.
In supervised fine-tuning the loss is averaged over the response tokens only. Why mask the prompt tokens? (4 marks, hard)
Answer. The prompt is given context, not a target: training to reproduce it wastes capacity and lets prompt text dominate the gradient. The model should learn to produce the response given the prompt.

Unit 7

A vision transformer cuts a 224 x 224 image into 16 x 16 patches. How many image tokens? How many for a 336 x 336 image with 14 x 14 patches? (1 mark, easy)
Answer. 224 x 224 with 16 x 16 patches: 196 tokens. 336 x 336 with 14 x 14 patches: 576 tokens.
CLIP-style training makes matching image-text pairs: (2 marks, medium)
Answer. D. A contrastive loss over a batch.
State the closed form of the forward diffusion step and why it is useful for training. (3 marks, medium-hard)
Answer. x_t = sqrt(abar_t) x_0 + sqrt(1 - abar_t) eps with eps ~ N(0, I). Any noise level can be produced in one step from x_0, so training samples random t without simulating the chain.
What does the guidance weight w do in classifier-free guidance, and what is the cost of a large w? (4 marks, hard)
Answer. The noise estimate is pushed away from the unconditional prediction toward the conditional one: eps_hat = eps_uncond + (1 + w)(eps_cond - eps_uncond). A larger w follows the prompt more closely but reduces diversity and can distort the image.

Unit 8

In a ReAct-style agent loop the model alternates: (1 mark, easy)
Answer. D.
An agent must complete a chain of 10 steps. Each step succeeds with probability 0.95, independently. What is the probability that the whole chain succeeds? What if each step succeeds with 0.99? (2 marks, medium)
Answer. 0.95^10 = 0.599; 0.99^10 = 0.904.
Give two defences against prompt injection in a tool result. (3 marks, medium-hard)
Answer. Treat tool output as data, never as instructions; restrict the agent to an allowlist of tools and require confirmation for sensitive actions (such as sending email); filter or isolate untrusted text.
Five agents exchange messages for one round. In a fully connected design everyone tells everyone; in a hub design a manager talks to each worker and each worker replies. Count the messages in each design. (4 marks, hard)
Answer. Fully connected: n(n-1) = 20. Hub: 2(n-1) = 8.

Unit 9

BLEU mainly measures: (1 mark, easy)
Answer. C. It does not measure truth.
Two raters label 10 answers as good (1) or bad (0): A = [1, 1, 1, 0, 0, 1, 0, 1, 1, 0], B = [1, 1, 0, 0, 0, 1, 1, 1, 1, 0]. Compute Cohen's kappa. (2 marks, medium)
Answer. kappa = 0.583 (observed agreement 0.80, chance agreement 0.52).
A system answers 18 of 20 questions correctly. Give the 95% Wilson interval for its accuracy. (2 marks, medium)
Answer. [0.70, 0.97].
Name a bias of an LLM judge and a simple way to reduce it. (3 marks, medium-hard)
Answer. Position bias: the judge prefers the answer shown first. Ask twice with the order swapped and average, or discard inconsistent verdicts.
The Laplace mechanism adds noise with scale b = sensitivity / epsilon. For sensitivity 1 and epsilon = 0.5, give b and the standard deviation of the noise. (4 marks, hard)
Answer. b = 1/0.5 = 2.0; standard deviation = sqrt(2) b = 2.83.

Unit 10

Continuous batching improves serving because: (1 mark, easy)
Answer. D.
A model has 32 layers, 8 key-value heads of width 128 (hidden 4096, 32 heads) and a 16-bit cache. Bytes of KV cache per token, and for a 2000-token sequence? (2 marks, medium)
Answer. 2 x 32 x 8 x 128 x 2 = 131,072 bytes per token; for 2000 tokens 262,144,000 bytes (about 262 MB).
A rented GPU costs 2 dollars per hour, generates 1000 tokens per second when busy, and is busy 50% of the time. Dollars per million tokens? (3 marks, medium-hard)
Answer. 2 / (1000 x 0.5 x 3600) x 10^6 = 1.11 dollars.
Why report the 95th-percentile latency instead of the mean? (2 marks, medium)
Answer. The mean hides the slow tail that users notice; the 95th percentile says how slow the slowest 5% of requests are, which is what a service-level objective should bound.

Unit 11

List the five parts of a design brief and say why it is written before the code. (2 marks, medium)
Answer. User, data, minimum viable version, the one metric, main risk. Without a metric you cannot tell when the project works; writing it first stops you from choosing the metric after seeing the result.
34 of 40 answers are correct. Give the 95% Wilson interval. (2 marks, medium)
Answer. [0.71, 0.93].
A legal assistant judges a wrong answer 9 times as costly as a refusal. Above what probability that the documents contain the answer should it answer? (3 marks, medium-hard)
Answer. pi > c_H/(c_H + c_F) = 9/10 = 0.90.
You chose a refusal threshold on your evaluation questions and report the result on the same questions. What is wrong, and what do you do instead? (4 marks, hard)
Answer. The threshold is tuned to those questions, so the result is optimistic. Split into a development half (choose settings) and a test half (report once), and give confidence intervals because small sets are noisy.