INTELLIGENT LEARNING SYSTEMS
& APPLICATIONS (ILSA)
Comprehensive Answer Key
16-Mark | 2-Mark | Numerical Questions
Unit Topic 16-Mark Qs 2-Mark Qs Numericals
1 Self-Supervised, Meta & Graph ML 10 15 5
2 Causal, Probabilistic & Continual Learning 11 15 5
3 Federated, Generative & Trustworthy ML 11 15 5
With Architecture Diagrams, Formulas, Examples & Analogies
UNIT 1: Self-Supervised, Meta & Graph Machine Learning
16-MARK QUESTIONS
Q1. Explain the concept of self-supervised learning. Discuss representation learning and
pretext tasks with suitable examples.
What is Self-Supervised Learning (SSL)?
Self-supervised learning is a paradigm where the model generates its own supervisory signals from unlabeled
data, eliminating the need for expensive human annotations. Think of it like a student who creates their own
practice tests from a textbook — the textbook has no answer key, but the student designs questions where the
answers can be verified from the text itself.
SSL sits between supervised learning (needs labels) and unsupervised learning (finds patterns without any
guidance). In SSL, part of the input is hidden or transformed, and the model must predict or reconstruct it. This
forces the model to learn meaningful internal representations of the data.
Self-Supervised Learning Pipeline
Unlabeled Pretext Learned Fine-Tune on Final
Data Task Representation Downstream Model
Images, Text, etc. Rotation, Jigsaw, Feature Vectors Classification, Trained
Masking, Colorization Detection, etc.
Representation Learning
Representation learning is the process of automatically discovering useful feature representations from raw
data. Instead of hand-crafting features (like edge detectors in images), the model learns to extract hierarchical
features that capture the semantic meaning of the data.
A good representation has these properties: (a) It captures the essential information needed for downstream
tasks, (b) It is compact and removes irrelevant noise, (c) It generalizes across different tasks — features
learned for one task transfer well to others, and (d) It disentangles factors of variation (e.g., separating shape
from color in images).
Analogy: Representation learning is like learning to summarize books. A good summary captures the key
themes (useful features) while discarding filler words (noise). Once you learn to summarize well, you can
apply that skill to any book (generalization).
Pretext Tasks
Pretext tasks are cleverly designed auxiliary tasks where labels are automatically generated from the data
itself. The actual goal is not to solve the pretext task perfectly, but to force the model to learn useful
representations in the process.
Common pretext tasks include:
1. Image Rotation Prediction: Rotate an image by 0°, 90°, 180°, or 270° and train the model to predict the
rotation angle. To predict rotation, the model must understand object orientation, gravity, and scene layout —
all useful features.
2. Jigsaw Puzzle: Split an image into a grid of patches (e.g., 3×3), shuffle them randomly, and train the model
to predict the correct arrangement. This forces learning spatial relationships between parts.
3. Colorization: Convert a color image to grayscale and train the model to predict the original colors. The
model must understand that sky is blue, grass is green — learning semantic content.
4. Masked Image Modeling (MAE): Randomly mask 75% of image patches and predict the missing pixels.
Used in Vision Transformers (ViT). Forces holistic scene understanding.
5. Next Sentence Prediction (NLP): Given two sentences, predict if the second follows the first in the original
text. Used in BERT to learn discourse-level understanding.
6. Masked Language Modeling: Mask random words in a sentence and predict them from context. 'The
[MASK] sat on the mat' → 'cat'. Core pretext task in BERT.
Real-world impact: GPT, BERT, CLIP, and DALL-E all use self-supervised pretext tasks. ImageNet
pre-training with SSL now matches or exceeds supervised pre-training, despite using zero labels.
Q2. Describe contrastive learning in detail. Explain the working principles of SimCLR and
MoCo architectures.
Contrastive Learning: Core Idea
Contrastive learning teaches a model to pull similar (positive) pairs close together in embedding space and
push dissimilar (negative) pairs apart. It learns by comparison rather than prediction.
The fundamental principle is: if two views are created from the same image (via different augmentations), their
representations should be similar. Views from different images should have different representations.
Analogy: Imagine learning to recognize your friend. You see them in different outfits, lighting, and angles
(positive pairs — same person, different views). You also see strangers (negative pairs). Over time, you
learn features that identify your friend regardless of surface variations.
Key components: (1) Data augmentation to create positive pairs, (2) An encoder network to extract features,
(3) A projection head to map features to a contrastive space, (4) A contrastive loss function (like NT-Xent or
InfoNCE) to optimize the similarity structure.
SimCLR (Simple Framework for Contrastive Learning of Visual Representations)
SimCLR, proposed by Chen et al. (2020) at Google, is an elegantly simple yet powerful contrastive learning
framework.
SimCLR Architecture: Contrastive Learning Framework
Input Image x
Random Aug 1 Random Aug 2
Augmented x_i Augmented x_j
Encoder f(.) Encoder f(.)
(Shared weights - ResNet) (Shared weights - ResNet)
Maximize NT-Xent Agreement
Projection g(.) Projection g(.)
Loss
SimCLR Pipeline:
Step 1 — Augmentation: For each image x in a batch of N images, apply two random augmentations (random
crop + resize, color distortion, Gaussian blur) to get x_i and x_j. This creates 2N augmented views total.
Step 2 — Encoding: Both views pass through the same encoder f(·) — typically a ResNet-50. This produces
representation vectors h_i = f(x_i) and h_j = f(x_j). The encoder has shared weights (Siamese structure).
Step 3 — Projection: A small MLP projection head g(·) maps representations to a lower-dimensional space:
z_i = g(h_i). The contrastive loss is applied in this projected space. Importantly, the projection head is
discarded after training — only the encoder is kept.
Step 4 — NT-Xent Loss: For each positive pair (z_i, z_j), the other 2(N-1) augmented views in the batch serve
as negatives. The loss maximizes agreement between positive pairs while pushing negatives apart.
NT-Xent Loss: L(i,j) = -log( exp(sim(z_i,z_j)/tau) / SUM_k
exp(sim(z_i,z_k)/tau) )
where sim(u,v) = cosine similarity = u·v / (||u|| · ||v||), and tau is a temperature parameter (typically 0.5) that
controls the sharpness of the distribution.
Key findings: Composition of augmentations matters greatly — random crop + color distortion is the most
effective combination. Larger batch sizes (4096-8192) dramatically improve performance by providing more
negatives. The projection head is crucial during training but should be removed for downstream transfer.
MoCo (Momentum Contrast)
MoCo, proposed by He et al. (2020) at Facebook AI, addresses SimCLR's requirement for extremely large
batch sizes by maintaining a dynamic dictionary (queue) of negative keys.
MoCo: Momentum Contrast Architecture
Query x_q Key x_k
Queue
(Dictionary)
Momentum Update:
k0, k1,f_k...,
= m*f_k
kN + (1-m)*f_q Momentum
Encoder f_q
Encoder f_k
Dequeue oldest
Enqueue
Query q Key k
MoCo Architecture:
Query Encoder f_q: A standard encoder that is updated via backpropagation. Processes the query
augmentation to produce query vector q.
Momentum Encoder f_k: A slowly-evolving copy of f_q. Updated via exponential moving average (EMA): f_k
= m·f_k + (1−m)·f_q, where m = 0.999. This ensures consistency of keys over time.
Queue (Dictionary): A FIFO queue storing the K most recent key representations (K = 65536). New keys are
enqueued; oldest keys are dequeued. This decouples the dictionary size from the batch size.
InfoNCE Loss: Treats the matching key as positive and all queue entries as negatives.
L_q = -log( exp(q · k+ / tau) / SUM_{i=0}^{K} exp(q · k_i / tau) )
SimCLR vs MoCo Comparison
Aspect SimCLR MoCo
Negative source Within same batch External queue (FIFO)
Batch size Very large (4096+) Small batches work (256)
needed
Hardware Multiple TPUs/GPUs Single GPU feasible
requirement
Key consistency Naturally consistent (same batch) Momentum encoder ensures it
Dictionary size = 2(N-1), limited by batch 65536+, independent of batch
Training stability Sensitive to batch size More stable across settings
Q3. Compare supervised, unsupervised, and self-supervised learning approaches. Highlight
advantages and limitations.
Learning Paradigms Comparison
Supervised Unsupervised Self-Supervised
• Labeled data required • No labels at all • Labels FROM the data itself
• Human annotates each sample • Find hidden patterns • Pretext tasks auto-generate
• Direct task training • Clustering, PCA, etc. • Learn representations first
• Costly but accurate • Cheap but limited • Best of both worlds
• E.g.: ImageNet classification • E.g.: K-means, Autoencoders • E.g.: SimCLR, BERT, MAE
Detailed Comparison
Criterion Supervised Unsupervised Self-Supervised
Labels Human-annotated labels No labels needed Auto-generated pseudo-labels
required from data
Signal source External (human annotators) Internal (data structure) Internal (pretext tasks)
Data cost Very high (annotation Low (raw data only) Low (raw data only)
expensive)
Learning Minimize prediction error on Discover hidden Solve pretext task to learn
objective labeled targets patterns/clusters representations
Scalability Limited by annotation budget Scales with data Scales with data (best
scalability)
Representatio Task-specific, may not General but often shallow General AND deep — excellent
n quality transfer well transfer
Examples Image classification K-Means, PCA, SimCLR, BERT, GPT, MAE,
(ImageNet), NER, Sentiment Autoencoders, DBSCAN DINO
Use case When labeled data is Exploration, dimensionality Pre-training when unlabeled
abundant and task is clear reduction, anomaly detection data is abundant, then
fine-tuning
Advantages and Limitations
Supervised: ■ Highest task-specific accuracy when data is sufficient. ■ Clear optimization objective. ■
Annotation is expensive ($0.05–$5 per label). ■ Labels may be noisy or biased. ■ Doesn't leverage abundant
unlabeled data.
Unsupervised: ■ No label cost at all. ■ Discovers hidden structure. ■ No guarantee learned patterns are
useful for downstream tasks. ■ Evaluation is subjective (what makes a good cluster?). ■ Often learns
superficial features.
Self-Supervised: ■ Leverages massive unlabeled data. ■ Learned representations are universal and transfer
well. ■ Matches or exceeds supervised pre-training. ■ Requires careful pretext task design. ■ Computationally
expensive to pre-train. ■ May learn shortcut solutions that don't generalize.
Practical insight: The modern trend in industry is SSL pre-training on huge unlabeled datasets, followed by
supervised fine-tuning on small labeled datasets. This is the paradigm behind GPT, BERT, CLIP, and
foundation models.
Q4. Explain meta-learning and its significance in few-shot and zero-shot learning scenarios.
Meta-Learning: Learning to Learn
Meta-learning is a paradigm where the model learns how to learn efficiently from very few examples. Instead of
training a model on one specific task, we train it across many tasks so it acquires a general learning strategy
that can be rapidly adapted to new, unseen tasks.
Analogy: A medical student who has studied many diseases doesn't need to memorize everything about a
new rare disease from scratch. Their meta-knowledge of how diseases work (symptoms patterns,
pathology, treatment frameworks) lets them quickly understand a new disease from just a few case studies.
This is meta-learning.
The meta-learning paradigm consists of:
Meta-training phase: The model is exposed to many different tasks (called episodes). Each episode contains
a small support set (like a training set) and a query set (like a test set). The model learns to use the support set
effectively to perform well on the query set.
Meta-testing phase: The model encounters entirely new tasks (new classes it has never seen). Using its
learned learning strategy, it adapts quickly from just a few examples.
Meta-Learning: N-way K-shot Episode Structure
Support Set (Training) Query Set (Test)
Cat Cat Dog Dog Bird Bird ? ? ?
N=3 classes, K=2 shots per class Predict class for each query
Model
Predictions: Cat, Dog, Bird
Few-Shot Learning (N-way K-shot)
In few-shot learning, the model must classify among N new classes given only K labeled examples per class.
For instance, 5-way 1-shot means: given 1 example each of 5 new classes, classify new test images into one
of these 5 classes.
This is extremely challenging because traditional deep learning needs thousands of examples per class.
Few-shot learning addresses scenarios where data collection is expensive or rare — medical images of rare
diseases, endangered species identification, new product recognition.
Zero-Shot Learning
In zero-shot learning, the model must recognize classes it has never seen even a single example of. This is
possible by leveraging semantic relationships — using textual descriptions, attributes, or knowledge graphs
that link unseen classes to seen classes.
For example, a model that has seen 'horse' and 'black-and-white stripes pattern' can recognize a 'zebra'
without ever seeing one, by combining these semantic attributes. Models like CLIP achieve this by learning a
shared embedding space between images and text descriptions.
Three Families of Meta-Learning
Family Approach Key Methods How It Works
Metric-Based Learn a good distance Prototypical Networks, Classify by similarity to class
function Siamese Networks, Matching prototypes in embedding space
Networks
Optimization-Ba Learn good initialization MAML, Reptile Find initial weights that can be
sed parameters fine-tuned in few gradient steps
Model-Based Learn a model that Neural Turing Machines, Use external memory or attention
reads support set and SNAIL, Memory-Augmented to rapidly incorporate new
predicts Networks information
Significance: Meta-learning is crucial for (1) Robotics — robots must adapt to new objects/tasks quickly, (2)
Drug discovery — few molecules available per target, (3) Personalization — adapt models to individual users
from limited interactions, (4) Low-resource languages — NLP for languages with minimal training data, and (5)
Security — detect novel attack types from few examples.
Q5. Discuss Prototypical Networks as a metric-based meta-learning approach with architecture
and working.
Prototypical Networks: Overview
Prototypical Networks, proposed by Snell et al. (2017), are a metric-based meta-learning approach that
classifies new examples by computing their distance to class prototypes in a learned embedding space. The
key insight is elegant: each class can be represented by a single prototype — the mean of its support set
embeddings.
Prototypical Networks: Metric-Based Meta-Learning
Embedding Space
Support c1
Samples Encoder
f_theta
q q = query
Classify by
Mean of embeddings
= Prototype per class nearest prototype
c2
c3
p(y=k|x) = softmax(-d(f(x), c_k)) where c_k = mean of class k embeddings
Architecture and Working — Step by Step
Step 1 — Episode Construction: For N-way K-shot training, sample N classes from the dataset. For each
class, randomly select K examples for the support set S and a few examples for the query set Q.
Step 2 — Embedding: All support and query examples are passed through a shared embedding function f_θ
(typically a CNN like a 4-layer ConvNet or ResNet). This maps each input x to a d-dimensional vector: f_θ(x) ∈
R^d.
Step 3 — Prototype Computation: For each class k, compute the prototype c_k as the mean of its support
set embeddings:
c_k = (1/|S_k|) * SUM_{(x_i, y_i) in S_k} f_theta(x_i)
Step 4 — Distance Computation: For each query example x_q, compute the Euclidean distance to every
class prototype:
d(f_theta(x_q), c_k) = ||f_theta(x_q) - c_k||^2
Step 5 — Classification via Softmax: Convert distances to probabilities using softmax over negative
distances:
p(y=k | x_q) = exp(-d(f_theta(x_q), c_k)) / SUM_j exp(-d(f_theta(x_q), c_j))
Step 6 — Loss and Training: Minimize negative log-probability of the true class for all query examples.
Backpropagate through the entire pipeline to update the encoder f_θ.
Why Prototypical Networks Work
The model learns an embedding space where classes form tight, well-separated clusters. The prototype
(centroid) is a robust summary of the class, being more stable than any single example. Even with K=1
(one-shot), the single example serves as the prototype directly.
Analogy: Imagine organizing a library. Each genre (sci-fi, romance, mystery) has a 'representative shelf'
(prototype). When a new book arrives, you compare it to each representative shelf and place it in the closest
genre section. Prototypical Networks do exactly this in high-dimensional embedding space.
Advantages and Limitations
Advantages: Simple and elegant — just means and distances. Fast inference — no iterative optimization at
test time. Scales well with number of classes. Naturally handles variable K (number of shots). Strong empirical
performance on miniImageNet, Omniglot, tieredImageNet.
Limitations: Assumes classes form spherical clusters in embedding space (due to Euclidean distance).
Prototype as mean can be influenced by outliers. May struggle with highly multimodal class distributions. Fixed
embedding — doesn't adapt the encoder to the specific task at test time (unlike MAML).
Q6. Explain graph data representation. Describe nodes, edges, and attributes with real-world
examples.
Graph Data: Why Graphs?
Many real-world datasets have an inherent relational or network structure that cannot be captured by regular
grids (images) or sequences (text). Graphs provide a flexible mathematical framework to represent entities and
their relationships. A graph G is defined as G = (V, E, X) where V is the set of nodes (vertices), E is the set of
edges, and X contains attributes/features.
Graph Data Structure: Social Network Example
Components:
Nodes (V): Entities - Alice, Bob, Carol, Dave, Eve
Eve
Edges (E): Relationships - friendships between people
Alice
Attributes: Node features (age, interests) &
Edge features (friendship duration)
Dave Bob Adjacency: Matrix A where A[i][j]=1 if edge exists
Degree: Number of connections per node
Carol
G = (V, E, X) |V|=5, |E|=6
Avg Degree = 2E/V = 12/5 = 2.4
Nodes (Vertices)
Nodes represent entities in the graph. Each node can have an associated feature vector (node attributes) that
describes its properties.
Examples: In a social network, each person is a node with features like age, interests, and location. In a
molecular graph, each atom is a node with features like atomic number, charge, and hybridization state. In a
citation network, each paper is a node with features derived from its abstract or title.
Edges
Edges represent relationships or connections between nodes. Edges can be directed (one-way, like 'follows'
on Twitter) or undirected (two-way, like 'friends' on Facebook). Edges can also have features — for instance, in
a road network, edge features might include distance, speed limit, and number of lanes.
Types: (1) Unweighted — edge exists or doesn't (binary). (2) Weighted — edges have numerical weights (e.g.,
strength of friendship, distance between cities). (3) Signed — positive or negative relationships (e.g., trust vs.
distrust). (4) Temporal — edges have timestamps (e.g., when a transaction occurred). (5) Multi-relational —
different types of edges (e.g., 'works-with' vs. 'reports-to').
Attributes (Features)
Node attributes (X ∈ R^{n×d}): A feature matrix where n is the number of nodes and d is the feature
dimension. Row i contains the feature vector for node i.
Edge attributes: Features associated with each edge, stored as a matrix or dictionary.
Graph-level attributes: Global properties of the entire graph (e.g., molecular weight for a molecule graph).
Mathematical Representation
Adjacency Matrix A: An n×n matrix where A[i][j] = 1 if there's an edge between node i and node j (or the edge
weight for weighted graphs). For undirected graphs, A is symmetric.
Degree Matrix D: A diagonal matrix where D[i][i] = degree of node i (number of connections).
Laplacian L = D - A: Used in spectral graph theory and graph signal processing.
Real-World Graph Examples
Domain Nodes Edges Node Features Application
Social Users Friendships/fol Demographics, Friend
Networks lows interests recommendation
Molecular Atoms Chemical Atomic number, Drug discovery
Biology bonds charge
Knowledge Entities Relations Descriptions, types Question answering
Graphs
Traffic Intersection Roads Traffic flow, signals Route optimization
Networks s
Citation Papers Citations Abstract embeddings Paper
Networks recommendation
E-Commerce Users + Purchases/vie User profiles, product Recommendation
Products ws specs systems
Q7. Discuss different graph learning tasks: node-level, edge-level, and graph-level predictions.
Three Levels of Graph Learning Tasks
Graph learning tasks are categorized by the granularity at which predictions are made — at the level of
individual nodes, pairs of nodes (edges), or entire graphs.
1. Node-Level Tasks
Goal: Predict a property or label for each individual node in the graph.
Node Classification: Assign a category to each node. Example: In a citation network, classify each paper into
its research topic (ML, NLP, CV, etc.) based on its connections and features. In a social network, predict if a
user is a bot or human.
Node Regression: Predict a continuous value for each node. Example: Predict the price of a house (node)
based on neighborhood graph structure.
How it works: GNN layers aggregate information from neighboring nodes to build richer representations. After
L layers, each node's representation captures information from its L-hop neighborhood. A final
classification/regression head operates on these node embeddings.
Semi-supervised setting: Often, only a small fraction of nodes have labels. The model leverages the graph
structure to propagate label information to unlabeled nodes — this is why GNNs excel in semi-supervised
learning.
2. Edge-Level Tasks
Goal: Predict properties of edges, or predict whether an edge should exist between two nodes.
Link Prediction: Given a graph with some edges missing, predict which pairs of nodes should be connected.
Example: Predicting future friendships in social networks, recommending products to users (user-product
bipartite graph), predicting protein-protein interactions in biology.
Edge Classification: Classify the type of relationship between connected nodes. Example: In a knowledge
graph, given (Entity A, ?, Entity B), predict the relation type (is-a, part-of, located-in, etc.).
How it works: Compute embeddings for both endpoint nodes, then combine them (concatenation, dot product,
or learned MLP) to produce an edge-level prediction. The score function s(u,v) indicates the likelihood or type
of edge between nodes u and v.
3. Graph-Level Tasks
Goal: Predict a property of an entire graph as a single entity.
Graph Classification: Assign a label to the entire graph. Example: Given a molecular graph, predict if the
molecule is toxic or non-toxic. Given a program's control flow graph, predict if it contains a bug.
Graph Regression: Predict a continuous property of the entire graph. Example: Predict the solubility or
binding affinity of a molecule.
How it works: First, compute node embeddings using GNN layers. Then, aggregate all node embeddings into
a single graph-level representation using a readout/pooling function (sum, mean, max, or attention-based
pooling). Finally, apply a classification or regression head on this graph embedding.
Graph Readout: h_G = READOUT({h_v | v in V}) = SUM/MEAN/ATTENTION over all node
embeddings
Task Level Prediction Target Key Application Pooling Needed?
Node-Level Label/value per node User classification, fraud No — operate on node
detection embeddings directly
Edge-Level Edge existence or type Link prediction, recommendation No — combine endpoint
embeddings
Graph-Level Label/value for entire graph Molecular property prediction Yes — aggregate all node
embeddings
Q8. Explain Graph Neural Networks. Compare Graph Convolutional Networks (GCN) and Graph
Attention Networks (GAT).
Graph Neural Networks: The Message Passing Framework
Graph Neural Networks (GNNs) extend deep learning to graph-structured data. The core mechanism is
message passing (also called neighborhood aggregation): each node updates its representation by collecting
and aggregating information from its neighbors, then combining it with its own features.
General GNN update rule at layer l:
h_v^(l) = UPDATE( h_v^(l-1), AGGREGATE({h_u^(l-1) : u in N(v)}) )
where h_v^(l) is the representation of node v at layer l, N(v) is the set of neighbors of v, AGGREGATE collects
neighbor information, and UPDATE combines it with the node's own features.
After L layers of message passing, each node's representation captures structural and feature information from
its L-hop neighborhood. This is what makes GNNs powerful — they naturally incorporate both node features
and graph topology.
GCN vs GAT: Message Passing Comparison
Graph Convolutional Network (GCN) Graph Attention Network (GAT)
n n n n
1/deg 1/deg a=0.4 a=0.1
v v
1/deg 1/deg a=0.3 a=0.2
n n n n
Equal weights based on Learned attention weights
degree normalization (different importance per neighbor)
h_v = sigma(SUM(1/sqrt(d_i*d_j) * h_j * W)) h_v = sigma(SUM(alpha_ij * W * h_j))
Graph Convolutional Network (GCN) — Kipf & Welling, 2017
GCN defines graph convolution as a spectral operation simplified into a spatial aggregation. The key idea is to
perform a normalized sum of neighbor features:
h_v^(l) = sigma( SUM_{u in N(v) U {v}} (1 / sqrt(d_u * d_v)) * h_u^(l-1) *
W^(l) )
where d_u and d_v are the degrees of nodes u and v (for normalization), W^(l) is a learnable weight matrix
shared across all nodes at layer l, and σ is an activation function (typically ReLU). The normalization term
1/√(d_u·d_v) prevents nodes with many neighbors from dominating and prevents the scale of representations
from exploding.
Properties of GCN: (1) All neighbors contribute equally (weighted only by degree), (2) Same weight matrix for
all nodes — parameter-efficient, (3) Based on spectral graph theory (1st-order Chebyshev approximation), (4)
Simple and computationally efficient, (5) Works well when all neighbors are equally important.
Graph Attention Network (GAT) — Veli■kovi■ et al., 2018
GAT introduces attention mechanisms to graph neural networks, allowing the model to learn which neighbors
are more important for each node. Instead of fixed normalization weights (like GCN), GAT computes dynamic
attention coefficients:
alpha_ij = softmax_j( LeakyReLU( a^T [W*h_i || W*h_j] ) )
h_i^(l) = sigma( SUM_{j in N(i)} alpha_ij * W * h_j^(l-1) )
where α_ij is the learned attention weight from node j to node i, a is a learnable attention vector, W is a shared
weight matrix, and || denotes concatenation. GAT also supports multi-head attention — K independent
attention heads compute representations in parallel, which are then concatenated or averaged.
GCN vs GAT — Detailed Comparison
Aspect GCN GAT
Weight Fixed (degree-based normalization) Learned (attention mechanism)
assignment
Neighbor All neighbors treated equally Different importance per neighbor
importance
Expressiveness Limited — cannot distinguish neighbor Higher — adapts to each node's context
roles
Multi-head No Yes — K attention heads in parallel
support
Computational O(|E| × d²) — cheaper O(|E| × d² × K) — more expensive
cost
Interpretability Low — fixed aggregation High — attention weights show importance
Best suited for Homogeneous graphs, transductive Heterogeneous importance, inductive learning
learning
Parameters One W per layer W + attention params per layer × K heads
Practical example: In a citation network, GCN treats all cited papers equally. GAT can learn that a seminal
foundational paper deserves more attention than a tangentially related citation — mimicking how
researchers actually read papers.
Q9. Analyze challenges in graph learning such as scalability, sparsity, and over-smoothing.
1. Scalability
Real-world graphs are massive — Facebook has billions of nodes and hundreds of billions of edges. Standard
GNN training requires the full graph in memory for message passing, which is infeasible at this scale.
Challenges: Full-batch training requires storing the adjacency matrix (O(n²) memory). Neighbor explosion: at L
layers, each node aggregates from O(d^L) nodes where d is average degree. This exponential growth makes
deep GNNs prohibitive.
Solutions: (a) Mini-batch training with neighbor sampling (GraphSAGE): randomly sample a fixed number of
neighbors at each layer. (b) Cluster-GCN: partition the graph into clusters and train on subgraphs. (c) Graph
partitioning: split large graphs and process in parallel. (d) Simplifying GNN: SGC removes non-linearities
between layers, reducing to a single matrix multiplication.
2. Sparsity
Most real-world graphs are extremely sparse — the adjacency matrix is mostly zeros. In a social network with 1
billion users, each user has ~200 friends on average, so only 200/10^9 = 0.00002% of possible edges exist.
Challenges: Sparse neighborhoods mean limited information for aggregation. Isolated nodes (degree 0)
receive no neighborhood information. Cold-start problem: new nodes have no edges yet. Uneven degree
distribution (power law) means some nodes have thousands of edges while most have very few.
Solutions: (a) Self-loops: add edges from each node to itself (included in GCN by default). (b) Graph
augmentation: add virtual edges based on similarity. (c) Positional encodings: provide additional structural
information. (d) Feature propagation: spread features to disconnected nodes before GNN processing.
3. Over-Smoothing
Over-smoothing is the most critical challenge unique to GNNs. As we stack more GNN layers, all node
representations converge to the same vector — they become indistinguishable. This is because each layer
averages neighbor features, and after many rounds of averaging, everything converges to the global mean.
Mathematically, after L layers, each node's receptive field covers its L-hop neighborhood. When L approaches
the graph diameter, every node sees the entire graph, causing all representations to become nearly identical.
This severely limits GNN depth — most GNNs use only 2-3 layers.
Solutions: (a) Residual connections: h^(l) = h^(l) + h^(l-1), preserving original information. (b) JK-Net
(Jumping Knowledge): concatenate representations from all layers. (c) DropEdge: randomly remove edges
during training to slow information diffusion. (d) PairNorm: normalize representations to maintain variance. (e)
DeeperGCN: combines residual connections, layer normalization, and message normalization.
4. Other Challenges
Heterogeneity: Real graphs have multiple node types and edge types (heterogeneous graphs). Standard
GNNs assume homogeneity — specialized architectures like HAN (Heterogeneous Graph Attention Network)
or R-GCN are needed.
Dynamic graphs: Many graphs evolve over time (edges appear/disappear). Temporal GNNs must handle this
evolution without retraining from scratch.
Expressiveness: Standard message-passing GNNs cannot distinguish certain graph structures (limited by the
Weisfeiler-Lehman graph isomorphism test). Higher-order GNNs and graph transformers address this
limitation.
Q10. Explain the application of self-supervised, meta, and graph learning in computer vision
with a suitable case study.
Case Study: Medical Image Analysis for Rare Disease Diagnosis
Consider the challenge of diagnosing rare skin conditions from dermoscopic images. This application naturally
requires all three paradigms because: (a) Labeled medical images are scarce and expensive (dermatologist
annotation costs ~$50/image), (b) Rare diseases have very few examples (few-shot), and (c) Skin lesion
relationships form a graph (similar conditions, anatomical co-occurrences).
Phase 1: Self-Supervised Pre-Training
Given 500,000 unlabeled dermoscopic images (easy to collect from clinical systems), use SimCLR/DINO to
learn visual representations. Pretext tasks specific to medical imaging: (a) Jigsaw puzzle on lesion patches —
forces learning of texture and border patterns, (b) Rotation prediction — learns orientation-invariant features,
(c) Colorization — learns that melanomas have specific color patterns (asymmetric pigmentation). After SSL
pre-training, the encoder captures medically relevant features like asymmetry, border irregularity, color
variation, and diameter — the ABCD criteria dermatologists use.
Phase 2: Meta-Learning for Few-Shot Diagnosis
For rare conditions with only 5-10 labeled images each, fine-tune the SSL-pretrained encoder using
Prototypical Networks. Training episodes simulate the clinical scenario: support set = reference atlas images of
each condition, query set = new patient images. The model learns to classify by similarity to prototypes in the
learned embedding space. With a pre-trained encoder + Prototypical Networks, the system achieves 78%
accuracy on 5-way 5-shot rare disease classification — competitive with resident dermatologists.
Phase 3: Graph Learning for Holistic Diagnosis
Build a graph where: Nodes = skin lesions from the same patient, Edges = spatial proximity on body +
temporal co-occurrence + visual similarity. Use a GCN/GAT to reason about multi-lesion patterns: 'This patient
has lesion A on the arm and lesion B on the trunk with specific morphological features — together they suggest
condition X rather than Y.' Graph-level pooling produces a patient-level diagnosis, integrating information
across all lesions. This mimics how dermatologists perform full-body skin exams rather than examining lesions
in isolation.
Impact: This integrated pipeline achieves: 85% accuracy on rare disease diagnosis (surpassing individual
paradigms), reduces diagnostic delay for rare conditions from months to minutes, enables deployment in
underserved clinics without specialist dermatologists, and continually improves as new unlabeled images are
added (SSL) and new conditions are encountered (meta-learning).
2-MARK QUESTIONS — UNIT 1
Q1. Define self-supervised learning.
Ans: Self-supervised learning is a machine learning paradigm where the model automatically generates
supervisory signals from unlabeled data by designing pretext tasks. The data itself provides the labels — for
example, predicting a masked word in a sentence or the rotation angle of an image. This eliminates the need
for expensive human annotations while learning useful representations that transfer to downstream tasks.
Q2. What is a pretext task? Give one example.
Ans: A pretext task is an auxiliary task designed to create self-supervised labels from the data itself. The goal
is not to solve the pretext task perfectly but to learn meaningful representations in the process. Example:
Image Rotation Prediction — rotate an image by 0°, 90°, 180°, or 270° and train the model to predict the
angle. To do this, the model must learn about object orientation, gravity, and scene structure.
Q3. What is representation learning?
Ans: Representation learning is the process of automatically discovering compact, informative feature
representations from raw data, replacing manual feature engineering. A good representation captures
essential semantic information, removes noise, and generalizes across tasks. For example, word2vec learns
word embeddings where semantically similar words are close in vector space ('king' - 'man' + 'woman' ≈
'queen').
Q4. Define contrastive learning.
Ans: Contrastive learning is a self-supervised learning approach that learns representations by contrasting
positive pairs (similar samples, e.g., two augmentations of the same image) against negative pairs (dissimilar
samples, e.g., augmentations from different images). The objective is to maximize agreement between
positive pairs and minimize agreement with negatives in the embedding space.
Q5. What is the role of positive and negative pairs in contrastive learning?
Ans: Positive pairs (two views of the same sample) are pulled close in embedding space, teaching the
model what features should be invariant (e.g., object identity regardless of augmentation). Negative pairs
(views from different samples) are pushed apart, preventing the model from collapsing to a trivial solution
where all inputs map to the same point. Both are essential — without negatives, the model collapses; without
positives, it learns nothing meaningful.
Q6. Expand SimCLR and MoCo.
Ans: SimCLR: Simple Framework for Contrastive Learning of Visual Representations. Proposed by Chen et
al. (2020) at Google. Uses large-batch contrastive learning with random augmentations, a shared encoder,
projection head, and NT-Xent loss. MoCo: Momentum Contrast. Proposed by He et al. (2020) at Facebook AI
Research. Uses a momentum-updated key encoder and a queue-based dictionary to enable contrastive
learning with small batch sizes.
Q7. What is meta-learning?
Ans: Meta-learning, or 'learning to learn,' is a paradigm where the model is trained across many tasks to
acquire a general learning strategy that enables rapid adaptation to new, unseen tasks with very few
examples. Instead of learning a single task well, the model learns how to learn efficiently. Three main
approaches: metric-based (learn similarity), optimization-based (learn good initializations, e.g., MAML), and
model-based (learn to read and store new information).
Q8. Define few-shot learning.
Ans: Few-shot learning is a machine learning setting where the model must learn to recognize new classes
from only a very small number of labeled examples (typically 1-5 per class). Formally, N-way K-shot
classification means classifying among N new classes given only K labeled examples per class. This is
motivated by real-world scenarios where data collection is expensive (medical imaging, rare species, etc.).
Q9. What is zero-shot learning?
Ans: Zero-shot learning is the ability to recognize or classify objects from classes that were never seen during
training — not even a single example. This is achieved by leveraging auxiliary information like textual
descriptions, attributes, or semantic embeddings that relate unseen classes to seen ones. For example, CLIP
aligns images and text in a shared embedding space, enabling classification of any class described in natural
language without specific training images.
Q10. What is a Prototypical Network?
Ans: A Prototypical Network is a metric-based meta-learning model that classifies query examples by their
distance to class prototypes in a learned embedding space. Each class prototype is computed as the mean
embedding of its support set examples: c_k = mean(f_θ(x_i) for x_i in class k). Classification is done via
softmax over negative distances: p(y=k|x) = softmax(-||f_θ(x) - c_k||²). Simple yet effective for few-shot
learning.
Q11. Define graph data structure.
Ans: A graph is a mathematical structure G = (V, E) consisting of a set of nodes (vertices) V and a set of
edges E that represent connections between pairs of nodes. Optionally, nodes and edges can have
associated feature vectors (attributes). Graphs can be directed or undirected, weighted or unweighted. They
are the natural representation for relational data like social networks, molecules, and transportation systems.
Q12. What are nodes and edges?
Ans: Nodes (vertices) represent entities in a graph — people in a social network, atoms in a molecule, or
web pages on the internet. Each node can have a feature vector describing its properties. Edges represent
relationships or connections between nodes — friendships, chemical bonds, or hyperlinks. Edges can be
directed (A→B) or undirected (A↔B), and may carry weights representing relationship strength.
Q13. What is node classification?
Ans: Node classification is a graph learning task where the goal is to predict the label or category of each
node in a graph based on its features and its neighborhood structure. For example, in a citation network,
classify each paper into its research topic. GNNs solve this by aggregating neighbor information through
message passing, enabling semi-supervised learning where only a few nodes have labels.
Q14. Define Graph Neural Network (GNN).
Ans: A Graph Neural Network is a neural network designed to operate on graph-structured data. It learns
node representations by iteratively aggregating and transforming features from neighboring nodes (message
passing). After L layers, each node's embedding captures information from its L-hop neighborhood. The
general update: h_v^(l) = UPDATE(h_v^(l-1), AGGREGATE({h_u^(l-1) : u ∈ N(v)})). GNNs handle
variable-size, non-Euclidean graph structures that standard CNNs and RNNs cannot.
Q15. What is over-smoothing in GNNs?
Ans: Over-smoothing is a phenomenon where node representations become increasingly similar (converge to
the same vector) as more GNN layers are stacked. This occurs because each layer averages neighbor
features, and after many layers, every node's receptive field covers the entire graph, causing all
representations to converge to the graph's global mean. This limits GNNs to typically 2-3 layers. Solutions
include residual connections, jumping knowledge, and DropEdge.
NUMERICAL PROBLEMS — UNIT 1
Q16. A graph has 6 nodes and 9 edges. Find the average degree.
Given: |V| = 6 nodes, |E| = 9 edges
Formula: Average degree = 2|E| / |V|
(Each edge contributes to the degree of 2 nodes)
Solution: Average degree = 2 × 9 / 6 = 18 / 6 = 3
Interpretation: On average, each node is connected to 3 other nodes.
Q17. If a node has degree 4 in an undirected graph, how many edges are connected to it?
Given: Degree of node = 4
Answer: In an undirected graph, the degree of a node equals the number of edges
incident to it.
Therefore, 4 edges are connected to this node.
(Note: In a directed graph, degree = in-degree + out-degree, but here it's
undirected.)
Q18. In a graph with 10 nodes, maximum possible edges = ?
Given: n = 10 nodes, undirected simple graph (no self-loops, no multi-edges)
Formula: Max edges = n(n-1)/2
(Each node can connect to n-1 others, divided by 2 to avoid double-counting)
Solution: Max edges = 10 × 9 / 2 = 90 / 2 = 45
This is a complete graph K■■.
Q19. If embedding vector dimension = 128 and 10 nodes exist, find total feature values stored.
Given: Embedding dimension d = 128, Number of nodes n = 10
Solution: Feature matrix X has shape n × d
Total feature values = n × d = 10 × 128 = 1280
This matrix X ∈ R^{10×128} stores all node features.
Q20. If 3 positive and 5 negative pairs are used, total contrastive pairs = ?
Given: 3 positive pairs, 5 negative pairs
Solution: Total contrastive pairs = 3 + 5 = 8
In contrastive learning, the loss function operates over all pairs. Typically,
for a batch of N samples, we get N positive pairs and N(N-1)-N negative pairs.
UNIT 2: Causal, Probabilistic & Continual Learning
16-MARK QUESTIONS
Q1. Differentiate between correlation and causation. Explain why causation is important in
machine learning.
Correlation vs. Causation
Correlation measures the statistical association between two variables — when one changes, the other tends
to change as well. It is symmetric (if A correlates with B, then B correlates with A) and says nothing about the
direction of influence. A correlation coefficient r ranges from -1 to +1.
Causation means that one variable directly influences or produces a change in another. It is directional (A
causes B does not imply B causes A) and implies a mechanism of action. Establishing causation requires
controlled experiments or causal inference frameworks.
Classic example: Ice cream sales and drowning deaths are positively correlated. But ice cream doesn't
cause drowning. Both are caused by a common confounder — hot weather. Temperature → more
swimming → more drownings. Temperature → more ice cream purchases. This is a spurious correlation.
Aspect Correlation Causation
Definition Statistical co-occurrence Direct influence mechanism
Direction Symmetric (A↔B) Directional (A→B)
Implies No Yes
mechanism?
Confounders Not accounted for Must be controlled
Sufficient for No — misleading if confounders exist Yes — reliable basis for interventions
action?
How to establish Observational data + statistics Randomized controlled trials or causal
inference
Why Causation Matters in Machine Learning
1. Robustness: Correlation-based models break when data distribution shifts. A model that learns 'wet roads
correlate with accidents' may predict more accidents whenever it rains, but fails in winter when roads are icy
(different mechanism). A causal model understands that 'reduced friction causes accidents' and works
regardless of the specific cause of reduced friction.
2. Fairness: Correlation-based models can encode societal biases. If income correlates with zip code which
correlates with race, a loan approval model might discriminate. Causal reasoning identifies which variables are
actually relevant (income, employment) vs. proxy discrimination paths.
3. Decision-making: ML is increasingly used for decisions — treatment plans, policy interventions, pricing
strategies. Acting on correlations can be harmful. If hospitalized patients with pneumonia who have asthma
had lower mortality (because they received more intensive care), a correlation-based model might wrongly
suggest that asthma reduces pneumonia risk — a dangerous conclusion.
4. Counterfactual reasoning: Understanding 'what would have happened if we had acted differently' is
essential for explanation and accountability. Only causal models can answer questions like 'Would this patient
have recovered if given a different treatment?'
5. Transferability: Causal relationships are more stable across environments than correlations. A causal
model trained in one hospital can work in another because the causal mechanisms (biology) are the same,
even if the correlations (demographics, equipment) differ.
Q2. Explain Structural Causal Models (SCM). Describe graphs, structural equations, and
assumptions.
Structural Causal Models: The Language of Causation
A Structural Causal Model (SCM), formalized by Judea Pearl, is a mathematical framework for representing
and reasoning about causal relationships. An SCM M = (U, V, F, P(U)) consists of: U — exogenous (external)
variables, V — endogenous (internal) variables, F — a set of structural equations, and P(U) — probability
distribution over exogenous variables.
Structural Causal Model (SCM): Ice Cream & Drowning Example
Temperature
(Confounder Z)
Causes Causes
Ice Cream Drowning
Sales (X) Spurious Correlation (NOT Causation) Deaths (Y)
Structural Equations: X = f_X(Z, U_X) Y = f_Y(Z, U_Y) Z = f_Z(U_Z)
Intervention do(X=x): Cut incoming arrows to X, set X=x, observe effect on Y after controlling for Z
1. Causal Graphs (DAGs)
The causal graph is a Directed Acyclic Graph (DAG) where: nodes represent variables, directed edges
represent direct causal relationships (X → Y means X directly causes Y), and the graph has no cycles (no
variable can cause itself through a chain). The graph encodes conditional independence relationships —
d-separation criteria determine which variables are independent given others.
Key structures in causal graphs:
• Chain: X → Z → Y (Z mediates the effect of X on Y)
• Fork: X ← Z → Y (Z confounds X and Y, creating spurious correlation)
• Collider: X → Z ← Y (Conditioning on Z creates a spurious association between X and Y)
2. Structural Equations
Each endogenous variable V_i has a structural equation that specifies how it is determined by its direct causes
(parents in the DAG) and an exogenous noise term:
V_i = f_i(PA_i, U_i)
where PA_i are the parent variables of V_i in the causal graph, and U_i is the exogenous noise specific to V_i.
Unlike regression equations, structural equations are asymmetric and represent actual causal mechanisms.
Example SCM for a hiring system: Education = f■(U_education), Skill = f■(Education, U_skill), Salary =
f■(Skill, Experience, U_salary). This says education causes skill development, and salary is caused by skill
and experience. We can intervene (set Education = PhD) and trace the causal effect on Salary through the
structural equations.
3. Assumptions
Causal Markov Assumption: Each variable is independent of its non-descendants given its parents. This
connects the DAG structure to probability distributions.
Faithfulness: All conditional independencies in the data are captured by the graph. No additional
independencies exist by coincidence.
Causal Sufficiency: All common causes of measured variables are included in the model. No hidden
confounders exist (a strong assumption often relaxed).
No Cycles (Acyclicity): The causal graph is a DAG — no feedback loops. This ensures well-defined causal
ordering.
Q3. Discuss interventions and do-calculus. Explain counterfactual reasoning with examples.
Interventions: The 'do' Operator
An intervention is the act of externally setting a variable to a specific value, overriding its natural causal
mechanism. Pearl's do-operator, written do(X=x), represents this. The crucial distinction is: P(Y|X=x) is
observational (what is Y when we observe X=x?), while P(Y|do(X=x)) is interventional (what happens to Y
when we force X=x?).
Graphically, do(X=x) means: cut all incoming edges to X (remove its natural causes), set X=x, and observe the
resulting distribution of other variables. This is called graph surgery or graph mutilation.
Example: Observing that people who carry lighters have higher lung cancer rates (P(cancer|lighter=yes) is
high) does NOT mean forcing people to carry lighters would cause cancer. The confounder is smoking.
P(cancer|do(lighter=yes)) would show no effect because carrying a lighter doesn't cause cancer — smoking
does. The do-operator removes the confounding path.
Do-Calculus: Three Rules
Do-calculus (Pearl, 1995) provides three rules for transforming interventional expressions into observational
ones — enabling us to estimate causal effects from observational data without experiments:
Rule 1 (Insertion/deletion of observations): P(Y|do(X), Z, W) = P(Y|do(X), W) if Y ⊥ Z | X, W in the
manipulated graph.
Rule 2 (Action/observation exchange): P(Y|do(X), do(Z), W) = P(Y|do(X), Z, W) if Y ⊥ Z | X, W in the graph
where incoming edges to Z are removed.
Rule 3 (Insertion/deletion of actions): P(Y|do(X), do(Z), W) = P(Y|do(X), W) if Y ⊥ Z | X, W in the graph
where all edges into Z from non-ancestors of W are removed.
These rules are complete — any identifiable causal effect can be computed using these three rules. The
backdoor adjustment formula is a special case:
P(Y|do(X=x)) = SUM_z P(Y|X=x, Z=z) * P(Z=z)
This adjusts for confounders Z by summing over all values of Z.
Counterfactual Reasoning
Counterfactuals ask 'what if' questions about alternative scenarios that didn't actually occur. They sit at the
highest level of Pearl's causal hierarchy: Level 1 — Association (seeing), Level 2 — Intervention (doing), Level
3 — Counterfactuals (imagining).
Formally, a counterfactual Y_x(u) asks: 'For individual u, what would Y have been if X had been set to x?' This
requires: (a) Abduction — use observed evidence to determine the exogenous variables U for the specific
individual. (b) Action — modify the SCM by setting X=x (do(X=x)). (c) Prediction — compute Y in the modified
SCM with the determined U values.
Medical counterfactual: A patient received drug A and died. Counterfactual question: 'Would the patient
have survived if given drug B instead?' We use the patient's actual health data (abduction) to determine their
specific constitution, then simulate drug B (action), and predict the outcome (prediction). This is the
foundation of personalized medicine and legal reasoning about negligence.
Q4. Explain Bayesian inference. Describe prior, likelihood, and posterior with suitable
illustrations.
Bayesian Inference: From Prior to Posterior
Prior P(H) Likelihood P(D|H) Posterior P(H|D) / P(D)
Initial Belief + How Likely Data = Updated Belief Evidence
Before Data Given Hypothesis After Data (Normalizer)
P(H|D) = P(D|H) * P(H) / P(D)
Example: "Is patient sick?" Prior=10% chance. Positive test (Likelihood=95%). Updated belief (Posterior)=much higher.
But depends on false positive rate! This is why Bayesian reasoning matters in medical diagnosis.
Bayesian Inference: The Framework
Bayesian inference is a principled framework for updating beliefs in light of new evidence. It treats model
parameters as random variables with probability distributions (rather than fixed unknowns), enabling the
quantification of uncertainty in predictions.
Bayes' Theorem: P(H|D) = P(D|H) × P(H) / P(D)
Prior: P(H) — What We Believe Before Seeing Data
The prior distribution encodes our initial belief about the hypothesis/parameters before observing any data. It
can be informative (strong prior knowledge) or non-informative/uniform (no prior preference).
Types: Uniform prior — equal probability for all values (no preference). Gaussian prior — centered on a best
guess with uncertainty. Informative prior — based on domain expertise or previous studies. Conjugate prior —
mathematical convenience (prior and posterior have the same distribution family).
Example: Before testing a coin, your prior belief might be P(fair) = 0.9 and P(biased) = 0.1 — you believe
most coins are fair. If you have no idea, a uniform prior P(fair) = P(biased) = 0.5 says you're equally
uncertain.
Likelihood: P(D|H) — How Well the Hypothesis Explains the Data
The likelihood function measures the probability of observing the data D given that hypothesis H is true. It
connects the model to the observed evidence. The likelihood is NOT the probability of the hypothesis — it's the
probability of the data under the hypothesis.
If the hypothesis is 'the coin is fair' (H: p=0.5) and we observe 8 heads in 10 flips, the likelihood is P(8H in
10|p=0.5) = C(10,8) × 0.5^8 × 0.5^2 = 0.044. If the hypothesis is 'p=0.8', the likelihood is C(10,8) × 0.8^8 ×
0.2^2 = 0.302. The biased coin hypothesis has a higher likelihood given this data.
Posterior: P(H|D) — Updated Belief After Seeing Data
The posterior distribution combines the prior and likelihood, representing our updated belief about the
hypothesis after observing data. As more data is collected, the posterior becomes sharper (more certain) and
is increasingly dominated by the likelihood rather than the prior. With infinite data, the prior becomes irrelevant.
Evidence: P(D) — The Normalizing Constant
P(D) = Σ_H P(D|H)P(H) is the total probability of the data across all hypotheses. It ensures the posterior is a
valid probability distribution (sums to 1). Often intractable to compute exactly — this is why approximate
methods (MCMC, Variational Inference) are used in practice.
Medical diagnosis: Prior P(disease) = 0.01 (1% prevalence). Test has 95% sensitivity and 90% specificity.
Positive test result. Posterior: P(disease|positive) = (0.95 × 0.01) / (0.95 × 0.01 + 0.10 × 0.99) =
0.0095/0.1085 ≈ 0.088 = 8.8%. Despite a positive test, there's only 8.8% chance of disease! This
counter-intuitive result (base rate neglect) is why Bayesian reasoning matters.
Q5. Discuss uncertainty quantification in machine learning and its importance in real-world
applications.
Types of Uncertainty
Aleatoric (Data) Uncertainty: Inherent randomness in the data that cannot be reduced with more data.
Example: A blurry image of a digit — even a human might not be sure if it's a 3 or an 8. This is irreducible
noise. Modeled by predicting a distribution (e.g., outputting mean and variance instead of just a point estimate).
Epistemic (Model) Uncertainty: Uncertainty due to limited knowledge — insufficient training data or model
capacity. This CAN be reduced with more data. Example: When asked to classify an animal the model has
never seen, epistemic uncertainty should be high. Methods: Bayesian neural networks, MC Dropout, Deep
Ensembles.
Methods for Uncertainty Quantification
1. Bayesian Neural Networks (BNNs): Place distributions over weights instead of point estimates.
Predictions involve integrating over all possible weight configurations. Computationally expensive but
principled. Approximated via Variational Inference or MCMC.
2. Monte Carlo Dropout: Keep dropout active at test time and run multiple forward passes. The variance
across predictions estimates uncertainty. Simple to implement — just don't turn off dropout during inference.
Theoretically linked to approximate Bayesian inference.
3. Deep Ensembles: Train M independent models with different random initializations. Prediction = mean of
ensemble; uncertainty = variance across ensemble members. Simple, effective, but M× more expensive to
train and store.
4. Evidential Deep Learning: Output parameters of a higher-order distribution (e.g., Dirichlet distribution for
classification). A single forward pass gives both prediction and uncertainty estimate.
Importance in Real-World Applications
Healthcare: A diagnostic AI must say 'I'm 95% confident this is benign' rather than just 'benign.' When
uncertain, it should defer to a human doctor. Overconfident wrong predictions can be fatal.
Autonomous Driving: The car must know when it's uncertain about a road sign or pedestrian. High
uncertainty → slow down, engage safety systems, or hand control to the human driver.
Finance: Risk assessment requires confidence intervals, not point predictions. A model predicting stock
returns must quantify how certain it is to enable proper portfolio management.
Active Learning: When selecting which data to label next, prioritize samples where the model is most
uncertain — this maximizes information gain per label, reducing annotation cost.
Out-of-Distribution Detection: When input is different from training data (e.g., a self-driving car encounters
an unusual obstacle), the model should flag high uncertainty rather than making a confident but wrong
prediction.
Q6. Explain sequential and temporal learning concepts with examples.
Sequential Learning
Sequential learning deals with data where the order of elements carries meaning. The model must capture
dependencies between past, present, and future elements in a sequence. Unlike tabular data where each
sample is independent, sequential data has inherent temporal or positional structure.
Key architectures: RNNs maintain a hidden state h_t = f(h_{t-1}, x_t) that summarizes all past inputs. LSTMs
add gating mechanisms (forget, input, output gates) to control information flow, solving the vanishing gradient
problem. GRUs simplify LSTMs with two gates (reset, update). Transformers use self-attention to relate all
positions simultaneously — O(1) path length vs O(n) for RNNs.
Examples of sequential data: Natural language text (word order matters), DNA sequences (gene expression
depends on base ordering), music (notes form melodies through temporal patterns), user clickstreams
(browsing patterns reveal intent), stock prices (historical patterns inform predictions).
Temporal Learning
Temporal learning specifically focuses on time-stamped data where the temporal dimension has physical
meaning (hours, days, years). Unlike general sequences, temporal data has: irregular sampling intervals, trend
and seasonality patterns, temporal correlations at multiple scales, and non-stationarity (distribution changes
over time).
Key methods: Time series forecasting (ARIMA, Prophet, temporal CNNs), temporal graph networks (for
evolving graphs), spatiotemporal models (combining spatial and temporal dimensions), and temporal point
processes (for event sequences with irregular timing).
Real-world temporal learning: Weather forecasting (learning atmospheric temporal patterns over days and
seasons), anomaly detection in server logs (detect unusual patterns in system metrics over time), predictive
maintenance (predict equipment failure from sensor readings over weeks), and epidemic modeling (predict
disease spread from temporal case data).
Q7. Describe continual learning and lifelong learning paradigms. Highlight their significance.
The Problem: Static vs. Dynamic World
Traditional ML assumes training data is fixed and complete — the model is trained once and deployed. But the
real world is dynamic: new tasks emerge, data distributions shift, and requirements change. Continual learning
(also called lifelong learning or incremental learning) addresses this by enabling models to learn from a stream
of tasks over time without forgetting previously learned knowledge.
Continual Learning
In continual learning, the model encounters tasks T■, T■, ..., T_n sequentially. At time t, the model trains on
T_t and should perform well on ALL tasks T■ through T_t. The fundamental challenge is that training on T_t
typically destroys knowledge about T■ through T_{t-1} — this is catastrophic forgetting.
Three continual learning scenarios:
Task-Incremental: Task identity is known at test time. Easiest — model just needs to switch to the right 'head'
for each task.
Domain-Incremental: Same task structure but data distribution shifts. The model must adapt without knowing
which domain is active.
Class-Incremental: New classes are added over time. Hardest — model must distinguish all classes seen so
far without task identity.
Lifelong Learning
Lifelong learning extends continual learning with the ability to transfer knowledge forward (use past knowledge
to learn new tasks faster) and backward (improve on old tasks as new related tasks are learned). It aims to
build a growing knowledge base that improves over time, mimicking how humans learn throughout life.
Significance
1. Real-world deployment: Deployed models encounter new data daily — a spam filter must adapt to new
spam types without forgetting old ones. A medical AI must learn from new research without losing previous
diagnostic capabilities.
2. Resource efficiency: Retraining from scratch on all data whenever new tasks arrive is computationally
expensive and requires storing all historical data. Continual learning is more efficient.
3. Edge/IoT deployment: Devices at the edge (phones, sensors, robots) cannot store massive datasets or
retrain completely. They must learn incrementally from local data streams.
4. Personalization: User-facing models must adapt to individual preferences over time. A recommendation
system learns from each user's evolving behavior without forgetting general patterns.
5. Toward AGI: General intelligence requires lifelong learning — acquiring and integrating knowledge across
diverse tasks, building an ever-expanding understanding of the world.
Q8. Analyze catastrophic forgetting in neural networks and discuss methods to overcome it.
Catastrophic Forgetting vs Continual Learning Solutions
Task A Task B Task C Without CL:
(Cats) (Dogs) (Birds)
Task A: 95% -> 40% (FORGOT!)
Task B: 90% -> 55% (FORGOT!)
Task C: 92% (Only this works)
Regularization (EWC): Penalize changing important weights
Replay-Based: Store & replay old task samples
Architecture: Add new neurons per task
What is Catastrophic Forgetting?
Catastrophic forgetting (also called catastrophic interference) is the phenomenon where a neural network,
upon learning new information, abruptly loses previously learned knowledge. When the network's weights are
updated to optimize for a new task, the weight changes interfere with the representations learned for previous
tasks, causing dramatic performance drops.
Analogy: Imagine writing notes on a whiteboard (fixed-capacity neural network). When you need to write
new notes (learn new task), you erase previous notes (overwrite weights) because the board has limited
space. After writing the new notes, the old information is permanently lost. Continual learning methods are
like using a smarter board — sticky notes (replay), priority markers (regularization), or expandable sections
(architecture).
Why it happens: Neural networks use shared, distributed representations. The same weights are responsible
for multiple tasks. Gradient updates for task B modify weights critical for task A. Unlike biological brains that
have complementary learning systems (hippocampus for fast learning, neocortex for consolidated knowledge),
standard neural networks have only one learning system.
Methods to Overcome Catastrophic Forgetting
1. Regularization-Based Methods
Elastic Weight Consolidation (EWC): Identifies weights that are important for previous tasks using the Fisher
Information Matrix, then penalizes changes to these important weights when learning new tasks. Loss = L_new
+ λ Σ_i F_i(θ_i − θ*_i)², where F_i is the Fisher information of parameter i and θ* are the optimal parameters
after the previous task.
Synaptic Intelligence (SI): Tracks each parameter's contribution to reducing loss online (during training),
computing importance in a path-integral fashion. More biologically plausible than EWC and computationally
cheaper.
Learning without Forgetting (LwF): Uses knowledge distillation — when learning a new task, preserve the
outputs of the old task by adding a distillation loss that keeps old task predictions stable.
2. Replay-Based Methods
Experience Replay: Store a small buffer of examples from previous tasks. When training on new tasks, mix in
replayed examples from the buffer. Simple and effective but requires storing actual data (privacy concerns,
storage costs).
Generative Replay: Train a generative model (GAN/VAE) on previous task data. When learning new tasks,
generate pseudo-examples from previous tasks instead of storing real data. Eliminates privacy and storage
concerns but adds model complexity.
Gradient Episodic Memory (GEM): Stores examples and uses them to constrain gradient updates — ensures
new task gradients don't increase loss on stored examples.
3. Architecture-Based Methods
Progressive Neural Networks: Add a new column of network layers for each new task, with lateral
connections to previous columns. Completely prevents forgetting (old columns are frozen) but grows linearly
with tasks.
PackNet: Uses iterative pruning to free up parameters for new tasks while keeping important parameters fixed
for old tasks. Achieves near-zero forgetting within a fixed network capacity.
Dynamic Expandable Networks (DEN): Selectively expand the network by adding neurons only when
needed for new tasks, achieving a balance between capacity and growth.
Q9. Compare regularization-based and replay-based continual learning strategies.
Aspect Regularization-Based Replay-Based
Core idea Penalize changes to important weights Rehearse old task examples while learning
new ones
Key methods EWC, SI, MAS, LwF Experience Replay, GEM, A-GEM,
Generative Replay
Data storage No raw data stored (only importance weights) Stores buffer of old examples (or trains
generator)
Privacy Better — no raw data needed Worse — stores real data (unless generative)
Memory Store importance matrix (same size as model) Store replay buffer (grows with tasks)
overhead
Compute Extra regularization term in loss Extra forward/backward passes on replayed
overhead data
Forgetting Moderate — can still forget when tasks Strong — directly rehearses previous
resistance conflict knowledge
Scalability Good for many tasks (importance matrices Buffer size limits scalability
compress)
Task similarity Works well when tasks share features Works regardless of task similarity
Plasticity May become too rigid (locked weights) Maintains plasticity through rehearsal
Best for Many tasks with shared structure Few tasks with distinct data distributions
Hybrid approaches combine both: use regularization to slow forgetting AND maintain a small replay buffer for
critical examples. Methods like HAL (Hindsight Anchor Learning) and ER-ACE show that combining strategies
outperforms either alone. The field is moving toward such hybrid systems that balance the strengths of both
families.
Q10. Explain incremental and online learning with real-world applications.
Incremental Learning
Incremental learning is a continual learning setting where the model learns from data that arrives in discrete
batches (increments) over time. Each batch may introduce new classes, new data for existing classes, or both.
The model must integrate new knowledge without full retraining on all historical data.
Class-Incremental Learning: New classes are added in each increment. Example: A product recognition
model starts with 100 categories; every month, 20 new products are added. The model must recognize all
products seen so far without retraining from scratch.
Data-Incremental Learning: Same classes but new data samples arrive. The model fine-tunes on new data
while maintaining overall performance.
Online Learning
Online learning processes one sample at a time (or very small batches) as data arrives in a stream. The model
updates immediately after each example and typically cannot revisit past examples. This is the most
constrained and real-time form of learning.
Key algorithms: Online Gradient Descent, Passive-Aggressive algorithms, Online SVM, Stochastic Gradient
Descent (SGD), and bandit algorithms.
Real-World Applications
1. Spam filtering (Online): Email classification must adapt in real-time as new spam tactics emerge. Each
email is processed once, and the filter updates immediately.
2. Recommendation systems (Incremental): Netflix/Spotify add new content weekly. The recommendation
model incrementally learns about new movies/songs without forgetting user preferences for existing content.
3. Autonomous driving (Incremental): Self-driving models must incrementally learn new road scenarios
(construction zones, new traffic signs) without forgetting standard driving behavior.
4. Financial fraud detection (Online): Transaction monitoring systems must adapt to evolving fraud patterns
in real-time while maintaining detection of known fraud types.
5. IoT sensor networks (Online): Edge devices process sensor readings one at a time, updating anomaly
detection models on-the-fly without storing historical readings.
Q11. Discuss applications of causal and continual learning in healthcare or autonomous
systems with a case study.
Case Study: Causal + Continual Learning in Healthcare — Adaptive Treatment Recommendations
Problem Context
Hospitals need AI systems that: recommend treatments based on causal understanding (not just correlations),
adapt to new drugs, guidelines, and patient populations over time, handle distribution shifts (e.g., new disease
variants, demographic changes), and explain recommendations causally ('this treatment works because...').
Phase 1: Causal Learning — Building the Treatment Model
Build a Structural Causal Model for diabetes treatment: Genetics + Lifestyle → Blood Sugar Levels; Blood
Sugar + Comorbidities → Treatment Type; Treatment + Adherence → Health Outcome. Use causal discovery
algorithms on electronic health records to learn the causal graph. Apply do-calculus to estimate causal effects:
P(improved | do(metformin)) vs P(improved | do(insulin)) for different patient profiles.
Counterfactual reasoning enables personalization: 'For this specific patient with their specific comorbidities and
genetics, would insulin have been better than metformin?' This allows retrospective analysis and treatment
plan optimization.
Phase 2: Continual Learning — Adapting Over Time
New challenges emerge over time: new drug classes (GLP-1 receptor agonists), changing patient
demographics (aging population), updated clinical guidelines, new disease variants (treatment-resistant
strains). The model must incrementally learn about new treatments without forgetting knowledge about existing
ones.
Use regularization-based continual learning (EWC) to protect important causal relationships discovered in
Phase 1. When new drugs arrive, expand the causal model with new nodes and edges while keeping
established causal pathways stable. Employ generative replay to synthesize old patient scenarios when
original data cannot be stored (privacy regulations like HIPAA).
Combined Impact
Causal reasoning ensures: Treatments are recommended based on genuine causal effects, not spurious
correlations (e.g., correlation between hospital food choices and recovery is not causal). Confounders
(socioeconomic status, access to care) are properly accounted for. Recommendations are explainable: 'Drug X
is recommended because it causally reduces HbA1c through pathway Y, given your specific comorbidities.'
Continual learning ensures: The system stays current with evolving medical knowledge. New treatments are
integrated without forgetting the efficacy data of established treatments. The system adapts to population
changes without full retraining, reducing computational cost and data requirements. Performance on all
treatments (old and new) is maintained.
2-MARK QUESTIONS — UNIT 2
Q1. Define causation.
Ans: Causation is a directional relationship where one variable (cause) directly produces a change in another
variable (effect). Unlike correlation, causation implies a mechanism of action: intervening on the cause will
change the effect. Formally, X causes Y if P(Y|do(X=x)) ≠ P(Y). Establishing causation requires controlled
experiments or rigorous causal inference using frameworks like SCMs.
Q2. What is correlation?
Ans: Correlation is a statistical measure of how two variables change together, ranging from -1 (perfect
negative) to +1 (perfect positive), with 0 indicating no linear relationship. Correlation is symmetric (corr(X,Y) =
corr(Y,X)) and does NOT imply causation. Two variables can be correlated due to: direct causation, reverse
causation, a common confounder, or pure coincidence.
Q3. What is a Structural Causal Model (SCM)?
Ans: An SCM is a mathematical framework M = (U, V, F, P(U)) for representing causal relationships, where U
= exogenous variables, V = endogenous variables, F = structural equations (V_i = f_i(PA_i, U_i)), and P(U) =
distribution over exogenous variables. The causal graph (DAG) encodes the structure, while structural
equations specify the mechanisms. SCMs support three levels of causal reasoning: association, intervention,
and counterfactuals.
Q4. What is an intervention?
Ans: An intervention is the act of externally setting a variable to a specific value, overriding its natural causal
mechanism. Represented by Pearl's do-operator: do(X=x). Graphically, it means cutting all incoming edges to
X and setting X=x. P(Y|do(X=x)) asks 'what happens to Y when we force X=x?' — distinct from P(Y|X=x)
which is mere observation. Interventions enable estimating causal effects from observational data.
Q5. Define counterfactual reasoning.
Ans: Counterfactual reasoning asks 'what would have happened if circumstances had been different?' —
reasoning about alternative scenarios that didn't occur. Formally, Y_x(u) asks 'for unit u, what would Y be if X
were x?' Process: (1) Abduction — determine exogenous variables from evidence, (2) Action — modify the
SCM with do(X=x), (3) Prediction — compute Y. Example: 'Would the patient have survived with a different
treatment?'
Q6. What is Bayesian inference?
Ans: Bayesian inference is a framework for updating beliefs about hypotheses given new evidence, using
Bayes' theorem: P(H|D) = P(D|H)·P(H)/P(D). It combines prior belief P(H) with data likelihood P(D|H) to
produce a posterior distribution P(H|D). Key properties: quantifies uncertainty, incorporates prior knowledge,
and updates coherently as more data arrives.
Q7. Define prior probability.
Ans: Prior probability P(H) represents our belief about a hypothesis before observing any data. It encodes
domain knowledge, previous experience, or assumptions. Types include: informative priors (strong belief
based on expertise), non-informative/uniform priors (minimal assumptions), and conjugate priors
(mathematically convenient, same family as posterior). The prior is updated to the posterior as data is
observed.
Q8. What is posterior probability?
Ans: Posterior probability P(H|D) is the updated belief about a hypothesis after incorporating observed data,
computed via Bayes' theorem. It combines the prior P(H) and likelihood P(D|H), normalized by evidence P(D).
The posterior represents our current best understanding given all available information. With more data, the
posterior concentrates around the true value (posterior consistency).
Q9. What is likelihood?
Ans: Likelihood P(D|H) measures how probable the observed data D is under a specific hypothesis H. It is
NOT the probability of H being true — it's the probability of seeing the data if H were true. The likelihood
function connects the model to observations. Maximum Likelihood Estimation (MLE) finds parameters that
maximize this function. In Bayesian inference, likelihood mediates between prior and posterior.
Q10. Define uncertainty in ML.
Ans: Uncertainty in ML refers to the model's lack of confidence in its predictions. Two types: Aleatoric (data
noise — irreducible, e.g., noisy sensor readings) and Epistemic (model ignorance — reducible with more
data, e.g., predictions on out-of-distribution inputs). Quantifying uncertainty is critical for safety-critical
applications. Methods include Bayesian NNs, MC Dropout, and deep ensembles.
Q11. What is continual learning?
Ans: Continual learning (also lifelong learning) is the ability of a model to learn from a sequence of tasks T■,
T■, ..., T_n over time while retaining knowledge of all previously learned tasks. The main challenge is
catastrophic forgetting — learning new tasks destroys old knowledge. Three scenarios: task-incremental (task
ID known), domain-incremental (same task, shifting domain), class-incremental (new classes added).
Q12. Define catastrophic forgetting.
Ans: Catastrophic forgetting is the phenomenon where a neural network abruptly and severely loses
previously learned knowledge when trained on new tasks. It occurs because weight updates for the new task
overwrite representations critical for old tasks. Unlike human gradual forgetting, it is sudden and complete.
Solutions include regularization (EWC), replay (experience replay), and architecture expansion (progressive
networks).
Q13. What is incremental learning?
Ans: Incremental learning is a form of continual learning where data arrives in discrete batches (increments)
over time, and each batch may introduce new classes or new samples. The model integrates new knowledge
without retraining from scratch on all data. Class-incremental learning (adding new categories) is the most
challenging variant, as the model must distinguish all classes seen so far.
Q14. What is online learning?
Ans: Online learning processes data one sample at a time as it arrives in a stream, updating the model
immediately after each observation. The model cannot revisit past examples. Key properties: real-time
adaptation, low memory requirement, no batch storage. Algorithms include online SGD, Passive-Aggressive
classifiers, and multi-armed bandits. Used in real-time applications: spam filtering, stock trading, ad click
prediction.
Q15. What is replay-based learning?
Ans: Replay-based learning is a continual learning strategy that stores a buffer of examples from previous
tasks and interleaves them with current task data during training. This rehearsal prevents forgetting by
periodically refreshing the model's memory of old tasks. Variants include: experience replay (store real
examples), generative replay (use a GAN/VAE to generate pseudo-examples), and gradient episodic memory
(constrain gradients using stored examples).
NUMERICAL PROBLEMS — UNIT 2
Q16. If P(A)=0.5 and P(B|A)=0.8, find P(A∩B).
Given: P(A) = 0.5, P(B|A) = 0.8
Formula: P(A∩B) = P(A) × P(B|A) (Multiplication rule of probability)
Solution: P(A∩B) = 0.5 × 0.8 = 0.4
Interpretation: The joint probability of both A and B occurring is 40%.
Q17. If prior = 0.3 and likelihood = 0.6, compute unnormalized posterior.
Given: Prior P(H) = 0.3, Likelihood P(D|H) = 0.6
Formula: Unnormalized posterior = Prior × Likelihood = P(D|H) × P(H)
Solution: Unnormalized posterior = 0.3 × 0.6 = 0.18
Note: To get the actual posterior P(H|D), divide by the evidence P(D) = Σ
P(D|H_i)P(H_i).
Q18. If P(A)=0.4, P(B)=0.5, and P(A∩B)=0.2, check independence.
Given: P(A) = 0.4, P(B) = 0.5, P(A∩B) = 0.2
Independence condition: A and B are independent iff P(A∩B) = P(A) × P(B)
Check: P(A) × P(B) = 0.4 × 0.5 = 0.2
P(A∩B) = 0.2 = P(A) × P(B) = 0.2 ✓
Conclusion: A and B are INDEPENDENT.
Q19. If model accuracy drops from 90% to 70% after new task, compute % drop.
Given: Original accuracy = 90%, After new task = 70%
Formula: % drop = (Original - New) / Original × 100
Solution: % drop = (90 - 70) / 90 × 100 = 20/90 × 100 = 22.22%
This quantifies catastrophic forgetting — the model lost 22.22% of its old task
performance.
Q20. If 100 samples are replayed out of 1000, find replay ratio.
Given: Replayed samples = 100, Total samples = 1000
Formula: Replay ratio = Replayed / Total
Solution: Replay ratio = 100 / 1000 = 0.1 (or 10%)
This means 10% of training data comes from the replay buffer. Typical ratios
range from 5-50% depending on buffer size constraints.
UNIT 3: Federated, Generative & Trustworthy ML
16-MARK QUESTIONS
Q1. Explain federated learning architecture and communication workflow between client and
server.
Federated Learning: Overview
Federated Learning (FL), proposed by McMahan et al. (2017) at Google, is a distributed machine learning
paradigm where the model is trained across multiple decentralized devices (clients) that hold local data,
without ever transferring raw data to a central server. The key principle is: 'bring the model to the data, not the
data to the model.'
Federated Learning: Communication Workflow
Global Server 4. FedAvg: w_global = SUM(n_k/n * w_k)
(Aggregator)
1. Distribute 3. Send model
global model updates only
Client 1 Client 2 Client 3 Client 4
(Hospital A) (Hospital B) (Hospital C) (Hospital D)
2. Train locally 2. Train locally 2. Train locally 2. Train locally
KEY: Raw data NEVER leaves the client. Only model parameters/gradients are shared.
Privacy preserved via Differential Privacy, Secure Aggregation, Homomorphic Encryption
Architecture Components
Central Server (Aggregator): Maintains the global model. Coordinates training rounds. Aggregates updates
from clients. Does NOT have access to any client's raw data. Distributes the updated global model to clients.
Clients (Edge Devices): Each holds a local dataset (e.g., Hospital A has its patient records). Trains the model
locally on its own data. Sends only model updates (parameters/gradients) to the server. Examples:
smartphones (Google Keyboard), hospitals, banks, IoT devices.
Communication Workflow — FedAvg Algorithm
Round t of Federated Learning:
Step 1 — Server broadcasts global model: The server sends the current global model weights w_t to a
randomly selected subset of K clients (typically 10-100 out of millions). Not all clients participate in every round
— this handles client availability issues.
Step 2 — Local training: Each selected client k initializes its local model with w_t, then trains on its local
dataset D_k for E local epochs using SGD. This produces updated local weights w_k^{t+1}. Each client
performs independent training — no communication between clients.
Step 3 — Clients send updates: Each client sends its updated model ∆w_k = w_k^{t+1} − w_t (or the full
weights) back to the server. Only model parameters are transmitted, not raw data.
Step 4 — Server aggregates: The server combines all client updates using Federated Averaging (FedAvg):
w_{t+1} = SUM_{k=1}^{K} (n_k / n) * w_k^{t+1}
where n_k is the number of data points at client k, and n = Σn_k is the total. Clients with more data have
proportionally more influence.
Step 5 — Repeat: Steps 1-4 are repeated for many communication rounds until convergence.
Google's practical deployment: Federated Learning powers the next-word prediction in Gboard (Google
Keyboard). Each phone trains locally on the user's typing patterns, sends model updates to Google's server,
which aggregates improvements from millions of phones — all without Google ever seeing what any individual
user typed.
Q2. Discuss privacy-preserving mechanisms in federated learning and their importance.
Why Additional Privacy is Needed Beyond FL
While FL's core design prevents raw data sharing, model updates (gradients/weights) can still leak information.
Research has shown that gradient inversion attacks can reconstruct training images from shared gradients
with high fidelity. Therefore, additional privacy mechanisms are essential.
1. Differential Privacy (DP)
Adds calibrated noise to model updates before sharing, providing mathematical privacy guarantees. (ε,
δ)-differential privacy ensures that any single data point's contribution is bounded by ε.
Local DP: Each client adds noise before sending updates. Stronger privacy but lower utility.
Global DP: Server adds noise after aggregation. Better utility but requires trusted server.
Noisy update = clip(gradient, C) + N(0, sigma^2 * C^2 * I)
Trade-off: More noise → better privacy → lower model accuracy. The privacy budget ε controls this balance.
2. Secure Aggregation
Cryptographic protocol ensuring the server can compute the aggregate of client updates WITHOUT seeing any
individual client's update. Achieved via secret sharing or homomorphic encryption. The server learns only the
sum, not individual contributions.
In Secure Aggregation, each client's update is split into encrypted shares distributed among other clients. The
server can reconstruct only the aggregate. Even if the server is compromised, individual client updates remain
hidden.
3. Homomorphic Encryption (HE)
Allows computation on encrypted data without decryption. Clients encrypt their updates; the server aggregates
encrypted updates; the result, when decrypted, equals the aggregation of plaintext updates.
Enc(a) + Enc(b) = Enc(a + b) -- Additive homomorphism
Fully Homomorphic Encryption (FHE) supports arbitrary computations but is currently too slow for most
practical FL deployments. Partially homomorphic (addition only) is more feasible.
4. Trusted Execution Environments (TEE)
Hardware-based security enclaves (Intel SGX, ARM TrustZone) that provide isolated, tamper-resistant
execution environments. Model aggregation happens inside the enclave where even the server operator
cannot inspect the data.
Importance
Privacy preservation in FL is critical because: (1) Legal compliance — GDPR, HIPAA, CCPA mandate data
protection, (2) User trust — users won't participate if their data might leak, (3) Competitive sensitivity —
companies won't share model updates if competitors could extract trade secrets, (4) Ethical obligation —
medical, financial, and personal data deserve robust protection.
Q3. Analyze challenges in federated learning such as communication efficiency and client
heterogeneity.
1. Communication Efficiency
Communication is the primary bottleneck in FL. Each round requires transmitting full model parameters
between server and clients. Modern models have millions to billions of parameters — transmitting these over
mobile networks or slow connections is expensive.
Solutions: Gradient compression (top-k sparsification, random sparsification), Gradient quantization (reduce
precision of updates from FP32 to INT8), Federated distillation (share knowledge, not model parameters),
Increase local epochs E (more local computation, fewer communication rounds), Model pruning (transmit only
non-zero weights).
2. Client Heterogeneity
Statistical heterogeneity (Non-IID data): Each client's data distribution is different. A phone in Japan has
Japanese text; one in France has French. This non-IID (non-independent and identically distributed) nature
causes client models to diverge, slowing convergence and harming global model quality.
System heterogeneity: Clients have different hardware capabilities (CPU, memory, battery), network speeds,
and availability patterns. Some clients are fast (powerful servers) while others are slow (old smartphones). The
system must handle stragglers without wasting faster clients' results.
Solutions for non-IID: FedProx — adds a proximal term to keep local models close to global: L_local + µ/2 ||w
- w_global||². SCAFFOLD — uses control variates to correct client drift. Personalized FL — allow client-specific
adaptations via local fine-tuning or mixture of global and local models.
3. Other Challenges
Client selection/participation: Not all clients are available every round. Selection bias can skew the model.
Random selection and importance sampling help.
Byzantine robustness: Malicious or faulty clients may send corrupted updates (Byzantine attacks, model
poisoning). Robust aggregation methods (Krum, trimmed mean, median) replace simple averaging to filter out
malicious updates.
Fairness: The global model may perform well on average but poorly for clients with underrepresented data
distributions. Fair FL aims for equitable performance across all clients.
Model heterogeneity: Different clients may need different model architectures (edge devices vs servers).
Heterogeneous FL allows each client to run a different model while still collaborating.
Q4. Explain model compression techniques: pruning, quantization, and knowledge distillation.
Model Compression Techniques
Pruning Quantization Knowledge
Distillation
• Remove unimportant • Reduce precision
• weights (set to 0) • FP32 -> INT8/INT4 • Teacher -> Student
• Structured/Unstructured • 2-4x size reduction • Large model teaches
• 40-90% sparsity • Minimal accuracy loss • small model via soft
• labels (temperature)
Goal: Deploy ML on edge devices (phones, IoT) with limited memory/compute
Why Model Compression?
State-of-the-art models (GPT-4, Vision Transformers) have billions of parameters, requiring enormous memory
and compute. Deploying these on edge devices (smartphones, IoT, embedded systems) with limited resources
requires compression — reducing model size and computational cost while preserving as much accuracy as
possible.
1. Pruning
Pruning removes unimportant weights (connections) from the network, creating a sparser model. Research
shows that large networks are typically over-parameterized — 90%+ of weights can be removed with minimal
accuracy loss.
Unstructured pruning: Remove individual weights (set to zero) based on magnitude — small weights
contribute little. Results in irregular sparsity patterns, requiring sparse matrix hardware for speedup.
Structured pruning: Remove entire neurons, channels, or layers. More hardware-friendly (regular dense
operations on a smaller model) but coarser granularity means potentially more accuracy loss.
Process: (1) Train the full model, (2) Compute importance scores (magnitude, gradient-based, or Fisher
information), (3) Remove least important weights, (4) Fine-tune the pruned model to recover accuracy. Iterative
magnitude pruning repeats steps 2-4 progressively.
The Lottery Ticket Hypothesis (Frankle & Carlin, 2019): Within a randomly initialized network, there exists a
sparse subnetwork (a 'winning ticket') that, when trained in isolation with the same initialization, matches the
full network's accuracy. This suggests we can find 90% smaller networks without any loss.
2. Quantization
Quantization reduces the numerical precision of model weights and activations — replacing 32-bit floating point
(FP32) with lower-bit representations like INT8, INT4, or even binary (1-bit).
Post-Training Quantization (PTQ): Quantize a pre-trained FP32 model without retraining. Simple calibration
step using a small dataset. Quick but may lose more accuracy.
Quantization-Aware Training (QAT): Simulate quantization during training, allowing the model to adapt. Uses
straight-through estimators for the non-differentiable rounding. Better accuracy retention but requires training.
Benefits: FP32 → INT8: 4× memory reduction, 2-4× inference speedup. FP32 → INT4: 8× memory reduction.
Hardware support: NVIDIA GPUs, mobile NPUs natively accelerate INT8 operations.
Quantization: q = round(x / scale) + zero_point, where scale = (max-min) /
(2^bits - 1)
3. Knowledge Distillation
Knowledge distillation transfers knowledge from a large, accurate 'teacher' model to a smaller, deployable
'student' model. The student learns to mimic the teacher's behavior — specifically, its soft probability outputs
(soft labels) rather than just the hard labels.
Why soft labels? Hard labels say 'this is a cat' (1.0 for cat, 0.0 for everything else). Soft labels say 'this is 90%
cat, 5% tiger, 3% dog, ...' — revealing inter-class similarities that the student can learn from. A horse is more
similar to a zebra than to an airplane — soft labels encode this.
Student loss = alpha * CrossEntropy(student, hard_labels) + (1-alpha) *
KL_div(student_soft, teacher_soft)
Temperature T controls softness: softmax(z_i/T). Higher T → softer probability distribution → more inter-class
information. Typically T = 3-20 during distillation, T = 1 at deployment.
Q5. Describe Variational Autoencoders (VAE). Explain their architecture and working.
Variational Autoencoder (VAE) Architecture
mu
Encoder z = mu + Decoder
Input x x'
q(z|x) sigma * eps p(x|z)
(Image) (Reparam.) Out
(Neural Net) (Neural Net)
sigma
Loss = Reconstruction Loss (x vs x') + KL Divergence (q(z|x) || p(z))
Reconstruction: forces accurate output. KL: forces latent space to be smooth Gaussian.
Reparameterization trick enables backpropagation through stochastic sampling.
VAE: Generative Model with Principled Latent Space
A Variational Autoencoder is a generative model that learns to encode data into a structured latent space and
decode from it. Unlike standard autoencoders that learn deterministic encodings, VAEs learn a probability
distribution over the latent space, enabling sampling and generation of new data.
Architecture — Detailed
Encoder q_φ(z|x): Takes input x and outputs parameters of a latent distribution — specifically, a mean vector
µ and a log-variance vector log(σ²). The encoder is a neural network (CNN for images, MLP for tabular)
parameterized by φ.
Latent Space: The latent vector z is sampled from N(µ, σ²I). Each dimension of z captures a factor of variation
in the data. The latent space is forced to be smooth and structured (close to standard Gaussian) by the KL
divergence term.
Reparameterization Trick: Sampling z ~ N(µ, σ²) is not differentiable. The trick: z = µ + σ ■ ε, where ε ~ N(0,
I). This moves the stochasticity to ε, making z a deterministic function of µ, σ, and ε — enabling
backpropagation through the sampling operation.
Decoder p_θ(x|z): Takes latent vector z and reconstructs the input x. For images, outputs pixel-level
probabilities. Parameterized by θ.
Loss Function — Evidence Lower Bound (ELBO)
L(theta, phi; x) = E_q[log p_theta(x|z)] - KL(q_phi(z|x) || p(z))
Reconstruction loss E_q[log p_θ(x|z)]: Ensures the decoder can accurately reconstruct the input. Typically
MSE for continuous data or binary cross-entropy for images. Forces the latent space to retain information
about x.
KL divergence KL(q_φ(z|x) || p(z)): Regularizes the latent space to be close to the prior p(z) = N(0, I). Ensures
smooth interpolation — nearby points in latent space decode to similar outputs. Prevents the model from
memorizing training data. Has closed-form solution for Gaussian distributions.
Generation Process
Once trained, new data is generated by: (1) Sample z ~ N(0, I) from the prior, (2) Pass z through the decoder:
x_new = decoder(z). Interpolation between two images: encode both to get z■ and z■, interpolate z_mid =
α·z■ + (1-α)·z■, decode z_mid to get a smooth morphing between the images.
Limitations and Variants
Blurry outputs: The pixel-level reconstruction loss (MSE) tends to produce blurry images because it averages
over possible outputs. β-VAE, VQ-VAE, and VAE-GAN address this.
Posterior collapse: The decoder may learn to ignore z, relying only on its own capacity. Solutions: KL
annealing (gradually increase KL weight), free bits (minimum KL per dimension).
Q6. Explain Generative Adversarial Networks (GANs). Discuss generator and discriminator
roles.
Generative Adversarial Network (GAN) Architecture
Real
Image
Random Generator G Discriminator D
Fake
Noise z (Creates fake (Classifies R/F
Image
~N(0,1) images) Real vs Fake)
G tries to fool D (minimize D's accuracy)
D tries to catch fakes (maximize accuracy)
min_G max_D V(D,G) = E[log D(x)] + E[log(1-D(G(z)))]
GAN: A Two-Player Game
Generative Adversarial Networks, proposed by Goodfellow et al. (2014), frame generative modeling as a
minimax game between two neural networks — a Generator (G) and a Discriminator (D) — that compete
against each other, driving both to improve.
Analogy: The Generator is a counterfeiter trying to produce fake currency. The Discriminator is a detective
trying to distinguish real bills from fakes. As the detective gets better at catching fakes, the counterfeiter
must improve quality. As the counterfeiter improves, the detective must sharpen their skills. Over time, the
counterfeiter produces perfect replicas that even the best detective cannot distinguish.
Generator (G)
Input: Random noise vector z sampled from a simple distribution (usually z ~ N(0, I) or z ~ Uniform[-1, 1]).
Output: A synthetic data sample G(z) — e.g., a fake image that should look realistic.
Architecture: Typically a deconvolutional neural network (transposed convolutions) that progressively
upsamples from the low-dimensional noise to the high-dimensional data space (e.g., 100-d noise → 64×64×3
image).
Objective: Maximize the probability that the discriminator classifies G(z) as real. In other words, fool D as
much as possible. Loss: L_G = -E[log D(G(z))] — G wants D(G(z)) to be close to 1 (classified as real).
Discriminator (D)
Input: Either a real sample x from the training data OR a fake sample G(z) from the generator.
Output: A probability D(x) ∈ [0, 1] indicating how likely the input is to be real (1 = definitely real, 0 = definitely
fake).
Architecture: A standard CNN classifier that processes the image and outputs a scalar probability.
Objective: Correctly classify both real and fake inputs. L_D = -E[log D(x)] - E[log(1 - D(G(z)))] — D wants D(x)
close to 1 for real and D(G(z)) close to 0 for fake.
Training Dynamics
min_G max_D V(D,G) = E_x[log D(x)] + E_z[log(1 - D(G(z)))]
Training alternates between: (1) Fix G, train D for k steps on a batch of real + fake samples, (2) Fix D, train G
for 1 step to fool the updated D. At equilibrium (Nash equilibrium), G produces perfect samples
(indistinguishable from real), and D outputs 0.5 for everything (cannot tell the difference).
Challenges and Solutions
Mode collapse: G learns to produce only a few types of outputs instead of the full diversity. Solutions:
Wasserstein GAN (WGAN), spectral normalization, mini-batch discrimination.
Training instability: The adversarial game can oscillate without converging. Solutions: Two timescale update
(different learning rates for G and D), gradient penalty, progressive growing.
Evaluation: GAN outputs are hard to evaluate objectively. Metrics include Fréchet Inception Distance (FID)
and Inception Score (IS).
Q7. Compare GANs and diffusion models with respect to working and applications.
Diffusion Models: Forward & Reverse Process
FORWARD PROCESS: Gradually add Gaussian noise (fixed, no learning)
Clean Slightly More Very Pure
Image x_0 Noisy x_t Noisy Noisy Noise x_T
REVERSE PROCESS: Learn to denoise step by step (neural network)
Neural net predicts noise at each step. Trained with simple MSE loss: ||eps - eps_theta(x_t, t)||^2
More stable training than GANs, better diversity, but slower generation (many denoising steps)
How They Work: Fundamentally Different Approaches
GANs: Learn to generate data in a single forward pass through the generator, guided by adversarial training
against a discriminator. Generation is implicit — G directly maps noise to data. No explicit density estimation.
Diffusion Models: Learn to reverse a gradual noise-adding process. Forward process systematically adds
Gaussian noise to data over T steps until it becomes pure noise. Reverse process: a neural network learns to
denoise step-by-step, starting from pure noise and iteratively cleaning it to produce a sample. Generation
requires T forward passes (typically T = 1000).
Aspect GANs Diffusion Models
Generation Single forward pass (fast) Iterative denoising over T steps (slow)
process
Training Adversarial (minimax game) Simple MSE loss on predicted noise
Training stability Notoriously unstable (mode collapse, Very stable (standard regression loss)
divergence)
Sample quality High quality but less diverse State-of-the-art quality AND diversity
Mode coverage Prone to mode collapse Excellent — covers full distribution
Generation Fast (one forward pass) Slow (hundreds-thousands of steps)
speed
Likelihood No (implicit model) Yes (variational bound)
estimation
Controllability Limited (conditional GAN, StyleGAN) Excellent (classifier-free guidance,
inpainting)
Applications Image synthesis, style transfer, Text-to-image (DALL-E 2, Stable Diffusion),
super-resolution video, audio
Key examples StyleGAN, CycleGAN, Pix2Pix DDPM, Stable Diffusion, DALL-E 2, Sora
Current trend: Diffusion models have largely supplanted GANs for high-quality image generation. DALL-E 2,
Midjourney, and Stable Diffusion all use diffusion models. However, GANs remain useful for real-time
applications (due to speed) and specific tasks like style transfer. Distilled diffusion models (Consistency
Models) aim to combine diffusion quality with GAN speed.
Q8. Explain Explainable AI (XAI). Discuss LIME and SHAP techniques.
Why Explainability Matters
As ML models become more complex (deep learning, ensemble methods), they become 'black boxes' —
accurate but opaque. XAI provides methods to make model decisions understandable to humans. This is
critical for: regulatory compliance (GDPR's 'right to explanation'), building trust in high-stakes decisions
(healthcare, criminal justice, finance), debugging and improving models, and scientific discovery
(understanding what the model learned).
Explainable AI: LIME vs SHAP
LIME (Local Interpretable Model-agnostic) SHAP (SHapley Additive exPlanations)
1. Take instance to explain 1. Based on Shapley values (game theory)
2. Perturb around instance 2. Fair attribution of each feature
3. Get black-box predictions 3. Consider ALL feature coalitions
4. Fit simple linear model locally 4. Compute marginal contribution
x
5. Linear coefficients = importance 5. Sum of SHAP values = prediction
Age
Income
LIME: Fast, local, approximate. SHAP: Theoretically grounded, global+local. Debt
Model-agnostic, easy to understand. Consistent, additive. Slower but precise.
History
LIME — Local Interpretable Model-agnostic Explanations
LIME, proposed by Ribeiro et al. (2016), explains individual predictions of ANY black-box model by
approximating it locally with an interpretable model (linear regression).
Algorithm:
1. Select instance: Choose the prediction you want to explain (e.g., 'why was this email classified as spam?').
2. Perturb: Create many slightly modified versions of the input. For text: randomly remove words. For images:
randomly turn off superpixels. For tabular: sample nearby values.
3. Get predictions: Feed all perturbed samples through the black-box model to get their predictions.
4. Weight by proximity: Assign higher weights to perturbations closer to the original input (using an
exponential kernel).
5. Fit interpretable model: Train a weighted linear model on the perturbed samples. The linear coefficients
directly indicate which features pushed the prediction toward or away from the predicted class.
LIME for spam detection: Explain why an email was classified as spam. LIME creates versions with different
words removed, checks if the model still says spam, and discovers that the words 'free', 'winner', and 'click'
are most important for the spam classification.
SHAP — SHapley Additive exPlanations
SHAP, proposed by Lundberg & Lee (2017), uses Shapley values from cooperative game theory to provide a
unified framework for feature importance. Shapley values are the ONLY attribution method satisfying all
desirable fairness properties.
Core concept — Shapley values: In game theory, the Shapley value of a player is their average marginal
contribution across all possible coalitions (subsets) of players. In ML, 'players' are features, and the 'game' is
the prediction. The Shapley value of feature i represents its fair contribution to the prediction, averaged over all
possible combinations of other features.
phi_i = SUM_{S subset of F\{i}} |S|!(|F|-|S|-1)! / |F|! * [f(S U {i}) - f(S)]
SHAP properties (axioms):
• Efficiency: Sum of all SHAP values = model output − expected output (f(x) − E[f(x)]). Explanations are
complete.
• Symmetry: Features contributing equally get equal values. No arbitrary differences.
• Null player: Features that don't influence the output get SHAP value = 0.
• Additivity: For combined models, SHAP values can be added.
Variants: KernelSHAP (model-agnostic, approximate), TreeSHAP (exact for tree models, very fast),
DeepSHAP (for neural networks, using DeepLIFT as backbone), GradientSHAP (combines integrated
gradients with SHAP).
LIME vs SHAP
Aspect LIME SHAP
Theory Ad-hoc local approximation Grounded in game theory (Shapley values)
Consistency No theoretical guarantees Uniquely satisfies fairness axioms
Scope Local explanations only Local AND global explanations
Speed Fast (few perturbations needed) Slow for KernelSHAP, fast for TreeSHAP
Determinism Stochastic (different runs → different results) Deterministic (same result every time)
Completeness Approximate Exact decomposition of prediction
Q9. Analyze fairness, bias, and robustness in machine learning systems.
Bias in ML Systems
Bias can enter ML systems at every stage of the pipeline:
Data bias: Training data reflects historical inequalities. Amazon's hiring tool penalized women because
training data reflected a decade of male-dominated hiring. Facial recognition datasets underrepresented
darker-skinned faces, causing higher error rates.
Algorithm bias: Model architecture or objective function may amplify certain patterns. Optimizing for overall
accuracy can sacrifice minority group performance. Proxy features (zip code as proxy for race) encode bias
even without protected attributes.
Deployment bias: Using a model in a context different from its training data (urban-trained model deployed in
rural areas).
Fairness Definitions and Metrics
Demographic parity: P(■=1|A=0) = P(■=1|A=1) — positive prediction rate should be equal across groups
(protected attribute A). Ignores merit but ensures equal representation.
Equalized odds: P(■=1|Y=y, A=0) = P(■=1|Y=y, A=1) for y∈{0,1} — true positive rate AND false positive rate
should be equal across groups. Balances fairness with accuracy.
Calibration: P(Y=1|■=p, A=0) = P(Y=1|■=p, A=1) = p — among all instances predicted with confidence p, the
actual positive rate should be p, regardless of group.
Impossibility theorem: Except in trivial cases, demographic parity, equalized odds, and calibration cannot all
be satisfied simultaneously. Practitioners must choose which fairness criteria matter most for their application.
Robustness
Robustness is the model's ability to maintain performance under adversarial or distributional perturbations:
Adversarial robustness: Resistance to adversarial examples — imperceptible perturbations that fool the
model. Adding small noise ε to an image of a panda makes the model classify it as a gibbon with 99%
confidence. Defense: adversarial training, certified defenses, input preprocessing.
Distribution shift robustness: Performance on data different from the training distribution. A model trained on
clear weather images should still work in fog, rain, or snow. Defense: domain generalization, data
augmentation, robust optimization.
Corruptions robustness: Handling common corruptions like noise, blur, compression artifacts, lighting
changes. ImageNet-C benchmark measures this systematically.
Mitigation Strategies
Pre-processing: Rebalance training data, remove or transform biased features, create synthetic minority
examples (SMOTE). In-processing: Add fairness constraints to the loss function, adversarial debiasing (train
the model to be accurate while simultaneously training an adversary that cannot predict the protected attribute
from the model's representations). Post-processing: Adjust decision thresholds per group to equalize metrics,
calibrate outputs separately for different groups.
Q10. Discuss ethical considerations in AI and the importance of responsible AI systems.
Core Ethical Principles
1. Fairness and Non-Discrimination: AI systems should not perpetuate or amplify existing societal biases.
Decisions about employment, credit, healthcare, and criminal justice must not discriminate based on protected
characteristics. Regular auditing and bias testing are essential.
2. Transparency and Explainability: Users should understand how and why AI makes decisions that affect
them. GDPR's Article 22 grants individuals the right not to be subject to decisions based solely on automated
processing without explanation. XAI techniques (LIME, SHAP) enable this.
3. Privacy and Data Protection: AI systems must respect user privacy. Data minimization — collect only
what's necessary. Federated learning, differential privacy, and anonymization help protect personal data.
Consent must be informed and meaningful.
4. Accountability and Liability: When AI causes harm, there must be clear lines of responsibility.
Human-in-the-loop systems keep humans accountable. Audit trails document AI decision processes.
Organizations deploying AI should accept liability for its outcomes.
5. Safety and Reliability: AI in safety-critical applications (autonomous vehicles, medical diagnosis, financial
systems) must be thoroughly tested. Uncertainty quantification helps identify when the AI should defer to
humans. Fail-safe mechanisms prevent catastrophic outcomes.
6. Beneficence and Human Welfare: AI should be developed and deployed to benefit humanity. Avoid
weaponization and surveillance applications that harm human rights. Consider long-term societal impacts,
including job displacement and economic inequality.
Responsible AI in Practice
AI Ethics Boards: Organizations should establish ethics review processes for AI projects, similar to IRBs for
human research. Google, Microsoft, and the EU all have AI ethics guidelines.
Algorithmic Impact Assessments: Before deploying AI systems that affect people's lives, conduct
assessments evaluating potential harms, biases, and mitigation measures.
Inclusive Development: Diverse teams build better AI. Including perspectives from affected communities,
ethicists, social scientists, and domain experts alongside engineers.
Regulation: The EU AI Act (2024) classifies AI systems by risk level and imposes requirements accordingly.
High-risk systems (healthcare, law enforcement) face strict transparency, testing, and documentation
requirements.
Q11. Explain a case study on Explainable AI for financial risk assessment or decision support
systems.
Case Study: XAI for Credit Scoring at a Retail Bank
Problem
A retail bank uses a gradient-boosted tree model (XGBoost) for credit scoring — predicting the probability that
a loan applicant will default. The model uses 50+ features and achieves 92% AUC. However: (a) Regulators
(per ECOA and GDPR) require the bank to explain loan rejections, (b) Loan officers don't trust the opaque
model, (c) Rejected applicants have the right to know why and how to improve, (d) The bank suspects the
model may have racial bias through proxy variables.
XAI Solution Implementation
Step 1 — Global Explanation with SHAP: Compute SHAP values for all applicants in the test set. Create
global feature importance rankings: Debt-to-Income ratio (most important), Payment history, Length of credit
history, Number of recent inquiries, Employment duration. SHAP summary plots reveal that high
debt-to-income ratios consistently push predictions toward default, while long credit histories push toward
approval.
Step 2 — Local Explanation for Individual Rejections: For applicant John Doe (rejected), SHAP waterfall
plot shows: Debt-to-income ratio = 0.65 (+0.25 toward default), Recent missed payment (+0.15), Short credit
history of 2 years (+0.10), Stable employment (-0.08 toward approval), Zero recent inquiries (-0.05).
Explanation generated: 'Your application was declined primarily due to a high debt-to-income ratio (65%) and a
recent missed payment, combined with a relatively short credit history (2 years). Reducing your monthly debt
obligations and maintaining consistent payment history would improve future applications.'
Step 3 — Bias Audit with SHAP: Analyze SHAP values stratified by demographic groups. Found that 'zip
code' had a high SHAP value and correlated strongly with race — acting as a proxy. Interaction analysis
revealed zip code × income interactions that disproportionately penalized minority applicants. Action:
Removed zip code as a feature. Retrained model with fairness constraints (equalized odds). Accuracy dropped
marginally (92% → 91.3% AUC) but demographic parity improved by 40%.
Step 4 — Loan Officer Decision Support: Built a dashboard showing: Model's risk score with confidence
interval, top 5 SHAP-based reasons for the recommendation, comparison to similar approved/rejected
applicants (counterfactual explanations), and override capability with documentation requirement. Loan officer
adoption increased from 45% to 89% after XAI implementation — officers reported feeling 'in control' rather
than 'replaced.'
Impact
Regulatory compliance achieved — all rejection reasons are documented and auditable. Customer satisfaction
improved — rejected applicants receive actionable feedback. Bias reduced — proxy discrimination identified
and mitigated. Loan officer trust increased — dashboard with explanations enables informed human oversight.
Default rate decreased 3% — officers caught edge cases the model missed, using XAI insights to make better
final decisions.
2-MARK QUESTIONS — UNIT 3
Q1. Define federated learning.
Ans: Federated learning is a distributed machine learning paradigm where multiple clients (devices)
collaboratively train a shared model without transferring their raw data to a central server. Each client trains
locally on its own data and only shares model updates (gradients/weights) with the server, which aggregates
them. This preserves data privacy while enabling learning from decentralized data sources.
Q2. What is client-server architecture?
Ans: In federated learning's client-server architecture, the central server maintains and coordinates the global
model — broadcasting it to clients, receiving updates, and performing aggregation (e.g., FedAvg). Clients are
edge devices (phones, hospitals, banks) holding local data — they receive the global model, train it locally,
and return model updates. Communication is bi-directional but data never leaves the client.
Q3. What is model aggregation?
Ans: Model aggregation is the process of combining model updates from multiple clients into a single global
model at the server. The most common method is Federated Averaging (FedAvg): w_global = Σ(n_k/n) × w_k,
where each client's contribution is weighted by its dataset size n_k relative to the total n. Robust aggregation
methods (Krum, trimmed mean) protect against malicious clients.
Q4. Define privacy-preserving learning.
Ans: Privacy-preserving learning encompasses techniques that enable model training while protecting the
privacy of individual data points. Methods include: Differential Privacy (adding calibrated noise to guarantee
bounded information leakage), Secure Aggregation (cryptographic protocols ensuring the server only sees
aggregated updates), Homomorphic Encryption (computation on encrypted data), and Federated Learning
(keeping data on-device).
Q5. What is client heterogeneity?
Ans: Client heterogeneity refers to differences among participating clients in federated learning. Statistical
heterogeneity: Non-IID data — each client's data has different distributions (e.g., different languages,
demographics). System heterogeneity: Clients have different computational capabilities, network speeds,
and availability. Both challenge FL convergence and require techniques like FedProx, personalization, and
asynchronous updates.
Q6. Define model pruning.
Ans: Model pruning is a compression technique that removes unimportant weights or structures from a neural
network to reduce size and computation. Unstructured pruning sets individual small-magnitude weights to
zero (creating sparse matrices). Structured pruning removes entire neurons, channels, or layers (maintaining
dense computation on smaller networks). Typically achieves 40-90% compression with minimal accuracy loss
after fine-tuning.
Q7. What is quantization?
Ans: Quantization reduces the numerical precision of model weights and activations from high-precision
formats (FP32) to lower-precision formats (INT8, INT4, or binary). This reduces model size (4× for
FP32→INT8) and speeds up inference (hardware-accelerated INT8 operations). Post-Training Quantization
(PTQ) is applied after training; Quantization-Aware Training (QAT) simulates quantization during training for
better accuracy.
Q8. Define knowledge distillation.
Ans: Knowledge distillation transfers knowledge from a large, accurate 'teacher' model to a smaller 'student'
model. The student learns to mimic the teacher's soft probability outputs (not just hard labels), which encode
inter-class relationships and dark knowledge. Loss = α×CE(student, hard_labels) + (1-α)×KL(student_soft,
teacher_soft). Temperature T softens the probability distribution, revealing more information.
Q9. What is a Variational Autoencoder (VAE)?
Ans: A VAE is a generative model consisting of an encoder that maps input to a latent distribution (mean µ
and variance σ²) and a decoder that reconstructs from latent samples. Unlike standard autoencoders, VAEs
learn a structured, continuous latent space regularized by KL divergence to be Gaussian. Loss =
Reconstruction Loss + KL(q(z|x)||p(z)). The reparameterization trick (z = µ + σ■ε) enables training via
backpropagation.
Q10. What is GAN?
Ans: A Generative Adversarial Network (GAN) is a generative model consisting of two competing neural
networks: a Generator that creates synthetic data from random noise, and a Discriminator that classifies
inputs as real or fake. They play a minimax game: min_G max_D E[log D(x)] + E[log(1-D(G(z)))]. At
equilibrium, G produces realistic samples and D cannot distinguish real from fake (outputs 0.5).
Q11. Define generator and discriminator.
Ans: Generator (G): A neural network that takes random noise z ~ N(0,I) as input and produces synthetic
data G(z) (e.g., images). Its goal is to fool the discriminator by generating realistic samples. Discriminator
(D): A classifier that takes either real data x or fake data G(z) and outputs a probability D(·) ∈ [0,1] of the input
being real. Its goal is to correctly distinguish real from fake.
Q12. What is a diffusion model?
Ans: A diffusion model is a generative model with two processes: the forward process gradually adds
Gaussian noise to data over T steps until it becomes pure noise, and the reverse process learns to denoise
step-by-step using a neural network. Training minimizes ||ε − ε_θ(x_t, t)||² (predict the noise). Generation
starts from pure noise and iteratively denoises. Produces state-of-the-art quality with stable training (unlike
GANs).
Q13. What is Explainable AI (XAI)?
Ans: Explainable AI encompasses methods and techniques that make machine learning model decisions
understandable to humans. XAI answers: 'Why did the model make this prediction?' Key approaches: Local
explanations (LIME — per-instance), global explanations (SHAP summary plots — overall behavior), and
inherently interpretable models (decision trees, linear models). Required by regulations like GDPR's right to
explanation.
Q14. Expand LIME and SHAP.
Ans: LIME: Local Interpretable Model-agnostic Explanations. Explains individual predictions by fitting a local
linear model on perturbed samples. Model-agnostic, fast, but stochastic. SHAP: SHapley Additive
exPlanations. Uses Shapley values from cooperative game theory to fairly attribute each feature's contribution
to the prediction. Theoretically grounded, consistent, deterministic, supports both local and global
explanations.
Q15. Define fairness in ML.
Ans: Fairness in ML requires that model predictions do not discriminate against individuals based on
protected attributes (race, gender, age, etc.). Key metrics: Demographic parity (equal positive prediction rate
across groups), Equalized odds (equal TPR and FPR across groups), and Calibration (equal accuracy at each
confidence level). The impossibility theorem states that all fairness criteria cannot be simultaneously satisfied.
NUMERICAL PROBLEMS — UNIT 3
Q16. If 5 clients send models of size 20 MB each, total data transmitted = ?
Given: Number of clients = 5, Model size per client = 20 MB
Solution: Total data transmitted (client → server) = 5 × 20 = 100 MB
Note: In a full round, the server also sends the global model to each client,
so total bidirectional communication = 100 MB (upload) + 100 MB (download) = 200
MB per round.
Q17. If pruning removes 40% of parameters from 1M parameters, remaining = ?
Given: Total parameters = 1,000,000, Pruning rate = 40%
Solution: Remaining parameters = 1,000,000 × (1 - 0.40)
= 1,000,000 × 0.60 = 600,000 parameters
The pruned 400,000 parameters are set to zero (unstructured) or removed entirely
(structured).
Q18. If model size reduces from 100 MB to 25 MB after quantization, % reduction = ?
Given: Original size = 100 MB, After quantization = 25 MB
Formula: % reduction = (Original - New) / Original × 100
Solution: % reduction = (100 - 25) / 100 × 100 = 75/100 × 100 = 75%
This is consistent with FP32 → INT8 quantization (32/8 = 4× reduction = 75%).
Q19. If generator loss = 0.3 and discriminator loss = 0.7, total loss = ?
Given: L_G = 0.3, L_D = 0.7
Solution: Total GAN loss = L_G + L_D = 0.3 + 0.7 = 1.0
Note: In practice, G and D losses are optimized separately (not summed).
At Nash equilibrium: L_D → -2*log(2) ≈ -1.386, and D(x) → 0.5 for all x.
Q20. If 3 clients have weights 0.2, 0.3, 0.5, verify sum of weights.
Given: Client weights: w_1 = 0.2, w_2 = 0.3, w_3 = 0.5
Verification: Sum = 0.2 + 0.3 + 0.5 = 1.0 ✓ (Valid)
In FedAvg, weights represent each client's proportion of total data: w_k = n_k /
n.
They must sum to 1.0 to ensure the weighted average is well-defined.
Here: Client 3 has 50% of all data, Client 2 has 30%, Client 1 has 20%.