uiz Space

May 2025 term · Large Language Models · BSDA5004

Large Language Models End Term: 31 August 2025, Set QDB3 (May 2025 term)

The IIT Madras BS Large Language Models (LLM) End Term paper sat on 31 Aug 2025, in the May 2025 term, set QDB3: 17 questions for 40 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
17
Marks
40
Duration
180 min
MCQ
6
MSQ
3
Numerical
8

Updated

Official paper: IIT M DEGREE AN EXAM QDB3 31 Aug 2025 · No negative marking.

Question 1

+3 marksOne correct option

Given the input string:

sunshine

And the following vocabulary of subword tokens with their corresponding log-probabilities:

SubwordLog-Probability (base ee)
sun-0.5
shine-0.7
sunshine-1.6
su-0.3
nshine-0.4
n-1.8
shi-0.6
ne-0.5

Using the Viterbi algorithm (as used in the SentencePiece tokenizer), determine the most probable tokenization of the input string. The probability of a tokenized sequence is the sum of the log-probabilities of the selected subwords. Only subwords from the vocabulary may be used.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 2

+2 marksOne correct option

A GPT model is trained using causal language modeling. During training, for a sequence of T = 4 tokens, which of the following correctly represents the attention mask matrix applied to the attention logits?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 3

+2 marksOne correct option
  1. A

    (a) : Random Local Attention,
    (b) : Strided Local Attention,
    (c) : Sparse Block Attention,
    (d) : Local + Global Attention

  2. B

    (a) : Strided Local Attention,
    (b) : Local + Global Attention,
    (c) : Random Local Attention,
    (d) : Sparse Block Attention

  3. C

    (a) : Strided Local Attention,
    (b) : Random Local Attention,
    (c) : Local + Global Attention,
    (d) : Sparse Block Attention

  4. D

    (a) : Sparse Block Attention,
    (b) : Local + Global Attention,
    (c) : Strided Local Attention,
    (d) : Random Local Attention

Show answer

Correct answer

  • B

    (a) : Strided Local Attention,
    (b) : Local + Global Attention,
    (c) : Random Local Attention,
    (d) : Sparse Block Attention

Question 4

+3 marksOne or more correct options

Which of the following preprocessing steps are commonly used when preparing data for transformer models like BERT?

Select all that apply.

  1. A

    Adding special tokens such as [CLS] and [SEP] to the sequence

  2. B

    Splitting tokens into subword units using a model-specific tokenizer

  3. C

    Removing all punctuation marks to ensure cleaner embeddings

  4. D

    Adding positional information to each token embedding

Show answer

Correct answers

  • A

    Adding special tokens such as [CLS] and [SEP] to the sequence

  • B

    Splitting tokens into subword units using a model-specific tokenizer

  • D

    Adding positional information to each token embedding

Question 5

+3 marksOne or more correct options

Which modifications are used in transformers to handle longer sequences efficiently?

Select all that apply.

  1. A

    Using sparse attention patterns to reduce computational complexity

  2. B

    Applying low-rank matrix factorization to approximate attention

  3. C

    Increasing only the feed-forward network width without modifying attention

  4. D

    Replacing the softmax function in attention with other activation function for faster training

Show answer

Correct answers

  • A

    Using sparse attention patterns to reduce computational complexity

  • B

    Applying low-rank matrix factorization to approximate attention

Question 6

+3 marksOne or more correct options

In Transformer models that use relative position embeddings (such as in Transformer-XL or T5), clipping is often applied to the relative position indices. Which of the following statements about clipping in relative position embeddings are correct?

Select all that apply.

  1. A

    Clipping ensures that very large relative distances are mapped to a fixed maximum distance.

  2. B

    Without clipping, the model would require embeddings for every possible relative distance, which is infeasible for long sequences.

  3. C

    Clipping increases the precision of embeddings for large relative distances.

  4. D

    Clipping introduces an upper bound k such that all distances greater than k are mapped to the same index.

Show answer

Correct answers

  • A

    Clipping ensures that very large relative distances are mapped to a fixed maximum distance.

  • B

    Without clipping, the model would require embeddings for every possible relative distance, which is infeasible for long sequences.

  • D

    Clipping introduces an upper bound k such that all distances greater than k are mapped to the same index.

Question 7

+2 marksNumerical answer
Show answer

Correct answer: 6

Question 8

+3 marksNumerical answer

A vocabulary V={tea,you,enjoy,often}\mathcal{V} = \{\text{tea}, \text{you}, \text{enjoy}, \text{often}\} is associated with the following embedding matrix:

E=[011110−11]E = \begin{bmatrix} 0 & 1 \\ 1 & 1 \\ 1 & 0 \\ -1 & 1 \end{bmatrix}

Words are indexed in the order shown above: “tea” (index 0), “you” (1), “enjoy” (2), and “often” (3). No positional encodings are used.

The parameters of the attention layer are:

WQ=[0.5110.5],WK=[10.5−0.51],WV=[10.20.51],W_Q = \begin{bmatrix} 0.5 & 1 \\ 1 & 0.5 \end{bmatrix}, \quad W_K = \begin{bmatrix} 1 & 0.5 \\ -0.5 & 1 \end{bmatrix}, \quad W_V = \begin{bmatrix} 1 & 0.2 \\ 0.5 & 1 \end{bmatrix},

WO=[0.50.51−1]W_O = \begin{bmatrix} 0.5 & 0.5 \\ 1 & -1 \end{bmatrix}

For the input sequence “you enjoy tea often”. The computed attention matrix A=softmax(QK⊤dk)A = \text{softmax}\left(\frac{QK^\top}{\sqrt{d_k}}\right) is given as:

A=[0.550.320.110.020.430.250.210.10.390.390.160.070.240.40.20.17]A = \begin{bmatrix} 0.55 & 0.32 & 0.11 & 0.02 \\ 0.43 & 0.25 & 0.21 & 0.1 \\ 0.39 & 0.39 & 0.16 & 0.07 \\ 0.24 & 0.4 & 0.2 & 0.17 \end{bmatrix}

Answer the given subquestions. If you believe the information is insufficient, enter -1 as your answer.

For the input “you enjoy tea often”, compute the final representation of the word “enjoy” after the attention layer (i.e., after applying WQ, WK, WV , attention weights, and WO). Enter the sum of the elements in the resulting vector.

Show answer

Correct answer: 0.96 (accepted within ±0.04)

Question 9

+2 marksNumerical answer

A vocabulary V={tea,you,enjoy,often}\mathcal{V} = \{\text{tea}, \text{you}, \text{enjoy}, \text{often}\} is associated with the following embedding matrix:

E=[011110−11]E = \begin{bmatrix} 0 & 1 \\ 1 & 1 \\ 1 & 0 \\ -1 & 1 \end{bmatrix}

Words are indexed in the order shown above: “tea” (index 0), “you” (1), “enjoy” (2), and “often” (3). No positional encodings are used.

The parameters of the attention layer are:

WQ=[0.5110.5],WK=[10.5−0.51],WV=[10.20.51],W_Q = \begin{bmatrix} 0.5 & 1 \\ 1 & 0.5 \end{bmatrix}, \quad W_K = \begin{bmatrix} 1 & 0.5 \\ -0.5 & 1 \end{bmatrix}, \quad W_V = \begin{bmatrix} 1 & 0.2 \\ 0.5 & 1 \end{bmatrix},

WO=[0.50.51−1]W_O = \begin{bmatrix} 0.5 & 0.5 \\ 1 & -1 \end{bmatrix}

For the input sequence “you enjoy tea often”. The computed attention matrix A=softmax(QK⊤dk)A = \text{softmax}\left(\frac{QK^\top}{\sqrt{d_k}}\right) is given as:

A=[0.550.320.110.020.430.250.210.10.390.390.160.070.240.40.20.17]A = \begin{bmatrix} 0.55 & 0.32 & 0.11 & 0.02 \\ 0.43 & 0.25 & 0.21 & 0.1 \\ 0.39 & 0.39 & 0.16 & 0.07 \\ 0.24 & 0.4 & 0.2 & 0.17 \end{bmatrix}

Answer the given subquestions. If you believe the information is insufficient, enter -1 as your answer.

Suppose the input sentence is “tea you enjoy often”. Using the same matrices and processing method, what is the attention score (i.e., softmax entry from A) for the query word “tea” attending to key word “often”?

Show answer

Correct answer: 0.07 (accepted within ±0.03)

Question 10

+2 marksOne correct option

Based on the above data, answer the given subquestions.

Choose the correct representation of π for the given mask image.

  1. A

    π = (2, 1, 3, 4, 0)

  2. B

    π = (0, 4, 3, 1, 2)

  3. C

    π = (0, 3, 4, 2, 1)

  4. D

    All of these

Show answer

Correct answer

  • C

    π = (0, 3, 4, 2, 1)

Question 11

+1 markNumerical answer

Based on the above data, answer the given subquestions.

How many permutations of π are possible for n = 5?

Show answer

Correct answer: 120

Question 12

+2 marksNumerical answer

Based on the above data, answer the given subquestions.

What percentage of entries in the attention matrix are zero (i.e., the sparsity)?

Show answer

Correct answer: 80

Question 13

+2 marksOne correct option

Consider the short sentence:

“small models sometimes beat big ones”

A model processes this sequence using the naive relative positional embedding method. The model's embedding dimension is dmodel=4d_{\text{model}} = 4, and the number of tokens is T=6T = 6. We use zero-based indexing for token positions:

0:small1:models2:sometimes3:beat4:big5:ones0: \texttt{small} \quad 1: \texttt{models} \quad 2: \texttt{sometimes} \quad 3: \texttt{beat} \quad 4: \texttt{big} \quad 5: \texttt{ones}

Note: In this context, the relative position between two tokens is:

Relative position=j−i\text{Relative position} = j - i

(rows == current token ii, columns == other token jj).

  1. Token embeddings (rows correspond to tokens in order):

    X=[111122223333444455556666].\mathbf{X} = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 2 & 2 & 2 & 2 \\ 3 & 3 & 3 & 3 \\ 4 & 4 & 4 & 4 \\ 5 & 5 & 5 & 5 \\ 6 & 6 & 6 & 6 \end{bmatrix}.

    Denote the ii-th row by xi\boldsymbol{x}_i.

  2. Positional embedding definition: For a relative position,

    p(j−i)=[(j−i)5(j−i)5(j−i)5(j−i)5].\boldsymbol{p}_{(j-i)} = \left[\frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5}\right].

Based on the above data, answer the given subquestions.

  1. A

    (0, 1, 2, 3, 4, 5)

  2. B

    (-1, 0, 1, 2, 3, 4)

  3. C

    (-3, -2, -1, 0, 1, 2)

  4. D

    (-2, -1, 0, 1, 2, 3)

Show answer

Correct answer

  • D

    (-2, -1, 0, 1, 2, 3)

Question 14

+2 marksOne correct option

Consider the short sentence:

“small models sometimes beat big ones”

A model processes this sequence using the naive relative positional embedding method. The model's embedding dimension is dmodel=4d_{\text{model}} = 4, and the number of tokens is T=6T = 6. We use zero-based indexing for token positions:

0:small1:models2:sometimes3:beat4:big5:ones0: \texttt{small} \quad 1: \texttt{models} \quad 2: \texttt{sometimes} \quad 3: \texttt{beat} \quad 4: \texttt{big} \quad 5: \texttt{ones}

Note: In this context, the relative position between two tokens is:

Relative position=j−i\text{Relative position} = j - i

(rows == current token ii, columns == other token jj).

  1. Token embeddings (rows correspond to tokens in order):

    X=[111122223333444455556666].\mathbf{X} = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 2 & 2 & 2 & 2 \\ 3 & 3 & 3 & 3 \\ 4 & 4 & 4 & 4 \\ 5 & 5 & 5 & 5 \\ 6 & 6 & 6 & 6 \end{bmatrix}.

    Denote the ii-th row by xi\boldsymbol{x}_i.

  2. Positional embedding definition: For a relative position,

    p(j−i)=[(j−i)5(j−i)5(j−i)5(j−i)5].\boldsymbol{p}_{(j-i)} = \left[\frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5}\right].

Based on the above data, answer the given subquestions.

  1. A

    [−0.4,−0.4,−0.4,−0.4]

  2. B

    [−0.1,−0.1,−0.1,−0.1]

  3. C

    [−0.8,−0.8,−0.8,−0.8]

  4. D

    [−0.2,−0.2,−0.2,−0.2]

Show answer

Correct answer

  • C

    [−0.8,−0.8,−0.8,−0.8]

Question 15

+3 marksNumerical answer

Consider the short sentence:

“small models sometimes beat big ones”

A model processes this sequence using the naive relative positional embedding method. The model's embedding dimension is dmodel=4d_{\text{model}} = 4, and the number of tokens is T=6T = 6. We use zero-based indexing for token positions:

0:small1:models2:sometimes3:beat4:big5:ones0: \texttt{small} \quad 1: \texttt{models} \quad 2: \texttt{sometimes} \quad 3: \texttt{beat} \quad 4: \texttt{big} \quad 5: \texttt{ones}

Note: In this context, the relative position between two tokens is:

Relative position=j−i\text{Relative position} = j - i

(rows == current token ii, columns == other token jj).

  1. Token embeddings (rows correspond to tokens in order):

    X=[111122223333444455556666].\mathbf{X} = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 2 & 2 & 2 & 2 \\ 3 & 3 & 3 & 3 \\ 4 & 4 & 4 & 4 \\ 5 & 5 & 5 & 5 \\ 6 & 6 & 6 & 6 \end{bmatrix}.

    Denote the ii-th row by xi\boldsymbol{x}_i.

  2. Positional embedding definition: For a relative position,

    p(j−i)=[(j−i)5(j−i)5(j−i)5(j−i)5].\boldsymbol{p}_{(j-i)} = \left[\frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5}\right].

Based on the above data, answer the given subquestions.

With a naive implementation, for each token embedding we combine (by addition) relative position embeddings. For token index i∈{0,…,T−1}i \in \{0, \ldots, T-1\},

hi=xi+∑j=0T−1pj−i\boldsymbol{h}_i = \boldsymbol{x}_i + \sum_{j=0}^{T-1} \boldsymbol{p}_{j-i}

compute the final combined embedding hi\boldsymbol{h}_i for the token "models" (i.e., i=1i = 1). Submit the sum of all the elements of h1\boldsymbol{h}_1

Show answer

Correct answer: 15.2

Question 16

+2 marksNumerical answer

Consider the short sentence:

“small models sometimes beat big ones”

A model processes this sequence using the naive relative positional embedding method. The model's embedding dimension is dmodel=4d_{\text{model}} = 4, and the number of tokens is T=6T = 6. We use zero-based indexing for token positions:

0:small1:models2:sometimes3:beat4:big5:ones0: \texttt{small} \quad 1: \texttt{models} \quad 2: \texttt{sometimes} \quad 3: \texttt{beat} \quad 4: \texttt{big} \quad 5: \texttt{ones}

Note: In this context, the relative position between two tokens is:

Relative position=j−i\text{Relative position} = j - i

(rows == current token ii, columns == other token jj).

  1. Token embeddings (rows correspond to tokens in order):

    X=[111122223333444455556666].\mathbf{X} = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 2 & 2 & 2 & 2 \\ 3 & 3 & 3 & 3 \\ 4 & 4 & 4 & 4 \\ 5 & 5 & 5 & 5 \\ 6 & 6 & 6 & 6 \end{bmatrix}.

    Denote the ii-th row by xi\boldsymbol{x}_i.

  2. Positional embedding definition: For a relative position,

    p(j−i)=[(j−i)5(j−i)5(j−i)5(j−i)5].\boldsymbol{p}_{(j-i)} = \left[\frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5}\right].

Based on the above data, answer the given subquestions.

Show answer

Correct answer: 24 (accepted within ±0.3)

Question 17

+3 marksNumerical answer

Consider the short sentence:

“small models sometimes beat big ones”

A model processes this sequence using the naive relative positional embedding method. The model's embedding dimension is dmodel=4d_{\text{model}} = 4, and the number of tokens is T=6T = 6. We use zero-based indexing for token positions:

0:small1:models2:sometimes3:beat4:big5:ones0: \texttt{small} \quad 1: \texttt{models} \quad 2: \texttt{sometimes} \quad 3: \texttt{beat} \quad 4: \texttt{big} \quad 5: \texttt{ones}

Note: In this context, the relative position between two tokens is:

Relative position=j−i\text{Relative position} = j - i

(rows == current token ii, columns == other token jj).

  1. Token embeddings (rows correspond to tokens in order):

    X=[111122223333444455556666].\mathbf{X} = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 2 & 2 & 2 & 2 \\ 3 & 3 & 3 & 3 \\ 4 & 4 & 4 & 4 \\ 5 & 5 & 5 & 5 \\ 6 & 6 & 6 & 6 \end{bmatrix}.

    Denote the ii-th row by xi\boldsymbol{x}_i.

  2. Positional embedding definition: For a relative position,

    p(j−i)=[(j−i)5(j−i)5(j−i)5(j−i)5].\boldsymbol{p}_{(j-i)} = \left[\frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5} \quad \frac{(j-i)}{5}\right].

Based on the above data, answer the given subquestions.

Now consider the same sequence but assume the model uses the ALiBi (Attention with Linear Biases) method. The model has H=4H = 4 heads and the per-head slope is defined as

mh=12h,h=0,1,2,3,m_h = \frac{1}{2^h}, h = 0, 1, 2, 3,

The pre-attention eije_{ij} for head hh are computed as:

xiWQxjWK  +  mh⋅[(j−i)]x_i W_Q x_j W_K \; + \; m_h \cdot \left[(j - i)\right]

Assume WQ=IW_Q = I and WK=2IW_K = 2I where II is an identity matrix . Answer eije_{ij} for the current token “big” and other token “small” for head h=2h = 2. correct upto 1 digit after the decimal.

Show answer

Correct answer: 39