Question 1
["hugging", "face", "is", "awesome"]
[102, 463, 509, 101, 2020]
["hugging", "face", "is", "awesome", ""]
"Hugging Face is awesome!"

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.
["hugging", "face", "is", "awesome"]
[102, 463, 509, 101, 2020]
["hugging", "face", "is", "awesome", ""]
"Hugging Face is awesome!"
Correct answer
[102, 463, 509, 101, 2020]
Consider the following code where a tokenizer is created using the BPE model:
from tokenizers import Tokenizerfrom tokenizers.models import BPEfrom tokenizers.trainers import BpeTrainerfrom tokenizers.normalizers import Lowercasefrom tokenizers.pre_tokenizers import Whitespace
data = ["existent", "non", "exist", "word"]
# Create a tokenizer with BPE model without specifying the unk_tokenmodel = BPE()tokenizer = Tokenizer(model)
# Normalizer and Pre-tokenizertokenizer.normalizer = Lowercase()tokenizer.pre_tokenizer = Whitespace()
# Train the tokenizertrainer = BpeTrainer(vocab_size=5000, special_tokens=["<s>", "</s>", "<pad>"])tokenizer.train_from_iterator(data, trainer)
# Access the tokenizer's vocabularyvocab = tokenizer.get_vocab()
# Test tokenization with a word not present in the vocabulary
tokens = tokenizer.encode("nonexistentword").tokensprint("Tokens:", tokens)Which of the following statements is correct about the tokenization output when the word "nonexistentword" is encountered?
The tokenizer will output the token [UNK] because "nonexistentword" is not in the vocabulary.
The tokenizer will output the word "nonexistentword" as a single token.
The tokenizer will output "non", "existent", "word" as separate tokens since it has split the word into known subwords.
The tokenizer will output "non", "exist", "ent", "word" as separate tokens since it has split the word into known subwords.
The tokenizer will output an error because "nonexistentword" is not present in the vocabulary and the unk_token was not defined.
Correct answer
The tokenizer will output "non", "existent", "word" as separate tokens since it has split the word into known subwords.
Consider the following code snippet:
from tokenizers import Tokenizerfrom tokenizers.models import BPEfrom tokenizers.trainers import BpeTrainerfrom tokenizers.normalizers import Lowercasefrom tokenizers.pre_tokenizers import Whitespacefrom tokenizers.processors import TemplateProcessing
data = ["hello", "world"]
# Create a tokenizer with BPE modelmodel = BPE()tokenizer = Tokenizer(model)
# Normalizer and Pre-tokenizertokenizer.normalizer = Lowercase()tokenizer.pre_tokenizer = Whitespace()
# Trainer for the tokenizertrainer = BpeTrainer(vocab_size=5000, special_tokens=["<s>", "</s>", "<pad>", "<unk>"])tokenizer.train_from_iterator(data, trainer)
# Post-processortokenizer.post_processor = TemplateProcessing(single="[CLS] $0 [SEP]", special_tokens=[("[CLS]", 2), ("[SEP]", 3)])
# Encode input and get the token IDsencoded = tokenizer.encode("Hello world")print("Token IDs:", encoded.ids)What will likely be printed as the output?
[2, 3]
[3, 0, 2]
[2, 0, 1, 3]
[3, 1, 0, 2]
Correct answer
[2, 0, 1, 3]
Given the following code snippet:
from transformers import AutoModelForSequenceClassificationfrom 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)
Correct answer
Given the following code for setting up the trainer:
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?
Correct answer
What would happen if you set the target_modules parameter in the LoraConfig to an empty list []?
lora_config = LoraConfig( task_type="SEQ_CLASSIFICATION", r=8, lora_alpha=32, lora_dropout=0.1, target_modules=[])LoRA will be applied to the entire model, including the embedding layers.
LoRA will only be applied to the final classification layer of the model.
LoRA will not be applied to any layer of the model.
The model will throw an error because an empty list is invalid.
Correct answer
LoRA will not be applied to any layer of the model.
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)
from tokenizers import Tokenizerfrom tokenizers.models import BPEfrom tokenizers.trainers import BpeTrainerfrom tokenizers.normalizers import Lowercasefrom tokenizers.pre_tokenizers import Whitespace
# Function to train and tokenize using a given vocabulary sizedef 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 tokensprint(train_and_tokenize(5000))print(train_and_tokenize(50000))
# Tokenize using vocab size 5K and 50Kn_t_5k = len(train_and_tokenize(5000))n_t_50k = len(train_and_tokenize(50000))
# Print results for both vocab sizesprint("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?
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.
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.
n_t_5k = n_t_50k because the number of tokens is independent of the vocabulary size and depends on the input words.
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.
Correct answer
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.
What type of language modeling objective is used during the pretraining of GPT-2?
Masked Language Modeling (MLM)
Sequence-to-Sequence Modeling
Causal Language Modeling (CLM)
Text Classification Objective
Correct answer
Causal Language Modeling (CLM)
Which of the following is/are gradient based (fine tuning) methods?
Zero-shot Tuning
Few-shots Tuning
Instruction Fine tuning
Parameter Efficient Fine Tuning
Preference Tuning Via RLHF
Correct answers
Instruction Fine tuning
Parameter Efficient Fine Tuning
Preference Tuning Via RLHF
Correct answers
Select all the correct statements.
Correct answers
You are working with two datasets and trying to combine them using the following code:
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.
Correct answers
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?
Correct answer: 3750
Below is a snippet for loading the GPT-2 model configuration:
from transformers import GPT2Config
config = GPT2Config.from_pretrained("gpt2-medium")print(config)the output of the above is
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.
Correct answer: 3145728
Below is a snippet for loading the GPT-2 model configuration:
from transformers import GPT2Config
config = GPT2Config.from_pretrained("gpt2-medium")print(config)the output of the above is
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.
Correct answer: 51.5 (accepted within ±0.5)
Below is a snippet for loading the GPT-2 model configuration:
from transformers import GPT2Config
config = GPT2Config.from_pretrained("gpt2-medium")print(config)the output of the above is
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?
The number of attention heads in the model.
The maximum length of the input sequence in tokens.
The embedding size of each token.
The total number of parameters in the model.
Correct answer
The maximum length of the input sequence in tokens.