MauryaHub PYQ Practice

Mathematical Foundations of Generative AI · End Term · Jan 2026 · AN

Mathematical Foundations of Generative AI · End Term · Jan 2026 AN

← Course papers · Start practice / exam

Questions and published explanations below are available without starting a test. Some questions may not have a published solution yet.

21 / 22 published solutions

Question 2 MCQ · 2.0 marks

Consider two discrete probability distributions
Source diagram or notation
and
Source diagram or notation
, defined over a sample space
Source diagram or notation
. The probability mass functions are given as follows:
Source diagram or notation
Compute
Source diagram or notation
. Use
Source diagram or notation
for the calculation.
6406536924646.
1
6406536924647.
0
6406536924648.Source diagram or notation
6406536924649.Source diagram or notation

Published solution

**1. State discrete KL:** \(D_{KL}(p\|q)=\sum_{x:p(x)>0}p(x)\log_2[p(x)/q(x)]\). **2. Check support:** At x1, p(x1)=0.5 but q(x1)=0. A distribution q assigns no probability to an event that p says can occur. **3. Apply the extended-value definition:** That term is \(0.5\log_2(0.5/0)=+\infty\). The shared x3 term is zero, but cannot remove the infinite term. Therefore KL is positive infinity, regardless of log base. **Answer: C.** A: **Incorrect:** A finite value misses the support mismatch. B: **Incorrect:** Zero would require identical distributions on their mass. C: **Correct:** Positive p mass at a zero-q point makes this KL infinite. D: **Incorrect:** KL is nonnegative and cannot be -1.

Report a correction for Q2

Question 3 MSQ · 3.0 marks

Which among the following statements are correct?
6406536924650.
A standard GAN cannot reconstruct a specific input sample because it does not learn an explicit encoder mapping inputs to the latent space.
6406536924651.
The blurriness in VAE-generated samples is primarily due to stochastic sampling in the latent space.
6406536924652.
GANs can generate realistic samples despite not learning an encoder, as they sample from a structured latent distribution.
6406536924653.
The regularization term in VAEs improves the sharpness of generated samples by enforcing consistency in reconstructions.

Published solution

**1. Compare mappings:** A standard GAN trains a generator from a latent prior to data, but no explicit inverse encoder. It can therefore generate samples without providing a direct input-to-code reconstruction operation. **2. Explain image quality:** Adversarial training can favor realistic generated samples. VAE blur is more closely associated with likelihood/reconstruction averaging, decoder limitations and the modeling tradeoff than with stochastic latent sampling alone. **3. Interpret reconstruction carefully:** A’s intended meaning is that a basic GAN does not supply direct reconstruction through a learned encoder. A particular input may still be approximately reconstructed through a separate GAN-inversion optimization; absence of an encoder is not a mathematical impossibility of every reconstruction. **Answer: A, C — Selected: A standard GAN cannot reconstruct a specific input sample because it does not learn an explicit encoder mapping inputs to the latent space.; GANs can generate realistic samples despite not learning an encoder, as they sample from a structured latent distribution.** A: **Correct:** The basic GAN has no explicit inference encoder; this concerns direct reconstruction, not the impossibility of later optimization-based inversion. B: **Incorrect:** Stochastic sampling alone is not the primary general explanation for VAE blur. C: **Correct:** A trained generator can produce realistic data from its latent prior without learning an encoder. D: **Incorrect:** KL regularization shapes the latent distribution and does not by itself guarantee sharper images.

Report a correction for Q3

Question 4 MSQ · 3.0 marks

Consider the ELBO objective in a Variational Autoencoder (VAE):
Source diagram or notation
Which of the following statements are correct?
6406536924655.
Ignoring the KL term leads to learning a model that treats latent variables
Source diagram or notation
as deterministic parameters rather than random variables.
6406536924656.
Optimizing only the KL term ensures that the encoder learns a distribution that still depends on
Source diagram or notation
.
6406536924657.
Optimizing only the KL term ensures that the encoder learns a distribution independent of the input
Source diagram or notation
.
6406536924658.
Optimizing only the KL term ensures that the decoder learns a better likelihood model
Source diagram or notation
due to stronger regularization.
6406536924659.
Optimizing only the KL term forces
Source diagram or notation
to match the prior
Source diagram or notation
for all
Source diagram or notation
.

A published solution is not available for this question yet.

Report a correction for Q4

Question 5 NAT · 2.0 marks

In a Generative Adversarial Network, suppose for a data point
Source diagram or notation
, the real data distribution assigns probability
Source diagram or notation
, while the generator assigns probability
Source diagram or notation
. If
Source diagram or notation
is the optimal discriminator, what probability does it assign to
Source diagram or notation
being generated? Enter the answer correct to two decimal places.

Published solution

**1. Identify real versus generated probability:** Under equal real/fake priors, \(D^*(x)=p_{data}(x)/(p_{data}(x)+p_G(x))\) is the probability of being real. **2. Substitute:** \(D^*=0.25/(0.25+0.75)=0.25\). **3. Answer the question’s direction:** It asks for being generated, so use \(1-D^*=0.75\). Equivalently, divide the generated density by the total density. **Answer: 0.75.**

Report a correction for Q5

Question 6 NAT · 3.0 marks

A Gaussian Mixture Model has two components,
Source diagram or notation
and
Source diagram or notation
, with prior probabilities
Source diagram or notation
. The components are 1D Gaussians with parameters
Source diagram or notation
and
Source diagram or notation
. For a data point
Source diagram or notation
, calculate the responsibility (posterior probability) of component
Source diagram or notation
for this point, i.e.,
Source diagram or notation
. Provide the answer to three decimal places.

Published solution

**1. Use Bayes responsibilities:** \[\gamma_1(x)=\frac{\pi_1\mathcal N(x;\mu_1,\sigma_1^2)}{\pi_1\mathcal N(x;\mu_1,\sigma_1^2)+\pi_2\mathcal N(x;\mu_2,\sigma_2^2)}.\] **2. Evaluate unnormalized weights:** At x=7, component 1 has mean 5, standard deviation 1 and weight 0.6; component 2 has mean 10, standard deviation 2 and weight 0.4. Cancel the common \(1/\sqrt{2\pi}\) factor, leaving \(u_1=0.6e^{-2}\approx0.081201\) and \(u_2=(0.4/2)e^{-9/8}\approx0.064930\). **3. Normalize:** \(\gamma_1=u_1/(u_1+u_2)\approx0.55566\), rounded to 0.556. The second Gaussian’s 1/2 density normalization must be retained. **Answer: 0.556.**

Report a correction for Q6

Question 7 MCQ · 3.0 marks

In a self-attention mechanism, each input vector has dimension
Source diagram or notation
. The queries, keys, and values are computed using separate linear transformations, each mapping from
Source diagram or notation
. Suppose there are
Source diagram or notation
input vectors. Based on the above data, answer the given subquestions.
How many learnable parameters (including both weights and biases) are used to compute the queries, keys, and values?
6406536924661.Source diagram or notation
6406536924662.Source diagram or notation
6406536924663.Source diagram or notation
6406536924664.Source diagram or notation

Published solution

**1. Count one affine projection:** Mapping D input features to D outputs requires D-squared weights and D biases. **2. Count separate query, key and value projections:** \[N_{params}=3(D^2+D)=3D^2+3D.\] **3. Explain sequence-length independence:** The same projection weights are applied at every token, so the N input vectors do not multiply the parameter count. An output projection is not included in this particular question. **Answer: B.** A: **Incorrect:** This counts weights but omits all three bias vectors. B: **Correct:** Three D-by-D weight matrices and three D-length biases give this count. C: **Incorrect:** This counts only one of the three projections. D: **Incorrect:** Six D-squared terms do not describe the specified three affine projections.

Report a correction for Q7

Question 8 NAT · 2.0 marks

In a self-attention mechanism, each input vector has dimension
Source diagram or notation
. The queries, keys, and values are computed using separate linear transformations, each mapping from
Source diagram or notation
. Suppose there are
Source diagram or notation
input vectors. Based on the above data, answer the given subquestions.
How many attention weights
Source diagram or notation
are computed in total if we have
Source diagram or notation
and
Source diagram or notation
?

Published solution

**1. Count query-key pairs:** Every one of N query vectors attends to every one of N key vectors in the stated single-head setting. **2. Form the attention matrix:** Its shape is N-by-N, so it contains N-squared weights. **3. Substitute N=100:** \[100^2=10{,}000.\] Feature width D=16 affects dot-product computation per score, not the number of score entries. **Answer: 10000.**

Report a correction for Q8

Question 9 NAT · 2.0 marks

A sampled generated response produces rewards
Source diagram or notation
with discount factor
Source diagram or notation
Suppose the value function values for different states are
Source diagram or notation
The sampled log-policy gradient scalars
Source diagram or notation
are given as
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the full discounted return
Source diagram or notation
. Enter the answer correct to two decimal places.

Published solution

**1. Use the supplied discounting:** Rewards are (3,1,-2,5), and gamma=0.8. **2. Compute discounted terms:** \[R=3+0.8(1)+0.8^2(-2)+0.8^3(5).\] The terms are 3,0.8,-1.28 and 2.56. **3. Add:** \(R=3+0.8-1.28+2.56=5.08\). Negative rewards remain negative when discounted. **Answer: 5.08.**

Report a correction for Q9

Question 10 NAT · 3.0 marks

A sampled generated response produces rewards
Source diagram or notation
with discount factor
Source diagram or notation
Suppose the value function values for different states are
Source diagram or notation
The sampled log-policy gradient scalars
Source diagram or notation
are given as
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the gradient estimate
Source diagram or notation
where
Source diagram or notation
is the advantage estimate given by
Source diagram or notation
Enter the answer correct to three decimal places.

Published solution

**1. Compute returns from each step:** Working backward with gamma=0.8 gives R3=5, R2=-2+0.8(5)=2, R1=1+0.8(2)=2.6 and R0=3+0.8(2.6)=5.08. **2. Subtract the value baselines:** Values are (4.5,2.0,1.5,5.0), so the sampled advantages are (0.58,0.6,0.5,0). **3. Form the stated scalar gradient estimate:** \[\hat g=0.4(0.58)+0.3(0.6)-0.2(0.5)+0.1(0)=0.232+0.18-0.10=0.312.\] This uses the question’s sum of g_t times advantage without adding an extra discount factor outside those terms. **Answer: 0.312.**

Report a correction for Q10

Question 11 NAT · 2.0 marks

A sequence of length
Source diagram or notation
is represented by
Source diagram or notation
where each row of
Source diagram or notation
represents a token. A single-head attention module uses
Source diagram or notation
Hence
Source diagram or notation
Each row of
Source diagram or notation
and
Source diagram or notation
correspond to the representation of a single input token. Use scaled dot- product attention with
Source diagram or notation
and scale factor
Source diagram or notation
. For the first query only, use the approximations
Source diagram or notation
Based on the above data, answer the given subquestions.
Which token receive the lowest attention score from the query
Source diagram or notation
before scaling? (For token 1, enter your answer as 1, and so on.)

Published solution

**1. Compute the first query:** The first token row is (1,2,0). Multiplying by the supplied WQ gives q1=(1,2). **2. Compute keys:** From K=XWK, the three rows are k1=(1,3), k2=(1,1), k3=(3,2). **3. Compare raw dot products:** \(q_1\cdot k_1=7\), \(q_1\cdot k_2=3\), \(q_1\cdot k_3=7\). Token 2 has the lowest score. Scaling by the same positive square root does not change the order. **Answer: 2.**

Report a correction for Q11

Question 12 NAT · 2.0 marks

A sequence of length
Source diagram or notation
is represented by
Source diagram or notation
where each row of
Source diagram or notation
represents a token. A single-head attention module uses
Source diagram or notation
Hence
Source diagram or notation
Each row of
Source diagram or notation
and
Source diagram or notation
correspond to the representation of a single input token. Use scaled dot- product attention with
Source diagram or notation
and scale factor
Source diagram or notation
. For the first query only, use the approximations
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the attention weight on token 3 for query 1. Enter the answer correct to three decimal places.

Published solution

**1. Find scaled scores:** The first-query dot products are (7,3,7); dividing by \(\sqrt2\) gives approximately (4.950,2.121,4.950). **2. Apply softmax with the supplied approximations:** Exponentials are (141.175,8.339,141.175), totaling 290.689. **3. Normalize token 3:** \[a_{13}=141.175/290.689\approx0.48566.\] Rounded to three decimals, its weight is 0.486. Tokens 1 and 3 receive equal weights. **Answer: 0.486.**

Report a correction for Q12

Question 13 NAT · 3.0 marks

A sequence of length
Source diagram or notation
is represented by
Source diagram or notation
where each row of
Source diagram or notation
represents a token. A single-head attention module uses
Source diagram or notation
Hence
Source diagram or notation
Each row of
Source diagram or notation
and
Source diagram or notation
correspond to the representation of a single input token. Use scaled dot- product attention with
Source diagram or notation
and scale factor
Source diagram or notation
. For the first query only, use the approximations
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the sum of the first and the second coordinate of the attention output for query 1. Enter the answer correct to two decimal places.

Published solution

**1. Compute value vectors:** Multiplying X by WV gives v1=(3,2), v2=(1,2), v3=(2,1). **2. Compute first-query weights:** The raw scores are (7,3,7), and scaled softmax using the provided exponentials gives weights (141.175,8.339,141.175)/290.689. **3. Sum output coordinates efficiently:** The sums of the value-vector coordinates are 5,3 and 3. Thus \[o_{11}+o_{12}=\frac{5(141.175)+3(8.339)+3(141.175)}{290.689}=3.9713\ldots.\] Rounded to two decimals, the requested sum is 3.97. **Answer: 3.97.**

Report a correction for Q13

Question 14 NAT · 1.0 marks

A decoder has the pre-mask scaled score matrix
Source diagram or notation
Causal masking is applied to the scores exactly as in autoregressive transformers. The masking uses
Source diagram or notation
for the mask matrix
Source diagram or notation
. Use
Source diagram or notation
Based on the above data, answer the given subquestions.
For token 3, compute the attention probability assigned to position 4.

Published solution

**1. Apply autoregressive visibility:** Query position 3 may attend to positions 1,2 and 3. Position 4 is a future position. **2. Mask the score:** Its additive mask entry is negative infinity, regardless of the original finite score. **3. Apply softmax:** \(e^{-\infty}=0\), while allowed positions have a positive denominator. Hence \(a_{34}=0\). **Answer: 0.**

Report a correction for Q14

Question 15 NAT · 2.0 marks

A decoder has the pre-mask scaled score matrix
Source diagram or notation
Causal masking is applied to the scores exactly as in autoregressive transformers. The masking uses
Source diagram or notation
for the mask matrix
Source diagram or notation
. Use
Source diagram or notation
Based on the above data, answer the given subquestions.
Which position receives the highest attention weight for token 4? Enter your answer as either 1 or 2 or 3 or 4.

Published solution

**1. Inspect row 4:** Its supplied scaled scores are (0,1,2,5). **2. Check the causal mask:** The final query position may attend to every one of positions 1 through 4, so none of these four entries is masked. **3. Compare:** Softmax preserves order. Score 5 is largest and belongs to position 4, so position 4 receives the highest attention probability. **Answer: 4.**

Report a correction for Q15

Question 16 NAT · 3.0 marks

A decoder has the pre-mask scaled score matrix
Source diagram or notation
Causal masking is applied to the scores exactly as in autoregressive transformers. The masking uses
Source diagram or notation
for the mask matrix
Source diagram or notation
. Use
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the ratio
Source diagram or notation
. Use the masked attention weights. Enter the answer correct to three decimal places.

Published solution

**1. Normalize the token-3 self weight:** After masking, row 3 has scores (1,2,4), so \[a_{33}=e^4/(e^1+e^2+e^4)=54.598/(2.718+7.389+54.598).\] **2. Normalize token 2’s weight on position 1:** Its allowed scores are (2,3), giving \(a_{21}=e^2/(e^2+e^3)=7.389/(7.389+20.085)\). **3. Form the ratio:** \[\frac{a_{33}}{a_{21}}=\frac{54.598/64.705}{7.389/27.474}\approx3.137.\] Each row needs its own softmax denominator; a single raw-score ratio would be incorrect. **Answer: 3.137.**

Report a correction for Q16

Question 17 MCQ · 4.0 marks

For a token at position
Source diagram or notation
, the base embedding is
Source diagram or notation
A sinusoidal positional encoding with
Source diagram or notation
is used:
Source diagram or notation
Use
Source diagram or notation
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the position-enhanced embedding
Source diagram or notation
.
6406536924672.Source diagram or notation
6406536924673.Source diagram or notation
6406536924674.Source diagram or notation
6406536924675.Source diagram or notation

Published solution

**1. Build four positional coordinates:** At position j=3 with model width four, the sinusoidal encoding is \((\sin3,\cos3,\sin0.03,\cos0.03)\), approximately (0.141,-0.990,0.030,0.9996). **2. Add to the base embedding:** The source gives x=(2,1,0,2), so \[\tilde x=(2.141,0.010,0.030,2.9996).\] **3. Match the rounded vector:** It is approximately (2.14,0.01,0.03,3.00), option A. Only two sine/cosine pairs are used for a four-dimensional vector; the PDF’s broad i-range notation is understood within those four coordinates. **Answer: A.** A: **Correct:** This matches coordinate-wise addition and rounding. B: **Incorrect:** The second coordinate should add a negative cosine and become 0.01, not 1.99. C: **Incorrect:** The third coordinate should be 0.03, not 0.30. D: **Incorrect:** The first coordinate must include sin(3), producing 2.14.

Report a correction for Q17

Question 18 MCQ · 2.0 marks

For a token at position
Source diagram or notation
, the base embedding is
Source diagram or notation
A sinusoidal positional encoding with
Source diagram or notation
is used:
Source diagram or notation
Use
Source diagram or notation
Source diagram or notation
Based on the above data, answer the given subquestions.
The sinusoidal positional encoding is added to the token embedding
Source diagram or notation
to form
Source diagram or notation
. Which of the following statements is true?
6406536924676.
It increases the dimensionality of the embedding vector to encode position.
6406536924677.
It adds position information to the embedding while preserving embedding dimensionality.
6406536924678.
It replaces the semantic information in the embedding with positional information.
6406536924679.
It ensures that embeddings are normalized across positions.

Published solution

**1. Match vector shapes:** The token embedding and positional encoding each have the same model dimension. **2. Add coordinate-wise:** \(\tilde x=x+PE(j)\) combines content and position without concatenating extra coordinates. **3. Interpret the effect:** The representation gains positional information while preserving its dimension. Addition does not remove semantic information by definition and does not enforce unit norm or another normalization across positions. **Answer: B — Selected: It adds position information to the embedding while preserving embedding dimensionality.** A: **Incorrect:** Concatenation would increase width; addition does not. B: **Correct:** Equal-dimensional vector addition preserves width and adds position information. C: **Incorrect:** The original content vector remains one component of the sum. D: **Incorrect:** Adding sine/cosine values does not guarantee normalized embeddings.

Report a correction for Q18

Question 19 NAT · 1.0 marks

For two sampled states, the old and new full action distributions over two actions are: State 1:
Source diagram or notation
State 2:
Source diagram or notation
Assume the sampled actions were the first action in both states.The advantages are
Source diagram or notation
Use PPO clipping with
Source diagram or notation
. Use natural logarithms with
Source diagram or notation
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the sampled-action ratio for state 1. Enter the answer correct to one decimal place.

Published solution

**1. Define the importance ratio:** For the sampled action, \(r=\pi_{new}(a\mid s)/\pi_{old}(a\mid s)\). **2. Read state 1’s first-action probabilities:** They are 0.36 for the new policy and 0.30 for the old policy. **3. Divide:** \(r_1=0.36/0.30=1.2\). Use the sampled action’s probability, not a ratio of entire distributions. **Answer: 1.2.**

Report a correction for Q19

Question 20 NAT · 2.0 marks

For two sampled states, the old and new full action distributions over two actions are: State 1:
Source diagram or notation
State 2:
Source diagram or notation
Assume the sampled actions were the first action in both states.The advantages are
Source diagram or notation
Use PPO clipping with
Source diagram or notation
. Use natural logarithms with
Source diagram or notation
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the clipped PPO contribution for state 1. Enter the answer correct to two decimal places.

Published solution

**1. Write the clipped objective term:** \(L=\min(rA,\operatorname{clip}(r,1-\epsilon,1+\epsilon)A)\). **2. Substitute state 1:** r=0.36/0.30=1.2, A=1.8 and epsilon=0.2, so clipping bounds are [0.8,1.2]. The ratio already equals the upper endpoint. **3. Compare the two products:** Both are \(1.2(1.8)=2.16\). Their minimum is 2.16. **Answer: 2.16.**

Report a correction for Q20

Question 21 NAT · 1.0 marks

For two sampled states, the old and new full action distributions over two actions are: State 1:
Source diagram or notation
State 2:
Source diagram or notation
Assume the sampled actions were the first action in both states.The advantages are
Source diagram or notation
Use PPO clipping with
Source diagram or notation
. Use natural logarithms with
Source diagram or notation
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the sampled-action ratio for state 2. Enter the answer correct to one decimal place.

Published solution

**1. Read the sampled action:** The first action is sampled in state 2, with old probability 0.60 and new probability 0.48. **2. Compute the ratio:** \[r_2=0.48/0.60=0.8.\] **3. Interpret:** The new policy assigns this action 80% of its old probability. This also equals the lower clipping endpoint for epsilon=0.2. **Answer: 0.8.**

Report a correction for Q21

Question 22 NAT · 2.0 marks

For two sampled states, the old and new full action distributions over two actions are: State 1:
Source diagram or notation
State 2:
Source diagram or notation
Assume the sampled actions were the first action in both states.The advantages are
Source diagram or notation
Use PPO clipping with
Source diagram or notation
. Use natural logarithms with
Source diagram or notation
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute the clipped PPO contribution for state 2. Enter the answer correct to one decimal place.

Published solution

**1. Compute the state-2 ratio:** \(r_2=0.48/0.60=0.8\). Its advantage is A2=-1.5. **2. Apply the clipping interval:** With epsilon=0.2, [0.8,1.2] leaves this ratio unchanged. **3. Evaluate the objective:** Both candidate products equal \(0.8(-1.5)=-1.2\), so \(\min(-1.2,-1.2)=-1.2\). For negative advantages the min operation still applies to the signed products, not to their magnitudes. **Answer: -1.2.**

Report a correction for Q22

Question 23 NAT · 2.0 marks

For two sampled states, the old and new full action distributions over two actions are: State 1:
Source diagram or notation
State 2:
Source diagram or notation
Assume the sampled actions were the first action in both states.The advantages are
Source diagram or notation
Use PPO clipping with
Source diagram or notation
. Use natural logarithms with
Source diagram or notation
Source diagram or notation
Based on the above data, answer the given subquestions.
Compute
Source diagram or notation
for state 1. Enter the answer correct to four decimal places.

Published solution

**1. Use full-distribution KL:** The question asks \(D_{KL}(\pi_{old}\|\pi_{new})\), so include both actions in state 1: \[D=0.30\ln(0.30/0.36)+0.70\ln(0.70/0.64).\] **2. Use the supplied logarithm approximations:** \(D\approx0.30(-0.182)+0.70(0.090)=-0.0546+0.0630=0.0084\). **3. Report precision:** The four-decimal answer under the supplied approximations is 0.0084. Using unrounded natural logs gives approximately 0.0080, also within the exported accepted range; the discrepancy is from the intentionally coarse log approximations. **Answer: 0.0084.**

Report a correction for Q23