Artificial Intelligence & Applications — Comprehensive Revision Notes
Topic 1: Data Exploration and Visualisation
Why Data Visualisation?
Summary statistics alone can be misleading — datasets with identical summary statistics (mean, standard deviation, correlation) can have completely different distributions. This was demonstrated by Anscombe’s Quartet (1973) and the Datasaurus Dozen.
Key principle: Always produce both calculations and graphs. Each contributes to understanding.
Purposes of Visualisation
Data visualisation is a critical tool in AI for identifying summaries, structure, relationships, differences, and abnormalities in data. It communicates complex information effectively.
Chart Types by Purpose
| Purpose | Chart Types |
|---|---|
| Relationship | Scatter plots, bubble charts |
| Composition | Pie charts, stacked bar charts |
| Connection | Network graphs |
| Location | Maps, geographic plots |
| Comparison | Bar charts, grouped bar charts |
Grammar of Graphics
The grammar of graphics is a systematic framework for building plots from components. Learning the grammar helps you think about new graphics beyond pre-existing templates.
Core components:
| Component | Role |
|---|---|
| Data | The dataset being visualised |
| Aesthetics | Mapping variables to visual properties (x, y, colour, shape, size) |
| Geometries | The visual marks (points, lines, bars) |
| Facets | Subplots for subsets of data |
| Statistics | Statistical transformations (smoothing, binning) |
| Coordinates | The coordinate system (Cartesian, polar) |
| Theme | Non-data visual styling |
Data Preparation (Data Wrangling)
Data quality issues to address:
- Missing values — remove or impute
- Duplicate records — merge
- Invalid values — generate best estimate
- Noise — filter or smooth
- Outliers — detect and handle
Feature engineering:
- Feature selection — remove highly correlated features, features with many missing values, irrelevant features (IDs, row numbers)
- Combining features — create new informative features
- Feature transformation — mapping values to a new representation to make analysis easier (e.g., scaling, normalisation)
Topic 2: Supervised Learning
What is Machine Learning?
Machine learning is a set of methods that can automatically detect patterns in data. These patterns are then used to predict future data or perform decision-making under uncertainty.
The Learning Problem
We have a set of training data:
We use this data and an ML method to estimate a function such that .
The relationship is modelled as:
where is an unknown function and is a random error (noise) term.
Terminology:
| Term | Also called |
|---|---|
| Input | Feature, attribute, predictor, independent variable |
| Output | Response, dependent variable, label, ground truth |
Regression vs Classification
| Regression | Classification | |
|---|---|---|
| Output type | Continuous (quantitative) | Categorical (qualitative) |
| Example | Predicting house price | Spam or not spam? |
Linear Regression
The model:
- = constant (y-intercept)
- = coefficient / slope
Least Squares Error — the “best fit” minimises the sum of squared differences between actual and predicted values:
This is minimised using gradient descent.
Strengths: Simple, interpretable, computationally efficient, works well for linearly separable data.
Limitations: Assumes linearity, sensitive to outliers, struggles with multicollinearity, poor with complex non-linear data.
Decision Trees
A decision tree partitions data recursively based on attribute values:
- Determine the best attribute to select as root (using a goodness measure)
- Partition examples into subsets according to values of that attribute
- Construct the tree recursively for each subset
- Exit when all examples belong to one class
Attribute Selection — Information Gain:
Entropy measures impurity:
where is the proportion of class in set .
Entropy after splitting on attribute :
Information Gain:
The attribute with the highest information gain is chosen as the split.
Example (Play Tennis):
| Attribute | Entropy after split | Information Gain |
|---|---|---|
| Outlook | 0.693 | 0.247 (highest) |
| Temperature | 0.911 | 0.029 |
| Humidity | 0.788 | 0.152 |
| Windy | 0.892 | 0.048 |
So Outlook is chosen as the root node.
Strengths: Easy to visualise and interpret, handles non-linear relationships, no need for data normalisation, handles categorical and continuous data.
Limitations: Prone to overfitting (without pruning), sensitive to small data changes.
Random Forest (Ensemble Classification)
Random Forest combines multiple decision trees to reduce overfitting:
- Bootstrapping — train each tree on a random subset of data with replacement
- Feature subsampling — use a random subset of features at each split
- Tree building — grow individual trees independently
- Aggregation — combine results using majority vote (classification) or averaging (regression)
Strengths: Reduces overfitting, handles high-dimensional data.
Limitations: Less interpretable, computationally intensive, requires hyperparameter tuning.
K-Nearest Neighbours (KNN)
A lazy learning approach — no model is built; the entire dataset is retained.
Algorithm:
- User inputs (number of neighbours)
- For each unlabelled instance, calculate the distance to all training instances
- Find the nearest neighbours
- Classification: majority vote among neighbours
- Regression: average of the target values:
Distance metrics:
- Euclidean:
- Manhattan:
Strengths: Simple, no assumptions about distribution, effective for non-linear problems.
Limitations: Computationally expensive at prediction time, performance depends on choice of and distance metric, sensitive to irrelevant/noisy features.
Topic 3: Unsupervised Learning
Clustering
Clustering is a type of unsupervised learning that groups similar objects together. The training data contains no output labels.
Goals: data reduction, outlier detection, missing value imputation, pattern discovery.
Key principle: maximise within-cluster similarity, minimise between-cluster similarity.
Similarity measures (same as KNN):
- Euclidean distance
- Manhattan distance
Cluster Quality Measures
- Cluster centre — for numeric data, the centre of mass (mean); for nominal data, the mode
- Within-cluster variation (wc) — how compact/tight clusters are
- Between-cluster variation (bc) — distances between different clusters
K-Means Algorithm
- Define the number of clusters
- Choose data objects randomly as initial centroids
- Assign each data object to its nearest centroid
- Recalculate the centroid of each cluster as the mean of its members
- Repeat steps 3–4 until cluster membership no longer changes
Finding optimal — Elbow Method:
Plot within-cluster sum of squares (WCSS) against . The “elbow” point where adding more clusters no longer significantly reduces WCSS is the optimal .
Strengths: Simple, efficient.
Weaknesses: Must specify in advance, sensitive to initialisation, sensitive to noise, struggles with non-globular cluster shapes.
Agglomerative (Hierarchical) Clustering
A bottom-up approach — no need to specify beforehand.
Algorithm:
- Treat all data objects as individual clusters; build an dissimilarity matrix
- While number of clusters > 1:
- Find the pair with minimum distance
- Merge them into a bigger cluster
- Update the distance matrix
- Produces a dendrogram
Measuring distance between clusters:
| Method | Description |
|---|---|
| Single link | Distance between the two closest points |
| Complete link | Distance between the two furthest points |
| Centroid | Distance between cluster centroids |
| Group average | Average of all pairwise distances |
Strengths: Deterministic, multiple clustering versions, no need to specify , can create arbitrary cluster shapes.
Weaknesses: Does not scale well to large datasets.
Topic 4: Deep Learning and Fully Connected Networks (FCNs)
Machine Learning vs Deep Learning
| Traditional ML | Deep Learning |
|---|---|
| Raw data → hand-crafted features → classifier | Raw data → learned representations → classifier |
| Requires domain expertise for feature extraction | Features learned automatically from data |
| Shallow representations | Multiple layers of increasingly meaningful representations |
Biological Inspiration
Neural networks are inspired by the human visual cortex (V1 → V2 → V3 etc.), which performs progressively more complex processing. The basic element in an artificial neural network is the artificial neuron (node/unit).
Fully Connected Network (FCN) Architecture
A fully connected network has:
- Input vector:
- Hidden values:
- Output value:
The forward computation:
Without an activation function, this is purely linear. The activation function introduces non-linearity.
One-Hot Encoding (OHE)
For multi-class classification, class labels are converted to binary vectors:
| Label | OHE Vector |
|---|---|
| 0 (zero) | |
| 3 (three) | |
| 6 (six) |
Key Hyperparameters
| Hyperparameter | Description |
|---|---|
| Epochs | Number of times the entire training set passes through the network |
| Batch size | Number of samples per gradient update |
| Learning rate | Scalar that controls the step size of weight updates |
| Number of hidden units | Width of each hidden layer |
Topic 5: Activation Functions in FCNs
Why Activation Functions?
Without non-linearity, no matter how many layers, the entire network collapses to a single linear function. Activation functions:
- Allow backpropagation (derivative is related to input)
- Enable stacking of multiple layers (non-linear combination)
Activation Functions Summary
| Function | Formula | Range | Pros | Cons |
|---|---|---|---|---|
| Linear | Simple | Cannot learn non-linear patterns | ||
| Sigmoid | Smooth, probabilistic output | Vanishing gradient for | ||
| Tanh | Zero-centred, steeper than sigmoid | Vanishing gradient for | ||
| ReLU | Fast, avoids vanishing gradient | Dying ReLU (neurons output 0 permanently) | ||
| Leaky ReLU | Fixes dying ReLU | Small negative slope is a hyperparameter | ||
| Softmax | , sums to 1 | Outputs probabilities | Used only in output layer for multi-class |
When to Use Which
- Hidden layers: ReLU (default), Leaky ReLU if dying neurons are an issue
- Binary classification output: Sigmoid
- Multi-class classification output: Softmax
- Regression output: Linear (no activation)
Topic 6: Loss Functions, Forward and Backpropagation
Loss Functions
The loss function measures how badly the AI system performed:
The total loss over the training set:
Binary Cross-Entropy (BCE)
For binary classification (output via sigmoid):
Categorical Cross-Entropy (CCE)
For multi-class classification (output via softmax):
Mean Squared Error (MSE)
For regression:
Summary: Loss + Output Activation Pairing
| Task | Output Activation | Loss Function |
|---|---|---|
| Binary classification | Sigmoid | Binary cross-entropy |
| Multi-class classification | Softmax | Categorical cross-entropy |
| Regression | Linear (none) | Mean squared error |
Gradient Descent and Backpropagation
Gradient — indicates the direction and rate of steepest ascent of the error function. To minimise the loss, we move in the opposite direction of the gradient.
Backpropagation computes the gradient of the loss with respect to each weight using the chain rule.
Weight update rule:
where is the learning rate.
SGD vs Mini-Batch SGD
| SGD | Mini-Batch SGD | |
|---|---|---|
| Samples per update | 1 random sample | A batch of samples |
| Gradient estimate | Noisy | Smoother |
| Speed | Fast per step | More stable convergence |
Training loop: Input → Predict → Error → Backprop → Update → Repeat
Dropout (Regularisation)
Dropout randomly drops (zeroes out) some neuron outputs during training with probability . This prevents overfitting by making the model less sensitive to noise and more generic.
model.add(Dropout(0.3)) # 30% dropout probabilityOptimisers
| Optimiser | Description |
|---|---|
| SGD | Basic stochastic gradient descent |
| RMSprop | Adapts learning rate per parameter |
| Adam | Combines momentum and adaptive learning rates; often the default choice |
Topic 7: Evaluating ML/DL Models
Model Validation Strategies
Goal: avoid overfitting and find the best hyperparameter combination.
Holdout
Split data into three sets:
| Set | Purpose | Typical Split |
|---|---|---|
| Training | Learn model parameters | 60% |
| Validation | Tune hyperparameters, detect overfitting | 20% |
| Test | Final evaluation on unseen data | 20% |
K-Fold Cross-Validation
- Split dataset into subsets (folds)
- For each fold: train on folds, validate on the remaining fold
- Average results across all runs
Overfitting vs Underfitting
| Underfitting | Good Fit | Overfitting | |
|---|---|---|---|
| Training error | High | Low | Very low |
| Validation error | High | Low | High |
| Model complexity | Too simple | Just right | Too complex |
Solutions to overfitting:
- Early stopping — stop training when validation loss starts increasing
- Regularisation (L2): adds penalty to loss
- Dropout
- More training data
Hyperparameter Optimisation
| Method | Description | Pros | Cons |
|---|---|---|---|
| Grid Search | Exhaustive search over all combinations | Systematic, thorough | Expensive for large spaces |
| Random Search | Random sampling from distributions | More efficient in high dimensions | No guarantee of finding best |
Classification Metrics
Confusion Matrix:
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | True Positive (TP) | False Negative (FN) |
| Actual Negative | False Positive (FP) | True Negative (TN) |
Key metrics:
Why accuracy alone is not enough: In imbalanced datasets (e.g., 91 benign vs 9 malignant tumours), a model that always predicts “benign” achieves 91% accuracy but is useless. Use precision, recall, and F1-score instead.
AUC-ROC: Area Under the Receiver Operating Characteristic Curve — measures the model’s ability to distinguish between classes across all thresholds.
Topic 8: Convolutional Neural Networks (CNNs)
Why CNNs?
FCNs treat input as flat vectors, losing spatial locality — the relationship between neighbouring pixels. CNNs are designed to preserve and exploit spatial structure.
CNN Architecture Components
1. Convolutional Layer
A kernel (filter) slides over the image, performing element-wise multiplication and summation to produce a feature map.
Key parameters:
- Kernel size — e.g., ,
- Stride — step size of the filter movement
- Padding:
valid— no padding, output smaller than inputsame— zero-padding, output same size as input
Output feature map size:
Important: The filter must have the same number of channels as the input (e.g., a filter on an RGB image is actually ).
Number of learnable parameters in a conv layer:
2. Pooling Layer
Reduces spatial dimensions while retaining key information. Max Pooling takes the maximum value in each pooling window.
MaxPooling2D(pool_size=(2, 2), strides=(2, 2))3. Fully Connected (Classification) Layer
After feature extraction through conv and pooling layers, the feature maps are flattened into a 1D vector and fed to dense layers for classification.
Example: Parameter Calculation
For a 32×32 input image (no padding, stride=1):
| Layer | Config | Output Shape | Parameters |
|---|---|---|---|
| Conv1 | 3×3, 16 filters | 30×30×16 | |
| Conv2 | 3×3, 32 filters | 28×28×32 | |
| FC | 10 outputs | 10 | |
| Total | 255,632 |
Pooling layers help reduce the number of parameters in subsequent FC layers.
LeNet Architecture
A classic CNN for handwritten digit recognition (MNIST):
Input (28×28×1)
→ Conv2D(20, kernel=5, valid) → ReLU → MaxPool(2×2)
→ Conv2D(50, kernel=5, valid) → ReLU → MaxPool(2×2)
→ Flatten → Dense(500) → ReLU
→ Dense(10) → Softmax
Topic 9: CNNs Part II — Improving Generalisability
Techniques for Better CNNs
Spatial Dropout
Like standard dropout but drops entire feature maps in convolutional layers rather than individual neurons.
Batch Normalisation
Normalises the output of each layer within a mini-batch to stabilise training.
Why it helps:
- Prevents vanishing/exploding gradients
- Reduces sensitivity to weight initialisation
- Acts as a slight regulariser
Formula:
- Normalise within mini-batch:
where and are the batch mean and variance.
- Scale and shift (learnable parameters):
where (scale) and (shift) are learned during training.
Placement: Typically after the convolutional/dense layer and before the activation function:
Conv2D → BatchNormalization → ReLU
Topic 10: Transfer Learning and Pre-trained CNNs
What is a Pre-trained Model?
A saved network previously trained on a large dataset (e.g., ImageNet with 1.4M images, 1000 classes). Useful when you have a small dataset — improves accuracy and saves training time.
Examples: VGG-16, GoogLeNet/Inception, ResNet, MobileNet, BERT, GPT.
Using a Pre-trained Model
Feature Extraction (Shallow Mode)
- Load pre-trained convolutional base without the top classifier
- Freeze all convolutional layers (
trainable = False) - Add new custom dense layers on top for your specific task
- Train only the new dense layers
Why not reuse the classifier? The original classifier was trained for 1000 ImageNet classes — not your task.
Fine-Tuning (Deep Mode)
Two approaches:
- Full fine-tuning: Set entire model as trainable (
conv_base.trainable = True), train end-to-end with a low learning rate - Partial fine-tuning: Freeze early layers, only unfreeze later layers (e.g., from
block5_conv1onwards)
Rationale: Early layers learn generic features (edges, textures) transferable across tasks. Later layers learn task-specific features.
Topic 11: Handling Class Imbalance
The Problem
When one class vastly outnumbers another (e.g., 998 negatives vs 2 positives), classifiers become biased toward the majority class. A model predicting “always negative” achieves 99.8% accuracy but is useless.
The standard cross-entropy loss is dominated by the majority class gradients.
Algorithm-Level Solutions
Weighted Cross-Entropy
Assign higher weights to minority classes in the loss function:
Weighted BCE:
class_weights = {0: 1.0, 1: 5.0} # higher weight for minority
model.fit(..., class_weight=class_weights)Focal Loss
Reduces the influence of easy (majority) samples and focuses training on hard (minority) samples. Adds a modulating factor to cross-entropy.
Data-Level Solutions
| Technique | Description | Risk |
|---|---|---|
| Random oversampling | Duplicate minority samples | Overfitting |
| Random undersampling | Remove majority samples | Loss of information |
| Data augmentation | Apply transformations (rotation, flip, shift, zoom, shear) | Requires careful tuning |
| SMOTE | Synthetically generate minority samples by interpolating between nearest neighbours | Only for structured/tabular data |
SMOTE (Synthetic Minority Over-sampling Technique)
- Select a minority class instance
- Find its -nearest neighbours (from minority class)
- Create a synthetic sample by interpolating:
where is random.
Critical rule: Perform oversampling/augmentation only on training data, never on the test set.
Performance Metrics for Imbalanced Data
Use precision, recall, and F1-score rather than accuracy alone.
Topic 12: Autoencoders
The Curse of Dimensionality
As the number of features increases without increasing training samples, the feature space becomes sparse. Distance metrics lose meaning, and models overfit easily.
Solution: Dimensionality reduction.
What is an Autoencoder?
An unsupervised neural network that learns a compressed representation of input data and then reconstructs it.
Components:
| Component | Role |
|---|---|
| Encoder | Compresses input into lower-dimensional latent space |
| Latent space (code) | Compressed representation |
| Decoder | Reconstructs input from latent representation |
Loss function (MSE):
Key idea: The network is trained to reproduce its own input (), forcing the latent space to capture essential features.
Types of Autoencoders
1. Vanilla Autoencoder
Fully connected layers. Input → Encoder (Dense) → Latent code → Decoder (Dense) → Reconstructed output.
2. Denoising Autoencoder
Input is a noisy version of the data; the network learns to reconstruct the clean version. This improves robustness.
3. Convolutional Autoencoder (CAE)
Uses Conv2D layers in the encoder and either UpSampling2D (fixed) or Conv2DTranspose (learnable) in the decoder.
Encoder: Conv2D + MaxPooling (downsample)
Decoder: Conv2D + UpSampling/Conv2DTranspose (upsample)
Applications
- Denoising — remove noise/artefacts from images
- Image colourisation — convert grayscale to colour
- Dimensionality reduction — alternative to PCA
- Anomaly detection — high reconstruction error = anomaly
Topic 13: Object Detection and Segmentation
Computer Vision Task Hierarchy
| Level | Task | Output |
|---|---|---|
| Classification | What is in the image? | Class label |
| Object Detection | Where are the objects? | Bounding boxes + labels |
| Semantic Segmentation | Pixel-wise classification | Class label per pixel |
| Instance Segmentation | Pixel-wise + distinguish instances | Mask per object instance |
R-CNN (Region-based CNN)
- Generate ~2000 region proposals using Selective Search
- Warp each region to fixed size
- Extract features using a CNN (e.g., AlexNet)
- Classify each region with an SVM
- Refine bounding boxes with regression
Cons: Very slow — requires ~2000 CNN forward passes per image.
Fast R-CNN
Key improvement: Run the CNN only once per image to produce a shared feature map.
- Generate region proposals with Selective Search
- Run entire image through CNN → feature map
- For each proposal, extract features via RoI (Region of Interest) Pooling
- Classify and refine bounding boxes in one unified network
Con: Still uses slow Selective Search for proposals.
Faster R-CNN
Replaces Selective Search with a Region Proposal Network (RPN) — a small CNN that generates proposals from the feature map itself.
Architecture:
- Backbone CNN → shared feature map
- RPN → generates proposals from the feature map
- RoI Pooling → extracts fixed-size features for each proposal
- Classification head → classifies and refines boxes
Everything is end-to-end trainable.
U-Net (Semantic Segmentation)
An encoder-decoder architecture with skip connections between corresponding encoder and decoder layers.
- Encoder (downsampling path): extracts context using Conv + MaxPool
- Decoder (upsampling path): restores spatial resolution
- Skip connections: combine location information from the encoder with context from the decoder
Advantages: No dense layers (input can be any size), combines localisation and context.
Mask R-CNN (Instance Segmentation)
Extends Faster R-CNN by adding a mask branch that outputs a binary segmentation mask for each detected object, providing pixel-level segmentation alongside bounding boxes and class labels.
Topic 14: Natural Language Processing (NLP)
NLP vs LLMs
- NLP — the broader field of techniques for analysing human language (includes statistical models like N-gram, TF-IDF, BoW)
- LLMs — a specific type of deep learning model within NLP, trained on massive datasets (e.g., GPT, BERT)
Levels of Linguistic Analysis
- Syntax — what is grammatically correct
- Semantics — what is the meaning
Ambiguity Types
| Type | Description | Example |
|---|---|---|
| Lexical | Words with multiple meanings | ”bank” (financial vs river) |
| Semantic | Sentences with multiple meanings | ”I saw him with a telescope” |
| Anaphoric | Pronouns referring to earlier mentions | ”He told his dog to sit, and it did” |
NLP Pipeline
- Sentence segmentation — split text into sentences
- Tokenisation — split sentences into words/tokens
- Stemming — crude chopping of word endings (e.g., “eating” → “eat”)
- Lemmatisation — proper reduction using vocabulary (e.g., “better” → “good”, “drove” → “drive”)
- Stop word removal — remove common words (“the”, “a”, “is”)
- POS tagging — assign part of speech (noun, verb, adjective, etc.)
- Named Entity Recognition — identify persons, locations, times
Bag of Words (BoW)
Represents a document as a vector of word frequencies. Ignores word order entirely.
Process:
- Build a vocabulary of known words
- For each document, count occurrences of each vocabulary word
- Resulting vector represents the document
TF-IDF (Term Frequency — Inverse Document Frequency)
Measures importance of a word to a document within a corpus.
Words that appear frequently in one document but rarely across the corpus get high TF-IDF scores.
Cosine Similarity
Measures similarity between two document vectors:
N-gram Language Models
Uses the probabilities of word sequences to predict the next word.
Markov assumption: the probability of a word depends only on the previous words:
MLE for conditional probabilities:
Types:
- Unigram:
- Bigram:
- Trigram:
Limitations: Computationally expensive for large ; gives zero probability to unseen sequences (sparsity).
Topic 15: Regression and Text Classification with FCNs
Regression with Deep Learning
For regression tasks, the output is continuous.
Key differences from classification:
| Classification | Regression | |
|---|---|---|
| Output activation | Softmax / Sigmoid | Linear (none) |
| Loss function | Cross-entropy | MSE |
| Output units | Number of classes | 1 (or number of target values) |
Data Normalisation for Regression
When features have different scales, normalisation is essential:
Min-Max Scaling:
Z-Score (Standardisation):
Important: Compute normalisation statistics (, , min, max) on the training set only, then apply to test set.
Text Classification with FCNs
Approach (e.g., IMDB sentiment analysis):
- Load pre-processed text data (each review = list of word indices)
- One-hot encode the word sequences into fixed-size binary vectors (dimension = vocabulary size)
- Build an FCN with Dense layers and appropriate activation
Binary classification (IMDB):
Dense(16, relu) → Dense(16, relu) → Dense(1, sigmoid)
Loss: binary_{c}rossentropy
Multi-class classification (Reuters, 46 topics):
Dense(64, relu) → Dense(64, relu) → Dense(46, softmax)
Loss: categorical_crossentropy
Topic 16: Recurrent Neural Networks (RNNs)
Why RNNs?
FCNs treat input as flat vectors — they discard sequential information. Word order matters in NLP: “not bad” ≠ “bad”.
RNN Architecture
An RNN processes sequences one element at a time, maintaining a hidden state that acts as memory.
At each time step :
- Input:
- Hidden state:
- Output:
The same weights (, , ) are shared across all time steps.
Backpropagation Through Time (BPTT)
The RNN is “unrolled” across time steps, and gradients are computed backwards through all steps. This is how RNNs learn temporal dependencies.
Padding Sequences
Since neural networks expect fixed-size inputs, sequences of different lengths are padded (typically with zeros) to the same length:
[1, 2, 3] → [0, 1, 2, 3]
[4, 5] → [0, 0, 4, 5]
[6, 7, 8, 9] → [6, 7, 8, 9]
Word Embeddings
Instead of sparse one-hot vectors, word embeddings map each word to a dense vector where similar words have similar representations.
Embedding layer:
Embedding(vocab_size, embedding_dim, input_length=max_len)vocab_size— number of distinct wordsembedding_dim— size of each embedding vectorinput_length— length of input sequences
Word2Vec
A method for learning word embeddings from context:
- CBOW (Continuous Bag of Words): predicts target word from context words
- Skip-gram: predicts context words from target word
RNN for Text Classification (IMDB)
Embedding(10000, 300, input_length=200)
→ SimpleRNN(32)
→ Dense(1, sigmoid)
The final hidden state summarises the entire input sequence into a fixed-size vector for classification.
Stacking RNNs: Use return_sequences=True for intermediate RNN layers to pass full sequence to the next RNN layer.
RNN for Word Prediction
Embedding(vocab_size, embedding_dim, input_length=max_len)
→ SimpleRNN(hidden_units)
→ Dense(vocab_size, softmax)
Output: probability distribution over entire vocabulary for the next word.
LSTM (Long Short-Term Memory)
Standard RNNs suffer from the vanishing gradient problem — gradients decay exponentially over long sequences, making it hard to learn long-term dependencies.
LSTMs solve this with a memory cell and gates:
| Gate | Function |
|---|---|
| Forget gate | Decides what to discard from memory |
| Input gate | Decides what new information to store |
| Output gate | Decides what to output from memory |
Topic 17: Actionability in AI — Search Algorithms
Search Problem Definition
| Component | Description |
|---|---|
| Initial state | Starting point |
| State space | All reachable states |
| Actions | Operations available at each state |
| Goal state | Desired endpoint |
| Goal test | Check if current state is the goal |
| Path cost | Cost associated with a path |
Search Algorithm Properties
| Property | Description |
|---|---|
| Completeness | Will it find a solution if one exists? |
| Optimality | Will it find the best (lowest-cost) solution? |
| Time complexity | How long does it take? |
| Space complexity | How much memory does it need? |
Uninformed (Blind) Search
Breadth-First Search (BFS)
Explores all neighbours at the current depth before moving deeper. Uses a queue (FIFO).
| Property | BFS |
|---|---|
| Complete | Yes |
| Optimal | Yes (if all actions have equal cost) |
| Strategy | Shallowest node first |
Depth-First Search (DFS)
Explores as deep as possible along one branch before backtracking. Uses a stack (LIFO).
| Property | DFS |
|---|---|
| Complete | No (can get stuck in infinite loops) |
| Optimal | No |
| Strategy | Deepest node first |
Uniform Cost Search (UCS)
Expands the node with the lowest cumulative path cost. Uses a priority queue.
| Property | UCS |
|---|---|
| Complete | Yes |
| Optimal | Yes |
Informed Search
Uses a heuristic function — an estimate of the distance from node to the goal.
Greedy Search
Expands the node with the lowest heuristic value .
| Property | Greedy |
|---|---|
| Complete | No |
| Optimal | No |
| Strategy | Closest to goal (by heuristic) |
A* Search
Combines UCS and Greedy. Evaluation function:
where:
- = backward cost (cumulative cost from start to )
- = forward cost (heuristic estimate from to goal)
Always expands the node with the lowest .
| Property | A* |
|---|---|
| Complete | Yes |
| Optimal | Yes (if is admissible — never overestimates) |
Search Algorithms Comparison
| Algorithm | Complete | Optimal | Uses Heuristic |
|---|---|---|---|
| BFS | Yes | Yes (equal costs) | No |
| DFS | No | No | No |
| UCS | Yes | Yes | No |
| Greedy | No | No | Yes |
| A* | Yes | Yes | Yes |
Topic 18: Uncertainty Quantification and Explainability (XAI)
Monte Carlo Dropout for Uncertainty
Deep learning models are typically “black boxes” — they give predictions but no confidence measure.
MC Dropout method:
- Train the model with dropout as usual
- At inference, keep dropout active (don’t disable it)
- Run multiple forward passes on the same input → different predictions each time
- Average the predictions → final output
- Standard deviation of the predictions → uncertainty estimate
High std = model is uncertain; Low std = model is confident.
Explainable AI (XAI)
XAI aims to make AI decisions interpretable and understandable to humans.
Grad-CAM (Gradient-weighted Class Activation Mapping)
Provides visual explanations for CNN decisions by highlighting important image regions.
How it works:
- Take the feature maps from the last convolutional layer
- Compute the gradient of the predicted class with respect to each feature map
- Compute a weighted sum of feature maps using these gradients → produces a 2D heatmap
- Upsample the heatmap to match the original image size
- Overlay the heatmap on the original image
The result shows which regions contributed most to the prediction — warm colours indicate high importance.
End of revision notes.