uiz Space

January 2025 term · Deep Learning Practice · BSDA5013

Deep Learning Practice Quiz 1: 23 February 2025 (January 2025 term)

The IIT Madras BS Deep Learning Practice (Deep Learning Practice) Quiz 1 paper sat on 23 Feb 2025, in the January 2025 term: 16 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
16
Marks
50
Duration
120 min
MCQ
9
MSQ
4
Numerical
3

Updated

Official paper: IIT M DEGREE AN EXAM QDB2 23 Feb 2025 · No negative marking.

Question 1

+3 marksOne correct option
  1. A

    ["hugging", "face", "is", "awesome"]

  2. B

    [102, 463, 509, 101, 2020]

  3. C

    ["hugging", "face", "is", "awesome", ""]

  4. D

    "Hugging Face is awesome!"

Show answer

Correct answer

  • B

    [102, 463, 509, 101, 2020]

Question 2

+3 marksOne correct option

Consider the following code where a tokenizer is created using the BPE model:

python
from tokenizers import Tokenizer
from tokenizers.models import BPE
from tokenizers.trainers import BpeTrainer
from tokenizers.normalizers import Lowercase
from tokenizers.pre_tokenizers import Whitespace
data = ["existent", "non", "exist", "word"]
# Create a tokenizer with BPE model without specifying the unk_token
model = BPE()
tokenizer = Tokenizer(model)
# Normalizer and Pre-tokenizer
tokenizer.normalizer = Lowercase()
tokenizer.pre_tokenizer = Whitespace()
# Train the tokenizer
trainer = BpeTrainer(vocab_size=5000, special_tokens=["<s>", "</s>", "<pad>"])
tokenizer.train_from_iterator(data, trainer)
# Access the tokenizer's vocabulary
vocab = tokenizer.get_vocab()
# Test tokenization with a word not present in the vocabulary
tokens = tokenizer.encode("nonexistentword").tokens
print("Tokens:", tokens)

Which of the following statements is correct about the tokenization output when the word "nonexistentword" is encountered?

  1. A

    The tokenizer will output the token [UNK] because "nonexistentword" is not in the vocabulary.

  2. B

    The tokenizer will output the word "nonexistentword" as a single token.

  3. C

    The tokenizer will output "non", "existent", "word" as separate tokens since it has split the word into known subwords.

  4. D

    The tokenizer will output "non", "exist", "ent", "word" as separate tokens since it has split the word into known subwords.

  5. E

    The tokenizer will output an error because "nonexistentword" is not present in the vocabulary and the unk_token was not defined.

Show answer

Correct answer

  • C

    The tokenizer will output "non", "existent", "word" as separate tokens since it has split the word into known subwords.

Question 3

+3 marksOne correct option

Consider the following code snippet:

python
from tokenizers import Tokenizer
from tokenizers.models import BPE
from tokenizers.trainers import BpeTrainer
from tokenizers.normalizers import Lowercase
from tokenizers.pre_tokenizers import Whitespace
from tokenizers.processors import TemplateProcessing
data = ["hello", "world"]
# Create a tokenizer with BPE model
model = BPE()
tokenizer = Tokenizer(model)
# Normalizer and Pre-tokenizer
tokenizer.normalizer = Lowercase()
tokenizer.pre_tokenizer = Whitespace()
# Trainer for the tokenizer
trainer = BpeTrainer(vocab_size=5000, special_tokens=["<s>", "</s>", "<pad>", "<unk>"])
tokenizer.train_from_iterator(data, trainer)
# Post-processor
tokenizer.post_processor = TemplateProcessing(single="[CLS] $0 [SEP]",
special_tokens=[("[CLS]", 2), ("[SEP]", 3)])
# Encode input and get the token IDs
encoded = tokenizer.encode("Hello world")
print("Token IDs:", encoded.ids)

What will likely be printed as the output?

  1. A

    [2, 3]

  2. B

    [3, 0, 2]

  3. C

    [2, 0, 1, 3]

  4. D

    [3, 1, 0, 2]

Show answer

Correct answer

  • C

    [2, 0, 1, 3]

Question 4

+3 marksOne correct option

Given the following code snippet:

python
from transformers import AutoModelForSequenceClassification
from peft import LoraConfig
base_model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=2)
lora_config = LoraConfig(
r=8,
lora_alpha=16,
lora_dropout=0.1
)

Which of the following options correctly adds LoRA to the base_model? (Whichever option you choose, assume the corresponding imports already done for them)

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

Correct answer

  • D

Question 5

+3 marksOne correct option

Given the following code for setting up the trainer:

python
from transformers import Trainer, TrainingArguments
training_args = TrainingArguments(
output_dir="./results",
evaluation_strategy="epoch",
save_strategy="epoch",
logging_dir="./logs"
)
trainer = Trainer(
model=peft_model,
args=training_args,
train_dataset=dummy_train_dataset,
eval_dataset=dummy_eval_dataset
)

Which of the following lines correctly starts the fine-tuning process?

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

Correct answer

  • B

Question 6

+3 marksOne correct option

What would happen if you set the target_modules parameter in the LoraConfig to an empty list []?

python
lora_config = LoraConfig(
task_type="SEQ_CLASSIFICATION",
r=8,
lora_alpha=32,
lora_dropout=0.1,
target_modules=[]
)
  1. A

    LoRA will be applied to the entire model, including the embedding layers.

  2. B

    LoRA will only be applied to the final classification layer of the model.

  3. C

    LoRA will not be applied to any layer of the model.

  4. D

    The model will throw an error because an empty list is invalid.

Show answer

Correct answer

  • C

    LoRA will not be applied to any layer of the model.

Question 7

+4 marksOne correct option

Consider the following code where the tokenizer is trained using two different vocabulary sizes: 5K and 50K. The function train_and_tokenize trains a tokenizer with the specified vocabulary size and tokenizes the word "unhappiness". The number of tokens produced for each vocabulary size is stored in n_t_5k and n_t_50k. (Assume get_examples() returns an iterator on some dataset)

python
from tokenizers import Tokenizer
from tokenizers.models import BPE
from tokenizers.trainers import BpeTrainer
from tokenizers.normalizers import Lowercase
from tokenizers.pre_tokenizers import Whitespace
# Function to train and tokenize using a given vocabulary size
def train_and_tokenize(vocab_size):
tokenizer = Tokenizer(BPE())
tokenizer.normalizer = Lowercase()
tokenizer.pre_tokenizer = Whitespace()
# Train the tokenizer with the specified vocabulary size
trainer = BpeTrainer(vocab_size=vocab_size, special_tokens=["<unk>", "<s>", "</s>", "<pad>"])
# tokenizer.train_from_iterator(["unhappiness", "happiness", "unhappy", "joy"], trainer)
tokenizer.train_from_iterator(get_examples(batch_size = 1000), trainer)
# Tokenize the dataset (let's assume we are using a simple list of words)
tokens = tokenizer.encode("unhappiness").tokens
return tokens
print(train_and_tokenize(5000))
print(train_and_tokenize(50000))
# Tokenize using vocab size 5K and 50K
n_t_5k = len(train_and_tokenize(5000))
n_t_50k = len(train_and_tokenize(50000))
# Print results for both vocab sizes
print("Tokens with vocab size 5K:", n_t_5k)
print("Tokens with vocab size 50K:", n_t_50k)

Which of the following is the likely behavior regarding the number of tokens (n_t_5k and n_t_50k) produced when using a vocabulary size of 5K vs. 50K?

  1. A

    n_t_5k > n_t_50k because with a smaller vocabulary size, the tokenizer will split more words into smaller subwords, leading to a higher number of tokens.

  2. B

    n_t_5k < n_t_50k because a smaller vocabulary size means the tokenizer can only split the words into fewer subwords, resulting in fewer tokens.

  3. C

    n_t_5k = n_t_50k because the number of tokens is independent of the vocabulary size and depends on the input words.

  4. D

    n_t_5k = n_t_50k because both vocabularies will represent the word "unhappiness" with the same number of tokens due to the use of subword tokenization.

Show answer

Correct answer

  • A

    n_t_5k > n_t_50k because with a smaller vocabulary size, the tokenizer will split more words into smaller subwords, leading to a higher number of tokens.

Question 8

+2 marksOne correct option

What type of language modeling objective is used during the pretraining of GPT-2?

  1. A

    Masked Language Modeling (MLM)

  2. B

    Sequence-to-Sequence Modeling

  3. C

    Causal Language Modeling (CLM)

  4. D

    Text Classification Objective

Show answer

Correct answer

  • C

    Causal Language Modeling (CLM)

Question 9

+3 marksOne or more correct options

Which of the following is/are gradient based (fine tuning) methods?

Select all that apply.

  1. A

    Zero-shot Tuning

  2. B

    Few-shots Tuning

  3. C

    Instruction Fine tuning

  4. D

    Parameter Efficient Fine Tuning

  5. E

    Preference Tuning Via RLHF

Show answer

Correct answers

  • C

    Instruction Fine tuning

  • D

    Parameter Efficient Fine Tuning

  • E

    Preference Tuning Via RLHF

Question 10

+3 marksOne or more correct options

Select all that apply.

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

Correct answers

  • A
  • C

Question 11

+3 marksOne or more correct options

Select all the correct statements.

Select all that apply.

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

Correct answers

  • A
  • B
  • D

Question 12

+3 marksOne or more correct options

You are working with two datasets and trying to combine them using the following code:

python
from datasets import concatenate_datasets, load_dataset
ds1 = load_dataset("imdb", split="train[:4000]")
ds2 = load_dataset("csv", data_files="reviews.csv")
combined_dataset = concatenate_datasets([ds1, ds2])

Assume the following:

The ds1 dataset has columns: text (string), label (int).
The ds2 dataset has columns: review (string), sentiment (int).

Select all the correct statements.

Select all that apply.

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

Correct answers

  • A
  • C

Question 13

+3 marksNumerical answer

The original train split contains 25,000 samples, and 60% of the samples have a text length greater than 200. If the dataset's text length distribution is uniform across all splits, how many samples will the subset dataset contain?

Show answer

Correct answer: 3750

Question 14

+4 marksNumerical answer

Below is a snippet for loading the GPT-2 model configuration:

python
from transformers import GPT2Config
config = GPT2Config.from_pretrained("gpt2-medium")
print(config)

the output of the above is

text
GPT2Config {
"activation_function": "gelu_new",
"architectures": [
"GPT2LMHeadModel"
],
"attn_pdrop": 0.1,
"bos_token_id": 50256,
"embd_pdrop": 0.1,
"eos_token_id": 50256,
"initializer_range": 0.02,
"layer_norm_epsilon": 1e-05,
"model_type": "gpt2",
"n_ctx": 1024,
"n_embd": 1024,
"n_head": 16,
"n_inner": null,
"n_layer": 24,
"n_positions": 1024,
"n_special": 0,
"predict_special_tokens": true,
"reorder_and_upcast_attn": false,
"resid_pdrop": 0.1,
"scale_attn_by_inverse_layer_idx": false,
"scale_attn_weights": true,
"summary_activation": null,
"summary_first_dropout": 0.1,
"summary_proj_to_labels": true,
"summary_type": "cls_index",
"summary_use_proj": true,
"task_specific_params": {
"text-generation": {
"do_sample": true,
"max_length": 50
}
},
"transformers_version": "4.47.1",
"use_cache": true,
"vocab_size": 50257
}

Based on the above data, answer the given subquestions.

Calculate the number of parameters in the query, key, and value matrices of a single transformer block.

Show answer

Correct answer: 3145728

Question 15

+4 marksNumerical answer

Below is a snippet for loading the GPT-2 model configuration:

python
from transformers import GPT2Config
config = GPT2Config.from_pretrained("gpt2-medium")
print(config)

the output of the above is

text
GPT2Config {
"activation_function": "gelu_new",
"architectures": [
"GPT2LMHeadModel"
],
"attn_pdrop": 0.1,
"bos_token_id": 50256,
"embd_pdrop": 0.1,
"eos_token_id": 50256,
"initializer_range": 0.02,
"layer_norm_epsilon": 1e-05,
"model_type": "gpt2",
"n_ctx": 1024,
"n_embd": 1024,
"n_head": 16,
"n_inner": null,
"n_layer": 24,
"n_positions": 1024,
"n_special": 0,
"predict_special_tokens": true,
"reorder_and_upcast_attn": false,
"resid_pdrop": 0.1,
"scale_attn_by_inverse_layer_idx": false,
"scale_attn_weights": true,
"summary_activation": null,
"summary_first_dropout": 0.1,
"summary_proj_to_labels": true,
"summary_type": "cls_index",
"summary_use_proj": true,
"task_specific_params": {
"text-generation": {
"do_sample": true,
"max_length": 50
}
},
"transformers_version": "4.47.1",
"use_cache": true,
"vocab_size": 50257
}

Based on the above data, answer the given subquestions.

Calculate the number of embedding parameters in the model. Enter your answer in millions, rounded to two decimal places.

Show answer

Correct answer: 51.5 (accepted within ±0.5)

Question 16

+3 marksOne correct option

Below is a snippet for loading the GPT-2 model configuration:

python
from transformers import GPT2Config
config = GPT2Config.from_pretrained("gpt2-medium")
print(config)

the output of the above is

text
GPT2Config {
"activation_function": "gelu_new",
"architectures": [
"GPT2LMHeadModel"
],
"attn_pdrop": 0.1,
"bos_token_id": 50256,
"embd_pdrop": 0.1,
"eos_token_id": 50256,
"initializer_range": 0.02,
"layer_norm_epsilon": 1e-05,
"model_type": "gpt2",
"n_ctx": 1024,
"n_embd": 1024,
"n_head": 16,
"n_inner": null,
"n_layer": 24,
"n_positions": 1024,
"n_special": 0,
"predict_special_tokens": true,
"reorder_and_upcast_attn": false,
"resid_pdrop": 0.1,
"scale_attn_by_inverse_layer_idx": false,
"scale_attn_weights": true,
"summary_activation": null,
"summary_first_dropout": 0.1,
"summary_proj_to_labels": true,
"summary_type": "cls_index",
"summary_use_proj": true,
"task_specific_params": {
"text-generation": {
"do_sample": true,
"max_length": 50
}
},
"transformers_version": "4.47.1",
"use_cache": true,
"vocab_size": 50257
}

Based on the above data, answer the given subquestions.

What does the n_ctx parameter in the GPT-2 configuration represent?

  1. A

    The number of attention heads in the model.

  2. B

    The maximum length of the input sequence in tokens.

  3. C

    The embedding size of each token.

  4. D

    The total number of parameters in the model.

Show answer

Correct answer

  • B

    The maximum length of the input sequence in tokens.