AI Computer Institute
Expert-curated CS & AI curriculum aligned to CBSE standards. A bharath.ai initiative. About Us

Grade 12 AI & Computer Science Practice Questions — Set 9

20 questions from the Grade 12 bank, each with its answer and a full explanation. Set 9 of 11 · 221 questions in this grade.

Reading is revision; testing is practice. Take the same questions as a timed quiz →

Question 161 · Weight Initialization Strategies: From Xavier to Kaiming · hard

A fully-connected layer in a deep ReLU network maps 512 input units to 512 output units. Weights are drawn i.i.d. from a zero-mean distribution, and the pre-activations feeding into this layer are symmetric around zero. Using the He (Kaiming) variance-preservation derivation — which explicitly accounts for ReLU zeroing out roughly half the pre-activations — what standard deviation should these weights be initialized with, and why does it differ from Xavier's value of roughly 0.0442 for this same layer?

  1. σ = 1/16 = 0.0625, because Var[W] = 2/n_in = 2/512; the factor of 2 corrects for ReLU zeroing out roughly half the pre-activations, an effect Xavier's derivation (built for symmetric activations like tanh) never accounts for
  2. σ = 1/√512 ≈ 0.0442, identical to Xavier's value, because ReLU's zeroing of negative pre-activations is exactly offset by its unbounded positive range, leaving the output variance equal to the input variance on average
  3. σ = 2/512 = 0.0039, because Var[W] = 2/n_in already gives the standard deviation directly once the ReLU correction factor is folded in, so no square root is needed
  4. σ = √(4/512) ≈ 0.0884, because preserving variance through both the forward activation pass and the backward gradient pass under ReLU requires applying the factor-of-2 correction twice, multiplying Xavier's variance by 4 rather than 2

Answer: A. σ = 1/16 = 0.0625, because Var[W] = 2/n_in = 2/512; the factor of 2 corrects for ReLU zeroing out roughly half the pre-activations, an effect Xavier's derivation (built for symmetric activations like tanh) never accounts for

ExplanationFollow the variance-propagation argument He et al. used to derive Kaiming initialization. For layer l, the pre-activation is y_l = W_l x_l, where x_l = ReLU(y_{l-1}). With weights i.i.d., zero-mean, variance Var[W], and independent of the inputs: Var[y_l] = n_in · Var[W] · E[x_l²] Note E[x_l²] is used, not Var[x_l], because x_l = ReLU(y_{l-1}) is not zero-mean. If y_{l-1} is symmetric around zero, ReLU sets the negative half to exactly 0 and passes the positive half through unchanged, so: E[x_l²] = E[ReLU(y_{l-1})²] = (1/2)·E[y_{l-1}²] = (1/2)·Var[y_{l-1}] Substituting back: Var[y_l] = n_in · Var[W] · (1/2) · Var[y_{l-1}]. To keep the variance stable across layers (Var[y_l] = Var[y_{l-1}]), the coefficient must equal 1: n_in · Var[W] · (1/2) = 1 ⟹ Var[W] = 2/n_in With n_in = 512: Var[W] = 2/512 = 1/256 = 0.00390625, so σ = √(1/256) = 1/16 = 0.0625. This is exactly the He/Kaiming rule, and the factor of 2 (versus Xavier's factor of 1, or equivalently 2/(n_in+n_out) when n_in = n_out) exists purely because ReLU deletes half the signal's second moment — Xavier's derivation assumes a roughly linear, symmetric activation (like tanh near zero) with no such deletion, so it under-scales the weights for ReLU networks and biases the network toward vanishing activations in deep stacks. For comparison, Xavier here gives σ = 1/√512 ≈ 0.0442, and indeed 0.0625 / 0.0442 ≈ √2, matching the well-known result that Kaiming's std is √2 times Xavier's. The remaining choices trace common errors: one drops the square root and reports the variance (0.0039) as if it were the standard deviation; one assumes ReLU's clipping has no net effect on variance and reuses Xavier's value unchanged; and one double-applies the correction factor (treating forward- and backward-pass preservation as requiring separate, multiplicative factor-of-2 corrections) even though He initialization only ever uses a single factor of 2 tied to one fan mode (fan_in or fan_out), not both at once.

Question 162 · Pipeline Parallelism: Minimizing Bubble Overhead · hard

A team building a large language model at an Indian AI research lab (using a compute cluster comparable to those at IIT Bombay's AI groups) trains its model with synchronous GPipe-style pipeline parallelism across P = 8 GPU stages. Each stage takes t = 5 ms to run one microbatch's combined forward-and-backward computation, uniform across all stages. For a pipeline flush processing M microbatches, the bubble (idle-time) fraction is (P − 1)/(M + P − 1). What is the minimum whole number of microbatches M needed to keep the bubble fraction at or below 10%?

  1. 70 microbatches
  2. 73 microbatches
  3. 63 microbatches
  4. 62 microbatches

Answer: C. 63 microbatches

ExplanationWith P = 8 stages, P − 1 = 7 is the fixed "fill-and-drain" bubble every stage sits through while the first microbatch propagates through the pipeline and the last one drains back out. That 7-unit idle cost does not shrink as M grows, so its impact must be measured against the *entire* flush length (M + P − 1), not against M alone. Set up the inequality using the given formula: 7/(M + 7) ≤ 0.10 Multiply both sides by (M + 7), which is positive: 7 ≤ 0.10(M + 7) = 0.1M + 0.7 Subtract 0.7 from both sides: 6.3 ≤ 0.1M Divide by 0.1: M ≥ 63 Check the boundary directly, since M must be a whole number. At M = 63: bubble fraction = 7/(63 + 7) = 7/70 = 0.10 exactly — this meets "at or below 10%." At M = 62: bubble fraction = 7/(62 + 7) = 7/69 ≈ 0.1014, i.e., 10.14% — this exceeds 10%. So 63 is the smallest microbatch count that satisfies the target, confirming M ≥ 63 is tight. The distractors trace two real misconceptions and a rounding slip. 70 comes from using the loose asymptotic form (P − 1)/M ≤ 0.10 (giving 7/M ≤ 0.10, M ≥ 70) instead of the exact formula — this ignores that the flush's wall-clock length is (M + P − 1), not M, so it overstates how many microbatches are needed. 73 comes from mistakenly putting P (= 8) in the numerator instead of P − 1 (= 7), treating every stage as fully idle during fill/drain rather than recognizing that only P − 1 stage-slots are ever empty at once. 62 is the boundary value with the inequality direction flipped — rounding 62.3 down instead of up, which leaves the bubble fraction just above the 10% target. This is exactly why production systems like GPipe and PipeDream push toward many small microbatches: the fixed (P − 1) bubble cost gets amortized over more useful work as M increases, driving the idle fraction toward zero even though the absolute bubble time per flush stays constant at (P − 1)·t = 35 ms.

Question 163 · Mixed Precision Training: Float16 and Beyond · hard

Mixed-precision training keeps master weights in FP32 but runs the forward/backward pass in FP16 (IEEE 754 half precision: 1 sign bit, 5 exponent bits with bias 15, 10-bit mantissa) to exploit GPU tensor cores — a technique Indian AI labs rely on to train multilingual LLMs under tight GPU budgets. FP16's smallest positive normal number is 2^-14, and its smallest positive subnormal number is 2^-24 (subnormals have no implicit leading 1, so near 2^-24 almost none of the 10 mantissa bits carry real information). Suppose one gradient's true FP32 magnitude is exactly 2^-24 — FP16's smallest representable subnormal, one quantization step above zero. To use loss scaling and lift this gradient to exactly FP16's smallest normal value, 2^-14, before the backward pass, by what power-of-two factor S must the loss (and every gradient with it) be multiplied?

  1. S = 1024 (2^10), because 2^-14 divided by 2^-24 equals 2^10, exactly lifting the gradient from the smallest subnormal to the smallest normal FP16 value.
  2. S = 16384 (2^14), matching the exponent bias-derived magnitude of FP16's smallest normal number itself rather than the ratio between the two thresholds.
  3. S = 16,777,216 (2^24), scaling the gradient all the way up to order 1.0 so it sits safely in the middle of FP16's dynamic range.
  4. S = 128, the fixed loss-scale constant used by default in several early mixed-precision training implementations, applied here without checking whether it actually clears the subnormal threshold.

Answer: A. S = 1024 (2^10), because 2^-14 divided by 2^-24 equals 2^10, exactly lifting the gradient from the smallest subnormal to the smallest normal FP16 value.

ExplanationLoss scaling multiplies the scalar loss L by S before calling backward(); by the chain rule, d(S·L)/dw = S · dL/dw, so every gradient in the graph gets scaled by the same factor S. Here the gradient's true magnitude is 2^-24, and the target is FP16's smallest normal value, 2^-14. Solving S · 2^-24 = 2^-14 gives S = 2^-14 / 2^-24 = 2^10 = 1024. Scaling the loss by 1024 moves this gradient from the extreme edge of the subnormal range — where its mantissa field held only a single nonzero bit (0000000001), giving essentially zero relative precision — into the normal range, where the implicit leading 1 plus the full 10-bit mantissa restore roughly three decimal digits of relative precision. After the backward pass, the FP32 optimizer divides the accumulated gradients by 1024 again before the weight update, so the final update matches what full FP32 precision would have produced; the scale factor only widens precision during the FP16 computation itself. A factor of 16384 (2^14) overshoots to 2^-10 — a valid normal number, but not the smallest one requested. A factor of 2^24 pushes the gradient all the way to 1.0, which is unnecessarily aggressive: since FP16's largest representable magnitude is only about 65504, such a large uniform scale risks pushing other, bigger gradients in the same batch into overflow (inf). A fixed scale of 128 — a common early default before dynamic loss scaling was standard — leaves this particular gradient at 128 × 2^-24 = 2^-17, still well inside the subnormal range and still short on precision, showing why a single hardcoded constant cannot safely cover every gradient's dynamic range.

Question 164 · Speculative Decoding: Speeding Sequential Generation · hard

An Indian startup deploys a customer-support chatbot using speculative decoding: a fast draft model proposes γ = 4 candidate tokens per round, and the large target model verifies all 4 in a single parallel forward pass. Under the modified rejection-sampling scheme (which guarantees the final output is distributed exactly as if sampled from the target model alone), each proposed token is accepted independently with probability α = 0.8. Generation proceeds token-by-token within the draft window: the instant a token is rejected, the target model samples one corrective token from its own residual distribution and the round ends; if all 4 proposed tokens are accepted, the target model also emits one bonus token from its next-position distribution (since its single forward pass already computed those logits for free). Let X be the number of tokens finalized in one round. What is E[X], correct to two decimal places?

  1. Summing the geometric series gives E[X] = (1 − 0.8^5)/(1 − 0.8) ≈ 3.36 tokens per round.
  2. Multiplying γ by α gives E[X] = 4 × 0.8 = 3.20 tokens per round.
  3. Assuming rejection never occurs, E[X] = γ + 1 = 5.00 tokens per round.
  4. Dropping the final bonus term, E[X] = (1 − 0.8^4)/(1 − 0.8) ≈ 2.95 tokens per round.

Answer: A. Summing the geometric series gives E[X] = (1 − 0.8^5)/(1 − 0.8) ≈ 3.36 tokens per round.

ExplanationThe clean way to compute E[X] for this stopping process is the identity E[X] = Σ_{m=0}^{∞} P(X ≥ m+1), valid for any non-negative integer-valued random variable. Here X ≥ m+1 happens exactly when the first m proposed draft tokens are all accepted — nothing about position m+1 matters yet — so P(X ≥ m+1) = α^m for m = 0, 1, 2, 3, 4 (the m = 0 term is just P(X ≥ 1) = 1, since a round always finalizes at least one token; the m = 4 term, α^4, is the branch where all 4 draft tokens survive and the guaranteed bonus token still follows). So E[X] = Σ_{m=0}^{4} 0.8^m = 1 + 0.8 + 0.64 + 0.512 + 0.4096, which is a finite geometric progression with first term a = 1, common ratio r = 0.8, and n = γ + 1 = 5 terms. Applying the standard GP sum formula S_n = a(1 − r^n)/(1 − r): E[X] = (1 − 0.8^5)/(1 − 0.8) = (1 − 0.32768)/0.2 = 0.67232/0.2 = 3.3616 ≈ 3.36 tokens per round. This number is the entire point of speculative decoding: a single expensive target-model forward pass, which costs about the same whether it verifies 1 token or γ+1 tokens in parallel, now yields 3.36 finalized tokens on average instead of 1 — a raw ~3.36x reduction in the number of sequential target-model calls needed per generated token (before subtracting the extra compute spent running the cheap draft model γ times per round). Multiplying γ by α (4 × 0.8 = 3.20) is a tempting shortcut because it lands close to the right answer, but the reasoning is wrong: it treats the 4 draft tokens as if their acceptances are independently averaged, when in fact the process stops dead at the first rejection, and it silently ignores the corrective/bonus token that fires on literally every round without exception — two errors that happen to nearly cancel numerically, which is exactly what makes this distractor dangerous. Assuming γ + 1 = 5.00 implicitly sets α = 1, erasing the very reason a target model needs to verify anything — if the draft model were always correct there would be no acceptance/rejection step at all, and speculative decoding would just be running the small model alone. Building the geometric series correctly but stopping at (1 − 0.8^4)/(1 − 0.8) ≈ 2.95 counts only the tokens accepted before the first rejection and forgets that the branch where all 4 tokens are accepted (probability 0.8^4 = 0.4096) still contributes one further bonus token, which is exactly the missing m = 4 term in the sum.

Question 165 · Vector Databases: Building Semantic Search Infrastructure · hard

A CBSE Class 12 college's AI doubt-resolution portal converts every student question into an embedding vector before searching its FAQ database for the closest match. A student's query is embedded as Q = (3, 4). Two candidate FAQ answers are embedded as A = (6, 8) and B = (4, 3). The portal's vector database ranks candidates by cosine similarity — the standard choice for semantic search, since an embedding's magnitude often reflects incidental properties like answer length rather than its meaning. Which candidate is returned as the top match, and how would the ranking change if the portal instead used raw Euclidean distance between the embeddings?

  1. The top match by cosine similarity is Document A, with cos θ = 50/(5×10) = 1.0 because A = 2Q places both vectors along the same direction; switching to Euclidean distance flips the ranking to Document B (≈1.41 units away versus 5.0 for A), since distance depends on magnitude while cosine similarity does not.
  2. Document B wins under both metrics: cosine similarity ranks it first (cos θ = 24/25 = 0.96) and Euclidean distance confirms this, since a smaller angle between two embeddings always produces a smaller Euclidean distance between them regardless of magnitude.
  3. A cosine similarity of exactly 1.0 between the query and Document A guarantees Document A is also the nearest neighbour by Euclidean distance, so both metrics rank Document A first, with A being closer to Q than Document B in raw distance as well.
  4. Because Document B's embedding (4, 3) has a smaller magnitude than Document A's embedding (6, 8), the vector database's cosine similarity calculation favors B, ranking it first ahead of A regardless of the actual angle between each vector and the query.

Answer: A. The top match by cosine similarity is Document A, with cos θ = 50/(5×10) = 1.0 because A = 2Q places both vectors along the same direction; switching to Euclidean distance flips the ranking to Document B (≈1.41 units away versus 5.0 for A), since distance depends on magnitude while cosine similarity does not.

ExplanationStart with the dot product and magnitudes needed for cosine similarity. For Q=(3,4) and A=(6,8): Q·A = (3)(6)+(4)(8) = 18+32 = 50, |Q| = √(9+16) = 5, and |A| = √(36+64) = 10, so cos θ = 50/(5×10) = 1.0 — a perfect match, which makes sense because A = 2Q, so A points in exactly the same direction as Q. For Q and B=(4,3): Q·B = (3)(4)+(4)(3) = 24, |B| = √(16+9) = 5, giving cos θ = 24/25 = 0.96. Since 1.0 > 0.96, the cosine-similarity index returns Document A as the top match. Now compute the Euclidean distances the same query would face under a distance-based index: |Q−A| = √((3−6)²+(4−8)²) = √(9+16) = 5.0, while |Q−B| = √((3−4)²+(4−3)²) = √(1+1) ≈ 1.41. Document B is more than three times closer to Q in raw distance, even though it is less aligned in direction. Switching the ranking metric therefore flips the winner from A to B. This divergence is exactly why production vector databases default to cosine similarity (or equivalently, L2-normalize embeddings before using dot-product/Euclidean search): a smaller angle between two vectors does not guarantee a smaller Euclidean distance between them, because distance also depends on how far each vector's magnitude sits from the other's — Document A's magnitude (10) is twice Q's (5), which inflates its Euclidean distance despite zero angular difference. Cosine similarity strips magnitude out of the comparison entirely, so it is not "biased" toward either larger- or smaller-magnitude embeddings — it measures direction alone, which is what a well-trained embedding model uses to encode semantic meaning.

Question 166 · Semantic Search at Scale: From Theory to Production · hard

A semantic search system for an Indian e-commerce marketplace indexes 10 million product descriptions as unit-normalized 768-dimensional embeddings, so cosine similarity between the query and each product reduces to a single dot product. Computing one 768-dimensional dot product costs 768 multiplications plus 768 additions (2 FLOPs per dimension). The serving hardware sustains 4×10⁹ FLOPs/second, and the product page must return results within a 50 ms end-to-end latency budget. By what factor does an exact brute-force scan over all 10 million embeddings exceed this latency budget?

  1. The search comfortably meets the budget, finishing in roughly 2.5 ms — this follows if you divide the corpus size directly by the throughput figure without accounting for the 768 multiply-add operations each dot product actually requires.
  2. About 38.4× over budget — if you count only one FLOP per multiply-add (forgetting that a dot product needs both a multiplication and an addition per dimension), you underestimate the true compute cost by half.
  3. About 76.8× over budget — brute force needs roughly 3,840 ms (10,000,000 × 768 × 2 FLOPs, divided by 4×10⁹ FLOPs/s) against the 50 ms limit, which is exactly why production systems replace this O(N·d) scan with an O(log N) index such as HNSW.
  4. About 7.68× over budget — treating the corpus as 1 million products instead of 10 million understates the total dot-product cost by a full order of magnitude.

Answer: C. About 76.8× over budget — brute force needs roughly 3,840 ms (10,000,000 × 768 × 2 FLOPs, divided by 4×10⁹ FLOPs/s) against the 50 ms limit, which is exactly why production systems replace this O(N·d) scan with an O(log N) index such as HNSW.

ExplanationSince every embedding is unit-normalized, cosine similarity collapses to a plain dot product, and each 768-dimensional dot product costs 2 × 768 = 1,536 FLOPs (768 multiplications plus 768 additions — a multiply-add pair per dimension). Scanning all 10,000,000 product embeddings therefore costs 10,000,000 × 1,536 = 1.536 × 10¹⁰ FLOPs total. At a sustained throughput of 4 × 10⁹ FLOPs/second, that scan takes 1.536×10¹⁰ ÷ 4×10⁹ = 3.84 seconds = 3,840 ms. Measured against the 50 ms latency budget, that is 3,840 ÷ 50 = 76.8 times too slow. This gap is exactly why production semantic search never runs brute-force cosine similarity at this scale: approximate nearest-neighbour structures such as HNSW (graph-based greedy search) or IVF-PQ (clustering plus quantization) trade a small, tunable amount of recall for query complexity that grows roughly as O(log N) instead of O(N·d), bringing a 3.84-second exhaustive scan down into the low-millisecond range without touching the underlying embeddings. The wrong answers correspond to real errors students make on this calculation: dropping the multiply-add factor of 2 gives 38.4×; misreading the corpus size as 1 million instead of 10 million gives 7.68×; and forgetting that each comparison itself costs 768 FLOPs (treating throughput as "dot products per second" rather than "FLOPs per second") makes the scan look like it finishes in 2.5 ms when it actually takes over three and a half seconds.

Question 167 · Few-Shot and In-Context Learning · hard

An Indian fintech startup deploys a customer-support LLM with a system prompt containing 4 in-context example dialogues, each showing how to answer a UPI refund-status query. Under the "in-context learning as implicit Bayesian inference" view (Xie et al.), the model maintains a hidden belief over two possible response concepts: Concept A — reply in casual Hinglish, matching the app's UI tone — and Concept B — reply in formal English. Before seeing any examples the model's implicit prior is 50:50 between A and B. Each of the 4 demonstrations is conditionally independent given the concept, and each one is 3 times more likely to have been generated under Concept A than under Concept B (a per-example likelihood ratio of 3). No gradient updates occur — the model only performs a forward pass over the prompt. According to this Bayesian view, what probability does the model's implicit posterior assign to Concept A after reading all 4 demonstrations?

  1. About 98.8% (posterior odds 81:1) — Bayesian updating multiplies the likelihood ratio across independent shots: odds = 1 × 3⁴ = 81, so P(A) = 81/82.
  2. About 92.3%, because each shot's evidence should be summed rather than multiplied — 4 shots at ratio 3 give combined odds of 3 × 4 = 12, so P(A) = 12/13.
  3. Exactly 50%, since in-context learning performs no gradient-based parameter update at inference time, so the model's posterior belief cannot shift away from the 50-50 prior no matter how many demonstrations are shown.
  4. About 81%, because raising the per-shot likelihood ratio to the fourth power gives 3⁴ = 81, and this number is already the posterior probability once written as a percent.

Answer: A. About 98.8% (posterior odds 81:1) — Bayesian updating multiplies the likelihood ratio across independent shots: odds = 1 × 3⁴ = 81, so P(A) = 81/82.

ExplanationXie et al.'s Bayesian view treats each in-context demonstration as evidence about a hidden "concept" the model is trying to infer purely through its forward pass — no weights change, but its effective belief over concepts still updates via Bayes' rule applied inside the network's computation. With a per-example likelihood ratio of λ = 3 in favour of Concept A and 4 conditionally independent demonstrations, the posterior odds compound multiplicatively, not additively: odds(A:B) = prior odds × λ^k = 1 × 3⁴ = 1 × 81 = 81. Converting odds to a probability: P(A) = 81 / (81 + 1) = 81/82 ≈ 0.9878, i.e., about 98.8%. This exponential concentration is exactly why adding a few well-chosen demonstrations can sharply shift an LLM's behaviour even though its parameters never move: each additional consistent example multiplies — rather than adds to — the odds in favour of the correct task concept. Summing the per-shot ratios instead of multiplying them, treating the raw compounded value 81 as if it were already a percentage, or assuming inference-time prompting cannot move the model's effective belief at all, are the three most common errors when reasoning about this mechanism.

Question 168 · Attention Mechanisms: The Foundation of Transformers · hard

In the Transformer's scaled dot-product attention, Attention(Q,K,V) = softmax(QK^T / √d_k) V, suppose each component of a query vector q ∈ ℝ^64 and a key vector k ∈ ℝ^64 is drawn independently from a distribution with mean 0 and variance 1, and the components of q are independent of the components of k. What is the standard deviation of the raw (unscaled) dot product q·k, and why does this magnitude make dividing by √d_k = 8 necessary before applying softmax?

  1. Since the 64 term-wise products q_i k_i are independent, zero-mean, and unit-variance, Var(q·k) = 64 and the standard deviation is √64 = 8; this large spread pushes softmax logits far apart, causing the output distribution to collapse toward one-hot and its gradients to vanish — dividing by √d_k = 8 restores unit variance and keeps softmax gradients well-scaled.
  2. Variance adds across all 64 dimensions, giving a standard deviation of 64 directly without taking a square root; the role of dividing by √d_k is to shift the scores' mean back to zero so the softmax stays centered, rather than to control their spread.
  3. The dot product's standard deviation is indeed √64 = 8, but the actual purpose of the √d_k divisor is to regularize the attention weights against overfitting, analogous to L2 weight decay on the logits, not to manage softmax saturation.
  4. Because query and key vectors are implicitly unit-normalized, q·k already has standard deviation 1 regardless of d_k; the √d_k divisor exists only to rescale attention outputs to match the magnitude of the value vectors V, not to control the variance of the logits.

Answer: A. Since the 64 term-wise products q_i k_i are independent, zero-mean, and unit-variance, Var(q·k) = 64 and the standard deviation is √64 = 8; this large spread pushes softmax logits far apart, causing the output distribution to collapse toward one-hot and its gradients to vanish — dividing by √d_k = 8 restores unit variance and keeps softmax gradients well-scaled.

ExplanationWrite q·k = Σ_{i=1}^{64} q_i k_i. Each term q_i k_i has mean E[q_i]E[k_i] = 0 by independence of q_i and k_i, and since E[q_i²] = E[k_i²] = 1, Var(q_i k_i) = E[q_i² k_i²] − 0² = E[q_i²]E[k_i²] = 1·1 = 1. The 64 terms are mutually independent (across dimensions), so variances add: Var(q·k) = Σ_{i=1}^{64} Var(q_i k_i) = 64 × 1 = 64, giving standard deviation √64 = 8. A raw score with typical magnitude of several units (versus the ±1 scale of a single term) sits far out on softmax's exponential curve: softmax(x)_j = exp(x_j) / Σ_l exp(x_l) is dominated by whichever logit is largest once logits differ by a few units, so the output collapses toward a one-hot vector and the gradient of softmax with respect to the non-maximal logits shrinks toward zero. This is precisely the vanishing-gradient regime that motivated the √d_k scaling in "Attention Is All You Need." Dividing every score by √d_k = 8 rescales the dot product back to unit variance — the same ±1 scale each individual term already had — so logits stay near zero, where softmax's Jacobian is well-conditioned and gradients propagate normally. The distractors fail for distinct reasons: summing variances does not itself give the standard deviation (variance and standard deviation are conflated when 64 is used directly instead of √64); √d_k scaling is a variance-control mechanism, not an L2-style regularizer, and it has nothing to do with penalizing weight magnitudes; and nothing in the setup normalizes q or k to unit length — assuming i.i.d. unit-variance components across 64 dimensions is in fact incompatible with a unit-norm vector, whose squared length would need to equal exactly 1 rather than have an expected value of 64.

Question 169 · Compositional Learning: Building Complex from Simple · hard

A target function h(x1, x2, ..., x8) of 8 real inputs has compositional structure: it is built as a binary tree of two-input node functions, h(x1,...,x8) = f7( f5(f1(x1,x2), f2(x3,x4)), f6(f3(x5,x6), f4(x7,x8)) ), where every f_i is smooth and depends on exactly two real inputs. Classical approximation theory says a single-hidden-layer ("shallow") network needs O(ε^-d) units to approximate a generic Lipschitz function of d variables to accuracy ε, while any smooth function of exactly 2 variables can be approximated to accuracy ε using O(ε^-2) units. Taking ε = 0.1, and comparing (i) a shallow network that treats h as a generic 8-variable function against (ii) a compositional network built with one small sub-network per node of the tree above, what is the approximate ratio of unit counts (shallow) / (compositional)?

  1. About 1.4 × 10^5, since the shallow count is (0.1)^-8 = 10^8 while the tree has 7 node functions (f1 through f7, since a full binary tree with 8 leaves has exactly 7 internal nodes), each needing (0.1)^-2 = 100 units, giving a compositional total of 700 units.
  2. About 1.0 × 10^6, since moving from a 2-variable to an 8-variable approximation problem costs a factor of ε^-6, and this factor alone fixes the ratio regardless of how many node functions the tree actually contains.
  3. About 4, since the tree halves the number of variables at each of its two internal levels (8 → 4 → 2), so the saving in unit count should scale with the depth of the tree rather than with a power of ε.
  4. About 1, since both architectures ultimately compute a function of the same 8 original inputs, so factoring the computation into smaller pieces cannot change the total number of units the curse of dimensionality demands.

Answer: A. About 1.4 × 10^5, since the shallow count is (0.1)^-8 = 10^8 while the tree has 7 node functions (f1 through f7, since a full binary tree with 8 leaves has exactly 7 internal nodes), each needing (0.1)^-2 = 100 units, giving a compositional total of 700 units.

ExplanationTreating h as a generic function of all 8 variables throws away its structure and forces a shallow network to cover an 8-dimensional domain: N_shallow = ε^-8 = (0.1)^-8 = 10^8 units. The compositional network instead mirrors the tree: leaves x1..x8 feed into f1, f2, f3, f4 (2 inputs each), whose outputs feed into f5, f6 (2 inputs each), whose outputs feed into f7 (2 inputs) — a full binary tree with 8 leaves always has exactly 7 internal nodes (each merge of two children reduces the leaf count by one, and 8 leaves need 7 merges to reach a single root). Every node function has only 2 inputs, so each needs only ε^-2 = (0.1)^-2 = 100 units, giving N_deep = 7 × 100 = 700 units. The ratio is 10^8 / 700 ≈ 142,857 ≈ 1.4 × 10^5. This is the core mechanism behind why deep, hierarchically structured networks beat shallow ones on compositional targets: the exponential curse of dimensionality ε^-d is replaced by a sum of small, fixed-size subproblems whose count grows only linearly with the number of variables (here d − 1 = 7 nodes), turning an exponential requirement into a tractable, near-linear one. Indian students can see the same idea in a UPI fraud-detection pipeline, where a transaction's risk score is built by composing small sub-models — a device-check, a velocity-check, a merchant-category-check — instead of training one giant model directly on every raw feature at once.

Question 170 · AI for Healthcare: Medical Imaging and Drug Discovery · hard

An AI-based chest X-ray screening tool (similar to AI triage systems deployed under India's National TB Elimination Programme) is used to screen for active tuberculosis in a district where the true prevalence of active TB is 2%. The tool has a sensitivity of 95% and a specificity of 90%. If a randomly selected screened individual receives a positive AI result, what is the probability (to one decimal place) that this individual actually has active TB?

  1. About 16.2%, since only a small fraction of positives are true TB cases once the 2% base rate is combined with the test's false-positive rate under Bayes' theorem.
  2. About 95%, because the sensitivity of the tool already tells us how likely a positive result is to indicate genuine TB.
  3. About 90%, because the specificity of the tool determines how trustworthy a positive screening result is.
  4. About 1.9%, since only 1.9 individuals out of every 100 screened will both test positive and actually have TB.

Answer: A. About 16.2%, since only a small fraction of positives are true TB cases once the 2% base rate is combined with the test's false-positive rate under Bayes' theorem.

ExplanationThis is a direct application of Bayes' theorem to a medical AI screening tool, and it shows why even a highly accurate model can have a low positive predictive value (PPV) when disease prevalence is low. Let TB denote "has active tuberculosis" and + denote "AI flags the X-ray as positive." We are given P(TB) = 0.02 (prevalence), sensitivity P(+|TB) = 0.95, and specificity P(-|no TB) = 0.90, so the false-positive rate is P(+|no TB) = 1 - 0.90 = 0.10. By the law of total probability, P(+) = P(+|TB)·P(TB) + P(+|no TB)·P(no TB) = (0.95)(0.02) + (0.10)(0.98) = 0.019 + 0.098 = 0.117. Applying Bayes' theorem, P(TB|+) = P(+|TB)·P(TB) / P(+) = 0.019 / 0.117 ≈ 0.1624, i.e., about 16.2%. So even though the AI tool correctly flags 95% of true TB cases and correctly clears 90% of healthy individuals, only about 16.2% of all positive flags in this 2%-prevalence population actually correspond to real TB, because the healthy majority (98% of the population) generates almost five times as many false positives (9.8 per 100 screened) as the diseased minority generates true positives (1.9 per 100 screened). This is exactly why programmes using AI chest X-ray triage tools (such as qXR under India's National TB Elimination Programme) treat an AI-positive result only as a pre-screening flag, requiring confirmation with a molecular test like CBNAAT/GeneXpert before treatment begins. Sensitivity and specificity describe the test's behaviour conditioned on true disease status, not the reverse; how much to trust a single positive result depends critically on the base rate (prevalence), a distinction known as the base-rate fallacy when it is ignored.

Question 171 · AI for Agriculture: Crop Prediction and Pest Detection · hard

An ICAR-affiliated agri-tech startup trains a CNN to flag leaf-miner infestation in groundnut crops from smartphone photos submitted by farmers in Junagadh, Gujarat. The model is tested on 1000 field-collected leaf images: 100 are actually infested and 900 are healthy. Of the 100 truly infested leaves, the model correctly flags 80 as infested (missing the other 20). Of the 900 healthy leaves, it wrongly flags 45 as infested. Based on this confusion matrix, what is the model's F1-score for the "infested" class, computed correctly from precision and recall?

  1. F1-score ≈ 0.71 — the harmonic mean of precision (80/125 = 0.64) and recall (80/100 = 0.80) correctly balances both the 45 healthy leaves wrongly flagged and the 20 infested leaves missed.
  2. F1-score ≈ 0.94, since overall accuracy captures how well the model classifies both infested and healthy leaves across all 1000 samples.
  3. F1-score ≈ 0.72, obtained by averaging precision and recall arithmetically, since both metrics contribute equally to a balanced classification score.
  4. F1-score ≈ 0.80, because recall is the only metric that matters here — missing an infested plant costs far more than spraying a healthy one unnecessarily.

Answer: A. F1-score ≈ 0.71 — the harmonic mean of precision (80/125 = 0.64) and recall (80/100 = 0.80) correctly balances both the 45 healthy leaves wrongly flagged and the 20 infested leaves missed.

ExplanationBuild the confusion matrix for the "infested" class first: TP = 80 (infested, correctly flagged), FN = 20 (infested, missed), FP = 45 (healthy, wrongly flagged), TN = 855 (healthy, correctly cleared) — these four sum to 1000, matching the field trial. Precision asks: of the leaves the model flagged as infested, how many actually were? Precision = TP/(TP+FP) = 80/(80+45) = 80/125 = 0.64. Recall asks: of the leaves that were actually infested, how many did the model catch? Recall = TP/(TP+FN) = 80/(80+20) = 80/100 = 0.80. The F1-score is defined as the harmonic mean of precision and recall, not their arithmetic mean: F1 = 2·P·R/(P+R) = 2(0.64)(0.80)/(0.64+0.80) = 1.024/1.44 ≈ 0.711, i.e., F1 ≈ 0.71. The harmonic mean is used deliberately because it penalizes imbalance between precision and recall more heavily than a simple average — a model can't hide a weak precision behind a strong recall (or vice versa) the way an arithmetic mean of 0.64 and 0.80 (= 0.72) would let it. That is why averaging P and R directly gives the wrong figure. Accuracy — (TP+TN)/total = (80+855)/1000 = 0.935 — is misleading here precisely because of class imbalance: 900 of the 1000 leaves are healthy, so a model could score ~90% accuracy by predicting "healthy" almost every time while still missing most real infestations. This is exactly why F1, not accuracy, is the standard reporting metric for imbalanced detection tasks like pest identification. Recall alone (0.80) also isn't the F1-score. It's true that in pest management a false negative (an infestation left untreated) is often costlier than a false positive (a healthy leaf sprayed unnecessarily) — but that cost asymmetry is a reason to weight recall more heavily using a metric like F-beta with beta > 1, not a reason to call recall itself the F1-score, which by definition must incorporate precision too.

Question 172 · Constitutional AI: Aligning Models with Principles · hard

A team building an AI customer-support assistant for a UPI payments app is fine-tuning it with Anthropic's Constitutional AI method. In the RL phase, a separate AI "judge" model compares two candidate replies to a user asking how to reverse a fraudulent transaction, scoring each against the written constitution. Reply A (which correctly directs the user to file a dispute through the bank's grievance portal without collecting any sensitive details) receives a harmlessness score of r_A = 2.3, and Reply B (which asks the user to share their UPI PIN "for verification") receives r_B = 0.7. The preference model converts these scores into a choice probability using the same Bradley–Terry logistic form as standard RLHF, P(A ≻ B) = σ(r_A − r_B). Given this setup and the actual division of labor between human and AI feedback in the original Constitutional AI paper, which statement is correct?

  1. Since AI feedback in Constitutional AI's RL phase replaces human labels only for harmlessness comparisons (helpfulness preferences stay human-generated), and σ(r_A − r_B) = σ(1.6), the preference model assigns P(A ≻ B) ≈ 0.83.
  2. Treating the scores as a simple ratio rather than a logistic difference, r_A/(r_A + r_B) = 2.3/3.0 ≈ 0.77 is mistaken for P(A ≻ B); AI feedback replaces human labels only for harmlessness, with helpfulness remaining human-generated.
  3. Constitutional AI's RL phase uses AI-generated labels to replace human feedback across both helpfulness and harmlessness comparisons, so with σ(r_A − r_B) = σ(1.6), the preference model assigns P(A ≻ B) ≈ 0.83.
  4. Reversing the order of subtraction, σ(r_B − r_A) = σ(−1.6) ≈ 0.17 is mistaken for P(A ≻ B); AI feedback replaces human labels only for harmlessness, with helpfulness remaining human-generated.

Answer: A. Since AI feedback in Constitutional AI's RL phase replaces human labels only for harmlessness comparisons (helpfulness preferences stay human-generated), and σ(r_A − r_B) = σ(1.6), the preference model assigns P(A ≻ B) ≈ 0.83.

ExplanationThe score gap is r_A − r_B = 2.3 − 0.7 = 1.6, so P(A ≻ B) = σ(1.6) = 1/(1 + e^(−1.6)). Since e^1.6 ≈ 4.953, e^(−1.6) ≈ 0.202, giving P(A ≻ B) ≈ 1/1.202 ≈ 0.83 — the preference model favors the safe, dispute-portal reply over the PIN-harvesting reply roughly 83% of the time it samples this pair. This matches how Constitutional AI's RL phase actually works: the harmlessness comparisons used to train the preference model are AI-generated — a separate model applies the written constitution via chain-of-thought critique to judge which reply is safer — while the helpfulness comparisons feeding the same preference model still come from human-labeled data collected the standard RLHF way. These two feedback streams are combined into one mixed preference model, which then supplies the reward signal for PPO. So Constitutional AI does not remove human labelers from the loop; it narrows their role by handing specifically the harmlessness judgments to an AI critic bound by explicit written principles, which is what makes the "AI Feedback" in RLAIF distinct from ordinary RLHF.

Question 173 · Direct Preference Optimization: Learning from Preferences · hard

An Indian ed-tech startup is fine-tuning a doubt-solving chatbot with Direct Preference Optimization. For one prompt x, human evaluators mark response y_w as preferred over response y_l. The current policy π_θ and the frozen reference policy π_ref assign these probabilities to the two full responses: π_θ(y_w|x) = 0.4, π_ref(y_w|x) = 0.1, π_θ(y_l|x) = 0.05, π_ref(y_l|x) = 0.2. Using the DPO loss L = −log σ(β[log(π_θ(y_w|x)/π_ref(y_w|x)) − log(π_θ(y_l|x)/π_ref(y_l|x))]) with temperature β = 0.5 and natural logarithms throughout, what is the loss for this single preference pair?

  1. ≈1.609 nats, from swapping the chosen and rejected terms so the margin becomes β[(log πθ(y_l) − log πref(y_l)) − (log πθ(y_w) − log πref(y_w))] = −ln4, so the loss works out to −ln σ(−ln4) = −ln(0.2).
  2. ≈0.303 nats, from treating the margin as β[log πθ(y_w) − log πθ(y_l)] = 0.5 × ln8 ≈ 1.040 while leaving π_ref out of the calculation entirely.
  3. ≈0.223 nats, from the margin β[(log πθ(y_w) − log πref(y_w)) − (log πθ(y_l) − log πref(y_l))] = 0.5 × ln16 = ln4, so the loss is −ln σ(ln4) = −ln(0.8).
  4. ≈0.061 nats, from the correct log-ratio margin ln16 ≈ 2.773 but without ever scaling it by β, so the loss is −ln σ(2.773).

Answer: C. ≈0.223 nats, from the margin β[(log πθ(y_w) − log πref(y_w)) − (log πθ(y_l) − log πref(y_l))] = 0.5 × ln16 = ln4, so the loss is −ln σ(ln4) = −ln(0.8).

ExplanationDPO turns pairwise human preferences directly into a classification loss on the policy itself, without ever training a separate reward model. Starting from the KL-regularized RL objective max_π E[r(x,y)] − β·KL(π‖π_ref), the closed-form optimal policy implies an implicit reward r(x,y) = β log(π_θ(y|x)/π_ref(y|x)) + β log Z(x), where Z(x) is a partition function depending only on the prompt x. Since the Bradley-Terry preference model only ever needs the difference r(x,y_w) − r(x,y_l), the Z(x) terms cancel, leaving L = −log σ(β[log(π_θ(y_w|x)/π_ref(y_w|x)) − log(π_θ(y_l|x)/π_ref(y_l|x))]). Plugging in the numbers: the chosen response's log-ratio is log(0.4/0.1) = log 4 ≈ 1.3863, and the rejected response's log-ratio is log(0.05/0.2) = log 0.25 ≈ −1.3863. The margin is β times their difference: 0.5 × (1.3863 − (−1.3863)) = 0.5 × 2.7726 = 1.3863 = log 4. Passing this through the logistic function gives σ(log 4) = 4/(1+4) = 0.8, so the loss is −log(0.8) ≈ 0.223 nats. Notice that although π_θ assigns y_l a fairly low absolute probability (0.05), what actually drives the loss is how much that probability moved relative to π_ref — it dropped by a factor of 4 from π_ref's 0.2, exactly mirroring the chosen response's 4x rise from 0.1 to 0.4. That relative, reference-anchored comparison is the whole point of the KL term, and it's why DPO's gradient cannot be computed from π_θ's probabilities alone. The 0.303-nats figure comes from treating the margin as β times the raw policy log-ratio only, 0.5 × (log 0.4 − log 0.05) = 0.5 × log 8 ≈ 1.040, which silently drops π_ref out of the computation and mistakes DPO for a plain likelihood-ranking loss with no anchor to the reference policy. The 0.061-nats figure uses the correct log-ratio margin, log 16 ≈ 2.773, but forgets to scale it by β, which changes how sharply the sigmoid saturates and understates the loss. The 1.609-nats figure comes from swapping which response is treated as preferred — computing β[(log-ratio of y_l) − (log-ratio of y_w)] = −log 4 instead — which flips the sign of the margin, gives σ(−log 4) = 0.2, and is exactly the error that results from mislabelling which response the annotators actually preferred.

Question 174 · Jailbreak Detection and Defense Mechanisms · hard

An Indian ed-tech platform runs its AICI tutoring model behind a perplexity-based jailbreak filter, following the defense strategy used against GCG-style adversarial-suffix attacks (optimized token strings appended to a prompt to force harmful completions). A student's otherwise benign homework question arrives with a suspicious 6-token string appended at the end. Scoring this string against the defender's own base language model produces the following per-token negative log-likelihoods, in nats (natural-log units): 1.2, 0.9, 5.8, 6.1, 5.5, 6.3. The filter uses the standard definition PPL(x) = exp((1/N) Σ −ln P(xᵢ)) computed over exactly these N = 6 tokens, and flags the input as an adversarial suffix whenever PPL(x) exceeds the threshold τ = 50. Does the filter flag this suffix, and what perplexity value drives that decision?

  1. Averaging the six negative log-likelihoods gives 25.8/6 = 4.3 nats, so PPL = e^4.3 ≈ 73.7, which exceeds τ = 50 and correctly triggers the adversarial-suffix flag.
  2. Perplexity is defined with base 2, so PPL = 2^4.3 ≈ 19.7, which stays below τ = 50 and the filter fails to flag this clearly anomalous suffix.
  3. Since perplexity exponentiates the total negative log-likelihood without dividing by N, PPL = e^25.8, an astronomically large value that trivially exceeds τ = 50 regardless of sequence length.
  4. Only the four highest-loss suffix tokens should count toward perplexity, giving PPL = e^(23.7/4) ≈ 374.3, so the benign prefix tokens must also be re-scored and flagged as adversarial.

Answer: A. Averaging the six negative log-likelihoods gives 25.8/6 = 4.3 nats, so PPL = e^4.3 ≈ 73.7, which exceeds τ = 50 and correctly triggers the adversarial-suffix flag.

ExplanationPerplexity filtering exploits a structural property of GCG-style adversarial suffixes: because these strings are found by gradient-guided search over token space to maximize the probability of a harmful target completion, they are optimized for attack success, not for fluency — so a well-trained language model assigns them unusually low probability (high negative log-likelihood) per token, unlike natural language. Apply the given definition exactly as stated, PPL(x) = exp((1/N) Σ −ln P(xᵢ)), with N = 6. Sum the six negative log-likelihoods: 1.2 + 0.9 + 5.8 + 6.1 + 5.5 + 6.3 = 25.8 nats. Divide by N to get the mean per-token loss: 25.8 / 6 = 4.3 nats. Exponentiate with base e (since the log-likelihoods were computed in natural-log units, "nats," the inverse of ln is exp, not 2^x): PPL = e^4.3. Using e^4 ≈ 54.60 and e^0.3 ≈ 1.350, PPL ≈ 54.60 × 1.350 ≈ 73.7. Since 73.7 > 50, the filter correctly flags the input as a likely adversarial suffix. The 2^4.3 ≈ 19.7 route mixes up units: base-2 perplexity is only equivalent to this base-e definition if the log-likelihoods were originally measured in bits (log base 2), not nats. Applying 2^x to a natural-log-derived exponent silently shrinks the exponent's effective base and produces a perplexity low enough to slip under the threshold — precisely the failure mode a defender must avoid when wiring a perplexity filter to a model's actual log-probability output format. The e^25.8 route skips the (1/N) normalization entirely. Raw summed negative log-likelihood grows with sequence length regardless of how anomalous each individual token is, so an un-normalized "perplexity" would flag long benign passages just as readily as short adversarial ones — defeating the purpose of a per-token fluency measure. The four-token route silently redefines which tokens count as "the suffix," computing e^(23.7/4) ≈ 374.3 over a different, smaller token set than the N = 6 the problem specifies, and then draws a non-sequitur conclusion: a high perplexity score over the suffix window says nothing about the separately-scored prefix, since perplexity is computed independently over whatever window is chosen, not propagated backward onto unrelated tokens.

Question 175 · The Alignment Tax: Trading Performance for Safety · hard

A team building a citizen-helpline chatbot for an Indian state government fine-tunes a language model using RLHF. Their model gives capability retention C(x) = 100 − x² (percentage of baseline task accuracy retained, for fine-tuning intensity 0 ≤ x ≤ 10) and safety compliance S(x) = 10x. The deployment policy sets the intensity x* that maximizes the combined utility U(x) = S(x) + C(x). At this x*, what is the alignment tax — the capability lost relative to the unaligned baseline C(0) = 100?

  1. 50 percentage points, since the safety compliance score at x* equals the capability sacrificed to reach it.
  2. 100 percentage points, since the utility-maximizing intensity sits at the domain's upper bound, x = 10.
  3. 25 percentage points, since the utility-maximizing intensity is x* = 5, where capability falls to 75.
  4. 0 percentage points, since capability alone is maximized at x = 0, so no alignment fine-tuning occurs there.

Answer: C. 25 percentage points, since the utility-maximizing intensity is x* = 5, where capability falls to 75.

ExplanationThe alignment tax is the drop in capability caused by safety fine-tuning: Tax(x) = C(0) − C(x). To find the intensity the deployment policy actually settles on, maximize the combined utility U(x) = S(x) + C(x) = 10x + (100 − x²) = 100 + 10x − x². This is a downward-opening parabola in x, so differentiate and set the derivative to zero: U'(x) = 10 − 2x = 0, giving x* = 5. Since U''(x) = −2 < 0, this is indeed a maximum, and x* = 5 lies inside the allowed range [0, 10], so the boundary is irrelevant here. At this intensity, capability retention is C(5) = 100 − 5² = 100 − 25 = 75, so the alignment tax is Tax(5) = C(0) − C(5) = 100 − 75 = 25 percentage points. The model trades 25 points of baseline task accuracy for the safety level S(5) = 10(5) = 50 that the utility-maximizing policy settles on. Treating the safety score itself as the tax conflates "safety gained" with "capability lost" — they are different axes of the same trade-off. Assuming the policy pushes intensity to the domain's upper bound ignores that U(x) is concave and peaks strictly inside the interval, not at an edge. And assuming the policy maximizes raw capability alone confuses the unconstrained optimum of C(x) with the optimum of the joint objective U(x) that the policy is actually built to maximize — capability-only optimization is exactly the pre-alignment baseline the tax is measured against, not the deployed operating point.

Question 176 · Multimodal Models: Combining Vision and Language · hard

A CLIP-style dual-encoder model is trained on a batch of 3 image-caption pairs. Both encoders map their inputs to L2-normalized embeddings, so the dot product between an image embedding and a text embedding equals their cosine similarity, lying in [-1, 1]. For one training batch, the image encoder and text encoder produce the following cosine-similarity matrix S, where S[I_i][T_j] is the similarity between image I_i and caption T_j (the true pairing is always on the diagonal, so (I1,T1), (I2,T2), (I3,T3) are the matched pairs): | S | T1 | T2 | T3 | |-----|-----|-----|-----| | I1 | 0.9 | 0.2 | 0.1 | | I2 | 0.3 | 0.8 | 0.4 | | I3 | 0.1 | 0.3 | 0.7 | CLIP's image-to-text contrastive loss treats each image as a query against every caption in the batch: it divides the similarity row by a learned temperature τ, applies softmax across that row to get a probability distribution over the batch's captions, and takes the negative log-probability assigned to the true caption. Using τ = 0.1, what is the image-to-text loss contribution −log p(T1 | I1) for image I1?

  1. ≈0.666 nats, since softmax is applied directly to the raw cosine similarities [0.9, 0.2, 0.1] and the temperature only rescales the loss after softmax is computed
  2. ≈1.05 nats, since dividing by a temperature τ = 0.1 means multiplying the raw similarities by 0.1 before the softmax, giving logits [0.09, 0.02, 0.01]
  3. ≈0.0012 nats, since dividing the similarity row by τ = 0.1 turns it into logits [9, 2, 1], and softmax cross-entropy on these gives −ln(0.9988) for the true caption T1
  4. 0 nats, because T1 already has the highest cosine similarity with I1 among the three captions, so the model's top-1 prediction is already correct

Answer: C. ≈0.0012 nats, since dividing the similarity row by τ = 0.1 turns it into logits [9, 2, 1], and softmax cross-entropy on these gives −ln(0.9988) for the true caption T1

ExplanationDividing similarities by τ before the softmax is exactly what makes CLIP's temperature-scaled contrastive loss (InfoNCE) work: a small τ sharpens the distribution over the batch, turning even a modest similarity gap into a highly confident prediction. Start from the I1 row of S: [0.9, 0.2, 0.1]. Dividing each entry by τ = 0.1 (equivalent to multiplying by 10) gives logits [9, 2, 1]. Applying softmax: exp(9) = 8103.08, exp(2) = 7.389, exp(1) = 2.718, sum = 8113.19 p(T1 | I1) = 8103.08 / 8113.19 = 0.9988 The loss contribution is −ln(0.9988) ≈ 0.0012 nats — a very small loss, because the temperature-sharpened distribution puts almost all its mass on the correct caption T1. The 0.666-nats distractor skips the division by τ entirely and runs softmax on the raw similarities [0.9, 0.2, 0.1]; that ignores where τ actually enters CLIP's formula (inside the softmax, as sim/τ), not as a post-hoc rescaling of the loss. The 1.05-nats distractor inverts the temperature operation: multiplying the similarities by τ = 0.1 instead of dividing by it produces logits [0.09, 0.02, 0.01], which flattens the distribution toward uniform (roughly equal probabilities for all three captions) instead of sharpening it — the opposite of what a small τ is designed to do, and it actually increases the loss above what you'd get with no temperature at all. The 0-nats distractor confuses top-1 accuracy with cross-entropy loss. T1 does have the highest similarity to I1, so the model's ranking is correct, but the loss is only exactly zero if the assigned probability is exactly 1. Since softmax always spreads some probability mass to T2 and T3, the loss stays strictly positive — small, but not zero — which is precisely why gradient signal keeps flowing even once the model is "getting it right."

Question 177 · Robotics Foundation Models: Learning Control Policies · hard

An Indian robotics startup trains a warehouse pick-and-place foundation model policy using pure behavior cloning: the policy learns entirely by imitating expert tele-operators on a fixed set of recorded demonstrations, with no online correction. On the states seen during training, the learned policy deviates from the expert's action with probability ε = 0.02 at each control step. A pick-and-place episode runs for T = 50 steps. Under the classical covariate-shift (compounding-error) analysis of behavior cloning, assume the very first deviation pushes the robot into states outside its training distribution, after which it was never taught to recover, so every remaining step of that episode counts as a failure (cost 1). Using E[C] = ε·T(T+1)/2 to bound the expected number of failed steps in the worst case, what is the expected number of failed steps in this 50-step episode, and how does it compare with the naive, non-compounding estimate of εT?

  1. About 25.5 failed steps (ε·T(T+1)/2 = 0.02 × 1275) — roughly half the episode, about 25 times worse than the naive εT ≈ 1, because a single early deviation carries a full-episode-length cost that a linear estimate ignores.
  2. About 1 failed step (simply εT = 0.02 × 50 = 1), since each control step's error is an independent, identically distributed event whose costs just add up regardless of the states visited earlier in the episode.
  3. About 50 failed steps (using the bound literally as εT² = 0.02 × 2500 = 50, without the factor-of-two correction that comes from summing the arithmetic series T + (T−1) + … + 1), overstating the true worst-case expectation by roughly 2×.
  4. About 7.1 failed steps (T√ε = 50 × √0.02 ≈ 7.07), treating the compounding effect as scaling with the square root of the per-step error rate rather than with the arithmetic sum of the remaining steps after the first mistake.

Answer: A. About 25.5 failed steps (ε·T(T+1)/2 = 0.02 × 1275) — roughly half the episode, about 25 times worse than the naive εT ≈ 1, because a single early deviation carries a full-episode-length cost that a linear estimate ignores.

ExplanationThis is the classical compounding-error (covariate-shift) bound for behavior cloning, due to Ross and Bagnell. Let the first mistake occur at step t. Because ε is small, the probability of matching the expert exactly through steps 1 to t−1 is approximately 1, so the probability that the first mistake happens exactly at step t is approximately ε for every t = 1, …, T. Once that first mistake occurs, the robot enters a state outside its training distribution — one the expert demonstrations never visited — so by the worst-case assumption every one of the remaining T − t + 1 steps (including step t itself) counts as a failure. The expected number of failed steps is therefore E[C] = Σ_{t=1}^{T} ε(T − t + 1) = ε Σ_{k=1}^{T} k = ε · T(T+1)/2. Substituting ε = 0.02 and T = 50: E[C] = 0.02 × (50 × 51)/2 = 0.02 × 1275 = 25.5. So on average about 25.5 of the 50 steps — roughly half the episode — end up as failures, even though the policy is wrong only 2% of the time on the states it saw during training. Compare this with the naive, non-compounding estimate εT = 0.02 × 50 = 1, which just adds up 50 independent 2%-probability failures and predicts about one bad step. The true worst-case expectation is about 25 times larger than that naive linear estimate, because the quadratic T(T+1)/2 term captures something the naive sum ignores: an early mistake doesn't cost one step, it costs every step that follows, since the robot was never shown how to recover once it drifts off the expert's state distribution. This is precisely why pure offline behavior cloning is a fragile way to train a robot foundation-model policy despite low training loss, and why techniques like DAgger (iteratively querying the expert for corrective labels on states the learner itself visits) or recovery-aware architectures (e.g., diffusion-policy action chunking, which resamples a whole action sequence instead of committing to one brittle action) are used in practice — DAgger provably brings the bound back down from O(εT²) to O(εT).

Question 178 · Sim-to-Real Transfer: From Simulation to Physical Robots · hard

A legged-robot control policy is trained entirely in simulation, where each ankle actuator is modeled as an ideal torque source that reaches its commanded value instantaneously. On the physical robot, the actuator instead follows first-order lag dynamics τ(t) = τ_cmd · (1 − e^(−t/T)), with time constant T = 50 ms measured by system identification on the real hardware before deployment. The policy's control loop issues a new torque command every 20 ms (a 50 Hz loop), and each command is chosen assuming the previous one already reached its target. By the instant the next command overwrites it, what fraction of the commanded torque has the real actuator actually reached, and why does this expose a fundamental limitation of training with an idealized simulator?

  1. About 33%, since τ(t)/τ_cmd = 1 − e^(−0.4) ≈ 0.33 — the servo is still far from its target when the next command overwrites it, so the policy is chronically chasing a moving reference.
  2. About 40%, since the torque is assumed to rise linearly toward the target at rate 1/T, giving τ(t)/τ_cmd = t/T = 20/50 = 0.4 over the 20 ms window.
  3. About 67%, since e^(−0.4) ≈ 0.67 is taken directly as the fraction of commanded torque already delivered when the next command arrives.
  4. About 92%, since τ(t)/τ_cmd = 1 − e^(−T/t) = 1 − e^(−2.5) ≈ 0.92, using the lag time constant over the control period instead of the period over the time constant.

Answer: A. About 33%, since τ(t)/τ_cmd = 1 − e^(−0.4) ≈ 0.33 — the servo is still far from its target when the next command overwrites it, so the policy is chronically chasing a moving reference.

ExplanationThe real actuator obeys exponential first-order dynamics, not the instantaneous response the simulator assumes, so the fraction of commanded torque reached at time t is τ(t)/τ_cmd = 1 − e^(−t/T). Substituting the control period t = 20 ms and the identified hardware time constant T = 50 ms gives t/T = 20/50 = 0.4, so τ(t)/τ_cmd = 1 − e^(−0.4). Since e^(−0.4) ≈ 0.6703, the achieved fraction is 1 − 0.6703 ≈ 0.3297, i.e., about 33%. So every 20 ms the real servo closes only about a third of the gap to its target before a fresh command supersedes it entirely — the actuator is perpetually chasing a moving reference it can never catch, even though the simulator's torque source hit every target exactly and instantly. This is the classic unmodeled-actuator-dynamics source of the reality gap: a policy that looks stable and precise in simulation can become jittery, underpowered, or unstable on hardware purely because the simulator's assumption of instantaneous actuation was never true. The fix is not more training in the flawed simulator but closing the model mismatch itself — via system identification of T followed by adding matching first-order lag to the simulated actuators (or randomizing T across a realistic range during training), or by slowing the control loop to match the hardware's actual bandwidth. The 40% distractor comes from wrongly treating the torque rise as linear (t/T) rather than exponential — first-order lag systems approach their asymptote fastest at first and slower over time, so linear extrapolation overstates early progress incorrectly here by only a little but reflects a fundamentally wrong model. The 67% distractor comes from computing e^(−0.4) correctly but forgetting to subtract it from 1, reporting the fraction still remaining as if it were the fraction achieved. The 92% distractor comes from inverting the exponent's ratio (T/t instead of t/T), which corresponds to asking how far the system would rise if the roles of the control period and the time constant were swapped.

Question 179 · Swarm Intelligence: Collective Behavior Systems · hard

A Bengaluru logistics startup routes its delivery bikes using an Ant Colony Optimization (ACO) algorithm: each bike behaves like an "ant," depositing a pheromone-like signal on the road segments it travels, and this signal evaporates over time so that inefficient routes are naturally forgotten while efficient ones get reinforced. For the road segment Hub A → Hub B, the current pheromone level is τ = 2.0, the evaporation rate is ρ = 0.4, and the pheromone deposit constant is Q = 100. In this round, exactly two bikes traverse segment A→B while completing their full delivery tours: Bike 1's total tour length is 50 km and Bike 2's total tour length is 25 km. Applying the standard ACO update rule τ(t+1) = (1−ρ)·τ(t) + Σₖ (Q/Lₖ), summed over every ant k that used the edge, what is the updated pheromone level on segment A→B after this round?

  1. τ(t+1) = 7.2, because evaporation is applied to the existing pheromone level first — giving 0.6 × 2.0 = 1.2 — and then the two ants' individual deposits, Q/50 = 2 and Q/25 = 4, are summed to 6 and added on top.
  2. τ(t+1) = 8.0, because the two ants' deposits (Q/50 = 2 and Q/25 = 4) are simply added straight to the original pheromone level of 2.0, with no evaporation applied at all this round.
  3. τ(t+1) = 4.8, because the two ants' deposits are first added to the original pheromone level (2.0 + 2 + 4 = 8.0), and evaporation is then applied to that combined total, giving 0.6 × 8.0 = 4.8.
  4. τ(t+1) = 4.2, because the two ants' deposits, Q/50 = 2 and Q/25 = 4, are averaged to 3 rather than summed, and that average is added to the evaporated base of 1.2.

Answer: A. τ(t+1) = 7.2, because evaporation is applied to the existing pheromone level first — giving 0.6 × 2.0 = 1.2 — and then the two ants' individual deposits, Q/50 = 2 and Q/25 = 4, are summed to 6 and added on top.

ExplanationThe ACO pheromone-update rule has two components that must be applied in a fixed order, and the order is the entire point of the exercise: evaporation acts on the pheromone trail that already exists, while deposits from the current round's ants are layered on afterward, independently of each other. Step 1 — Evaporation: the existing trail decays by factor (1−ρ) regardless of what happens this round. With ρ = 0.4 and τ(t) = 2.0, this gives (1 − 0.4) × 2.0 = 0.6 × 2.0 = 1.2. Step 2 — Deposits: every ant that used edge A→B this round contributes Q/Lₖ, where a shorter tour length Lₖ produces a larger deposit — this is the mechanism by which ACO reinforces good (short) routes faster than bad ones. Bike 1 (50 km) deposits 100/50 = 2. Bike 2 (25 km) deposits 100/25 = 4. Step 3 — Sum the deposits: because each ant's pheromone contribution is independent and additive, the two deposits stack rather than average: 2 + 4 = 6. Step 4 — Combine: the evaporated base and the summed deposits add together: 1.2 + 6 = 7.2. So τ(t+1) = 7.2 is the only value consistent with the standard update rule. Skipping evaporation entirely gives 8.0, evaporating the combined total instead of just the pre-existing trail gives 4.8, and averaging instead of summing the ants' deposits gives 4.2 — each of these corresponds to a genuine, common implementation mistake, but none matches the rule as stated.

Question 180 · Genetic Programming: Evolving Computer Programs · hard

In a Genetic Programming run tasked with evolving an arithmetic expression tree to fit the target function y = 2x + 1 exactly at the test points x = 1, 2, 3, 4, two individuals in the population both achieve zero sum-of-squared error (SSE): Individual A = (+ (* 2 x) 1), containing 5 total nodes, and Individual B = (+ (+ x x) (+ 1 (- x x))), containing 9 total nodes. To control code bloat, the run applies parsimony-pressure adjusted fitness = SSE + 0.1 × (total node count), with the lower adjusted fitness preferred in tournament selection. Which individual is selected, and what are the two adjusted fitness values?

  1. Individual A is selected, with adjusted fitness 0.5 for A and 0.9 for B, since parsimony pressure adds a size-proportional penalty to the tied SSE of 0.
  2. Individual B is selected, with adjusted fitness 0.5 for A and 0.9 for B, because tournament selection favours whichever combined score is numerically larger.
  3. Individual A wins by adjusted fitness 0.2 versus 0.4, counting only the operator nodes (+, *, -) and excluding terminal nodes such as x and the constants.
  4. Both individuals tie at an adjusted fitness of 0, because achieving a perfect fit exempts a program from the parsimony penalty term entirely.

Answer: A. Individual A is selected, with adjusted fitness 0.5 for A and 0.9 for B, since parsimony pressure adds a size-proportional penalty to the tied SSE of 0.

ExplanationBoth expression trees compute exactly y = 2x + 1 at every sampled point (x = 1,2,3,4 give y = 3,5,7,9): tree A directly encodes 2x + 1, while tree B reaches the same function through the redundant identities x + x = 2x and 1 + (x − x) = 1, so both have raw SSE = 0 and are indistinguishable by accuracy alone. Node counts differ sharply: A = (+ (* 2 x) 1) has 5 nodes in total (2 function nodes + and *, plus 3 terminals 2, x, 1); B = (+ (+ x x) (+ 1 (- x x))) has 9 nodes in total (4 function nodes +, +, +, − plus 5 terminals x, x, 1, x, x). Applying the parsimony-pressure formula, adjusted fitness = SSE + 0.1 × nodes, gives A = 0 + 0.1(5) = 0.5 and B = 0 + 0.1(9) = 0.9. Because the tournament here minimizes adjusted fitness, the smaller score wins, so Individual A is selected over the functionally identical but bloated Individual B. This is exactly what parsimony pressure is designed to do in Genetic Programming: once accuracy is tied, it steers selection toward the more compact program and discourages the introns and redundant subtrees that drive code bloat across generations.
← Set 8Set 10 →