Module 1
Viva Questions
1. What is a Transformer model, and why is it preferred over RNNs for text classification?
A Transformer is a deep learning model based entirely on the attention mechanism,
without using recurrence or convolution.
It is preferred over RNNs because:
It processes tokens in parallel, making training faster
It captures long-range dependencies more effectively
It avoids issues like vanishing gradients
It scales well to large datasets
2. Which Hugging Face classes are typically used to build a Transformer-based text
classification model?
Commonly used Hugging Face classes include:
AutoTokenizer – for text tokenization
AutoModelForSequenceClassification – for classification models
Trainer – to handle training and evaluation
TrainingArguments – to configure training parameters
pipeline – for quick inference
3. What is the role of the tokenizer in the Transformer pipeline?
The tokenizer:
Converts raw text into tokens
Maps tokens to numerical IDs
Adds special tokens like [CLS] and [SEP]
Creates attention masks
Transformers only understand numbers, so tokenization is essential.
4. What happens if text is not tokenized properly?
If tokenization is incorrect:
The model may misinterpret words
Sentence structure can be lost
Important context may be removed
Model accuracy decreases significantly
Incorrect tokenization leads to poor or meaningless predictions.
5. What is role of transformers, torch and pipeline in python code? What are these?
Transformers provides pre-trained models, tokenizers, and training utilities from Hugging
Face.
torch (PyTorch) handles tensor operations, model training, backpropagation, and GPU
acceleration.
Pipeline:- A high-level API for quick tasks like text classification without writing full
training code.
6. What is the purpose of attention masks in text classification models?
Attention masks:
Indicate which tokens are real and which are padding
Prevent the model from attending to padding tokens
Improve prediction accuracy
They ensure the model focuses only on meaningful text.
7. What is the difference between fine-tuning a Transformer and training a model from
scratch?
8. Fine-Tuning Training from Scratch
Uses pre-trained weights Random weight initialization
Requires less data Needs large datasets
Faster training Slower and expensive
Better performance Harder to converge
Fine-tuning is preferred for most NLP tasks.
9. How does batch size affect training stability and GPU memory usage in your
implementation?
Large batch size
a. More stable gradients
b. Faster training
c. Requires more GPU memory
Small batch size
d. Noisier gradients
e. Slower training
f. Lower memory usage
Batch size is chosen based on GPU capacity and model size.
10. What is the attention mechanism, and why is it important in Transformer architectures?
The attention mechanism allows the model to:
Focus on important words in a sentence
Assign different importance weights to tokens
Capture contextual meaning efficiently
It replaces recurrence and enables parallel processing
11. Explain the difference between Query (Q), Key (K), and Value (V) in attention
computation.
Query (Q): What the model is looking for
Key (K): What each word offers
Value (V): Actual information passed forward
Attention scores measure how well Q matches K, and then weight the V vectors.
12. How is the attention score calculated mathematically in self-attention?
Where:
Q K computes similarity
T
√ d k stabilizes gradients
Softmax converts scores to probabilities
13. What does an attention heatmap represent in visualization?
An attention heatmap:
Visualizes attention weights between tokens
Shows which words influence others
Darker colors indicate higher attention
It helps in model interpretability and understanding predictions
Module 2
Viva Questions
1. What is a GAN, and which two neural networks are implemented in your DeepFake
code?
A GAN consists of a Generator and a Discriminator trained together to generate
realistic fake data.
2. What role does the Generator play in a DeepFake application?
The Generator creates synthetic face images that try to look real.
3. How does it learn to generate realistic faces?
The Generator learns to generate realistic faces through adversarial training. It starts by
producing random images from noise. These images are evaluated by the Discriminator,
which provides a loss signal indicating how fake or real the images appear. Using this
loss, the Generator updates its weights via backpropagation to reduce the difference
between generated and real images. Over many iterations, the Generator learns facial
features such as eyes, nose, texture, and expressions, gradually producing realistic faces.
4. What is the function of the Discriminator, and how does it help improve the Generator?
The Discriminator acts as a binary classifier that distinguishes between real images from
the dataset and fake images generated by the Generator. It outputs a probability score
indicating whether an image is real or fake. When the Discriminator correctly classifies
images, it produces meaningful gradients that are backpropagated not only to update
itself but also passed to the Generator. This feedback helps the Generator understand
which features look unrealistic, forcing it to improve image quality over time.
5. Which loss functions are used for the Generator and Discriminator in your code, and
why?
In standard GAN implementations, Binary Cross-Entropy (BCE) loss is used for both
networks:
Discriminator Loss
The Discriminator is trained to:
Assign label 1 to real images
Assign label 0 to fake images
This loss measures how well the Discriminator separates real and fake samples.
Generator Loss
The Generator is trained to:
Make fake images be classified as real (label = 1)
6. How do you evaluate the quality of DeepFake outputs generated by your GAN?
The quality of DeepFake outputs is evaluated using a combination of:
Visual inspection to assess realism, facial consistency, and artifacts
Discriminator accuracy/loss to check how well fake images resemble real ones
7. Why diffusers are used? Which diffuser model you have imported in your python code?
How do you import the diffuser model in your code?
Diffusers are used because they:
Produce high-quality and diverse images
Provide stable training and inference
Offer pretrained diffusion pipelines
In the code, a commonly used model is Stable Diffusion.
from diffusers import StableDiffusionPipeline
import torch
device = "cuda" if [Link].is_available() else "cpu"
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
torch_dtype=torch.float16
).to(device)
prompt = "a realistic photo of a modern house with a garden, daylight, high detail"
image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]
[Link]("sd_output.png")
[Link]()
This pipeline includes the UNet, scheduler, and text encoder required for image
generation.
8. What is a diffusion model, and how does it differ from GAN-based image generation?
A diffusion model generates images by gradually removing noise from a random signal,
whereas GANs generate images in a single forward pass.
Diffusion Model GAN
Step-by-step generation One-shot generation
Stable training Unstable adversarial training
High diversity Risk of mode collapse
Slower inference Faster inference
9. Explain the forward diffusion process implemented in your code.
The forward diffusion process:
Gradually adds Gaussian noise to training images
Continues over multiple timesteps until the image becomes pure noise
Is a fixed, non-learnable process
This prepares the data for training the reverse (denoising) model.
10. What is the reverse diffusion process, and how does the model learn it?
The reverse diffusion process:
Gradually removes noise from a noisy image
Uses a neural network to predict the noise at each timestep
Is learned through supervised training using noisy-clean image pairs
The model learns to reconstruct images by minimizing noise prediction loss.
11. Why is Gaussian noise added gradually during the diffusion process instead of all at
once?
Gradual noise addition:
Makes the reverse process easier to learn
Maintains a smooth probability transition
Prevents loss of structural information early
Adding all noise at once would make reconstruction extremely difficult.
12. What is the role of the UNet architecture in diffusion models?
The UNet:
Predicts the noise component at each timestep
Uses encoder–decoder structure with skip connections
Preserves fine-grained spatial details during denoising
It is the core denoising network in diffusion models.
13. How do parameters like num_inference_steps and guidance_scale affect image quality
and generation speed?
num_inference_steps
a. More steps → better quality, slower generation
b. Fewer steps → faster but lower quality
guidance_scale
c. Higher value → stronger prompt adherence, less diversity
d. Lower value → more diverse but less controlled images
14. Why are diffusion models considered more stable to train compared to GANs?
Diffusion models are more stable because:
They avoid adversarial training
Use a simple mean squared error (MSE) objective
Have well-defined likelihood-based learning
Do not suffer from mode collapse
This results in predictable and reliable training.