session: "6103-advanced-ml/2026-10-27 1831 Advance Machine Learning"
title: "Advance Machine Learning"
date: "2026-10-27 18:31"
duration: "--"
language: "en"
model: "deepseek-ai/DeepSeek-V3.2"
parts: 3
transcript_chars: 56375
generated: "2026-11-23T00:42:19+05:30"
Advanced Machine Learning
Overview
This class introduced sequential data modeling, contrasting it with non-sequential data handled by CNNs. It covered the motivation and architecture of Recurrent Neural Networks (RNNs), including input representation via one-hot encoding and the concept of unfolding over time steps. The lecture then detailed various RNN architectures (one-to-one, one-to-many, many-to-one, many-to-many) and their inherent problems—vanishing/exploding gradients and failure to capture long-term dependencies. Finally, Long Short-Term Memory (LSTM) networks were introduced as a solution, explaining their core components of cell state, hidden state, and gating mechanisms. This session lays the foundation for sequence modeling within the course.
Learning outcomes
- Distinguish between sequential and non-sequential data and choose appropriate models (CNN vs. RNN family).
- Convert text data into a format suitable for RNN input using one-hot encoding.
- Describe the unfolding process of an RNN and how hidden states propagate.
- Identify and explain the different RNN architectures (one-to-one, one-to-many, many-to-one, many-to-many).
- Explain the causes and consequences of vanishing and exploding gradients in RNNs.
- Describe the long-term dependency problem and how LSTM architecture addresses it through cell states and gates.
Core concepts
Sequential vs. Non-Sequential Data
Definition: Non-sequential data items are independent (e.g., images), while sequential data items have strong relationships with previous observations (e.g., stock prices, text). Why it matters: This fundamental distinction dictates the choice of model architecture: CNNs for non-sequential data and RNNs/LSTMs/Transformers for sequential data. Connection: It is the primary motivation for introducing RNNs in the class.
Recurrent Neural Network (RNN) Architecture
Definition: A neural network with cyclic connections, allowing the hidden layer's output (hidden state) to be fed back as input alongside the next data point. Why it matters: This recurrence enables the network to maintain a memory of previous inputs, making it suitable for sequential data. Connection: It is the basic building block contrasted with feedforward networks (like CNNs) and extended into more complex models like LSTM.
Unfolding and Timesteps
Definition: The process of visualizing the RNN's single, looping hidden layer as a series of discrete, repeated steps (T0, T1, T2...), where the number of steps equals the input sequence length. Why it matters: Unfolding makes the sequential processing explicit and simplifies understanding of forward propagation and backpropagation through time. Connection: This concept is key to understanding how RNNs handle variable-length inputs and why deep unfolding leads to gradient problems.
RNN Architectural Types
Definition: Categorization based on the sequential nature of inputs and outputs: One-to-One (vanilla NN), One-to-Many (e.g., image captioning), Many-to-One (e.g., sentiment analysis), and Many-to-Many (e.g., machine translation or video classification). Why it matters: Different real-world tasks require different input-output mappings; choosing the correct architecture is crucial. Connection: This taxonomy shows the flexibility of the RNN framework and introduces the encoder-decoder (sequence-to-sequence) model.
Vanishing and Exploding Gradients
Definition: Problems during backpropagation in deep networks where gradients become extremely small (vanishing) or large (exploding), hindering effective weight updates, especially in early layers. Why it matters: These problems are particularly acute in RNNs due to many unfolded layers, preventing learning over long sequences. Connection: This flaw in standard RNNs motivates the development of more advanced architectures like LSTM.
Long-Term Dependency
Definition: The phenomenon where a term in a sequence depends on information from much earlier in the sequence, not just the immediately preceding element. Why it matters: Standard RNNs with simple recurrent connections often fail to learn these distant relationships. Connection: This specific limitation of RNNs is the key problem that LSTM's cell state and gates are designed to solve.
Long Short-Term Memory (LSTM)
Definition: An RNN variant featuring a cell state (long-term memory), a hidden state (short-term memory), and three gates (forget, input, output) that regulate information flow. Why it matters: LSTMs can learn long-term dependencies and mitigate vanishing/exploding gradients, making them superior to standard RNNs for many sequential tasks. Connection: It is presented as the direct solution to the problems identified with standard RNNs.
Gates in LSTM
Definition: Neural network layers (using sigmoid activation) that decide how much information to forget, add, or output. They operate on a continuous scale from 0 to 1. Why it matters: Gates provide fine-grained control over the cell state, allowing the network to selectively remember or forget information across many time steps. Connection: These are the core mechanisms that enable the LSTM to manage long-term memory and address the dependency problem.
Formulas and maths
- One-hot encoding vector: A binary vector representing a word from a vocabulary of size \( V \).
Example: For vocabulary ["movie", "was", "enjoyable", "disappointing", "not"], "movie" = \([1, 0, 0, 0, 0]\).
Symbols: \( V \) is the vocabulary size.
Used when: Converting categorical text data into numerical input for an RNN.
- RNN Input Shape: \((n, f)\)
Symbols: \( n \) is the sequence length (number of tokens/timesteps), \( f \) is the feature size (e.g., vocabulary size \( V \)).
Used when: Defining the input dimensions for an RNN layer.
- RNN Hidden Layer Net Input (at timestep \( t \)): \( \text{net input}_t = (\mathbf{x}_t \mathbf{W}) + (\mathbf{h}_{t-1} \mathbf{H}) \)
Symbols: \( \mathbf{x}_t \) is the input vector at time \( t \), \( \mathbf{W} \) is the input-to-hidden weight matrix, \( \mathbf{h}_{t-1} \) is the previous hidden state, \( \mathbf{H} \) is the hidden-to-hidden (recurrent) weight matrix.
Used when: Calculating the activation for the hidden layer at each step during RNN forward propagation.
- Weight Update Rule: \( \mathbf{w}_{\text{new}} = \mathbf{w}_{\text{old}} + \alpha \cdot \frac{\partial L}{\partial \mathbf{w}} \)
Symbols: \( \mathbf{w} \) are the weights, \( \alpha \) is the learning rate, \( \frac{\partial L}{\partial \mathbf{w}} \) is the gradient of the loss with respect to the weights.
Used when: Updating model parameters during backpropagation.
- Sigmoid Function Range: \( \sigma(x) \in (0, 1) \)
Symbols: \( \sigma \) denotes the sigmoid activation function.
Used when: Applying activation in LSTM gates to produce gating values between 0 (completely forget/block) and 1 (completely remember/pass).
Worked examples
1. Dataset for Sentiment Analysis:
- Sentences: "movie was enjoyable" (Positive: 1), "movie was disappointing" (Negative: 0), "movie was not enjoyable" (Negative: 0).
- Vocabulary (unique words): {movie, was, enjoyable, disappointing, not}. Size \( V = 5 \).
- One-hot encoding size: 5-dimensional vectors. E.g., "movie" = [1,0,0,0,0], "was" = [0,1,0,0,0].
- Sentence lengths: First two sentences have 3 tokens, third has 4 tokens. Input shape example: (3, 5).
2. RNN Network Sizing:
- For an input shape (3, 5) and a hidden layer with 3 neurons:
- Input-to-hidden weight matrix \(\mathbf{W}\) size: \(5 \times 3\).
- Recurrent weight matrix \(\mathbf{H}\) size: \(3 \times 3\) (for 3 hidden neurons).
- Number of recurrent connections: \(3 \times 3 = 9\).
3. RNN Unfolding for "movie was good":
- Sequence length \( n = 3 \). The hidden layer executes 3 times.
- T0: Input \(\mathbf{x}_{11}\) ("movie") is passed. Initial hidden state \(\mathbf{h}_0\) is random (e.g., [0.01, 0.02]).
- T1: Input \(\mathbf{x}_{12}\) ("was") and previous hidden state \(\mathbf{h}_0\) are passed.
- T2: Input \(\mathbf{x}_{13}\) ("good") and previous hidden state \(\mathbf{h}_1\) are passed.
4. Illustrative Deep RNN:
- A network with 5 hidden layers and an input sequence of length 30.
- Each hidden layer executes 30 times due to unfolding.
- Total loops during forward propagation: \(5 \times 30 = 150\).
- During backpropagation, weights need to be updated at least 150 times (in reverse order).
5. Long-Term Dependency Example:
- Sentence: "Ram studies in the 10th class. He is a good boy."
- The pronoun "He" has a long-term dependency on "Ram," which appeared earlier.
- Extended sentence: "He lives in Agra that famous for Taj Mahal. Which now..."
- Here, "which" references "Taj Mahal," requiring the model to forget the old "He"-"Ram" relationship and learn the new "which"-"Taj Mahal" relationship.
6. Sigmoid Gate Operation (Illustrative):
- A hidden state vector \([10, 20, 30]\) passes through a sigmoid gate, producing values like \([0.1, 0.2, 0.1]\).
- After multiplication (gating), the information is reduced, e.g., to \([1, 4, 3]\).
7. Learning Rate Example:
- Alpha (\(\alpha\)) is normally kept very small for stable updates.
- A large, problematic alpha value example is 100, which would cause drastic, unstable weight updates.
Questions asked in class
- On bias addition: How is bias handled in the weight matrices?
- Answer: Bias is an additional input that changes the matrix dimensions (e.g., from 5x3 to 6x3). This was covered in fundamental neural network concepts.
- On input feeding: What is fed as input at each timestep?
- Answer: At each timestep (t1, t2...), the input is the next token from the dataset (e.g., "movie", then "was", then "good"), not a weight.
- On number of loops: Does the number of loops equal the input sequence length?
- Answer: Yes, the number of times the RNN loop executes equals the size of the input (e.g., three tokens mean three loops).
- On weight update timing: When do weight updates happen?
- Answer: Weight updates happen during backpropagation, not during the forward propagation being discussed.
- On inputs to hidden layer: What are the inputs to the hidden layer at every timestep?
- Answer: There are always two inputs: 1) the new data point from the dataset, and 2) the hidden state from the previous timestep. For the first timestep, the previous hidden state is randomly initialized.
- On multiple hidden layers: If an RNN has multiple hidden layers, how many times does each execute?
- Answer: Each hidden layer executes the same number of times (loops) as the input sequence length.
- On deciding hidden layer size: Is there a formula to decide the number of hidden neurons?
- Answer: No mathematical formula. It is determined empirically by experimentation ("hit and try").
- On LSTM inputs: How many input types does LSTM have?
- Answer: In LSTM, three kinds of input are possible (to be covered in detail later).
- On encoder-decoder: Is the first version of many-to-many also called something else?
- Answer: Yes, it is also called encoder-decoder or sequence-to-sequence architecture.
- Ritika's point: Do more hidden layers increase the chance of vanishing gradients?
- Answer: Yes, you are correct. If the model is deeper, there is more chance for the vanishing gradient problem.
- Narayan's question (implied): Is forgetting a relationship permanent?
- Answer: No. If you forget about "he" and "Ram," you cannot add it back at that point, but if the relationship appears again in the dataset later, you can learn/add it then.
Key takeaways
- Sequential data (text, time series) requires models like RNNs/LSTMs, unlike independent, non-sequential data (images) handled by CNNs.
- RNNs handle variable-length sequences by unfolding a single, recurrent hidden layer over as many timesteps as the input sequence length.
- The hidden state acts as the network's memory, passed from one timestep to the next alongside the new input.
- RNN architectures are defined by their input-output sequence types: One-to-One, One-to-Many, Many-to-One, and Many-to-Many (encoder-decoder or synchronous).
- Vanishing and exploding gradients are major training problems in RNNs, caused by multiplying many gradient terms during backpropagation through many unfolded layers.
- The long-term dependency problem refers to an RNN's difficulty in learning relationships between elements far apart in a sequence.
- LSTM solves RNN limitations by introducing a cell state (long-term memory) and three gates (forget, input, output) that regulate information flow.
- LSTM gates use sigmoid activations to output values between 0 and 1, controlling how much information is retained, added, or passed on.
- The number of hidden neurons in an RNN/LSTM layer is a hyperparameter determined experimentally, not by a fixed formula.
- During forward propagation, the hidden layer receives two inputs at each step: the current data point and the previous hidden state (randomly initialized for the first step).
- Weight updates occur during backpropagation, not during the forward pass/unfolding.
- For tasks without long-term dependencies and with shallow networks, RNNs might suffice, but LSTMs are generally preferred for robustness.
Exam-style questions
1. Question: Given a vocabulary of size 10 and a maximum sentence length of 7 tokens, describe the input preparation for an RNN. What would be the shape of the input tensor for a batch of 5 such sentences? Explain the role of the "sequence length" parameter.
- Answer Outline: Each word is one-hot encoded into a 10-dimensional vector. A sentence is a sequence of these vectors, padded/truncated to length 7. The input tensor shape would be (5, 7, 10) representing (batch_size, sequence_length, features). The sequence length parameter defines how many times the RNN loop will execute during unfolding.
2. Question: Compare and contrast the Many-to-Many RNN architectures used for Machine Translation versus Frame-level Video Classification. Use diagrams if necessary.
- Answer Outline: Machine Translation uses an encoder-decoder (sequence-to-sequence) architecture: the entire input sequence is processed by the encoder first, then the decoder generates the output sequence step-by-step. Frame-level Video Classification uses a synchronous many-to-many architecture: at each timestep, an input frame is processed, and an output (e.g., a label) is produced immediately for that frame, without waiting for the entire input sequence to finish.
3. Question: Explain why a standard RNN might fail to learn the relationship between the words "Ram" and "He" in the sentence: "Ram, who arrived early, finished his work quickly. He then left." Propose a solution and describe one core mechanism it uses.
- Answer Outline: The RNN suffers from the long-term dependency problem; the dependency between "Ram" and "He" spans many intermediate words, and gradients may vanish over these steps during training, preventing the network from learning the connection. The solution is LSTM. One core mechanism is the forget gate, which uses a sigmoid activation to decide what proportion of the long-term cell state information to retain, allowing it to maintain relevant information (like "Ram" being the subject) over long distances.
4. Question: During backpropagation in a deep RNN, you observe that the weights in the early layers are not updating significantly, while the loss remains high. Name the problem, its cause, and one common architectural solution used to mitigate it.
- Answer Outline: This is the vanishing gradient problem. It is caused by repeatedly multiplying gradients (often values <1) through many unfolded layers during backpropagation, causing gradients for early layers to approach zero. A common architectural solution is using LSTM (or GRU) units, which use gating mechanisms to create more stable gradient paths and preserve information over time.
Glossary
- Non-sequential data - Data where each record is independent and order does not matter (e.g., images).
- Sequential data - Data where each observation has a strong relationship with previous ones (e.g., text, time series).
- One-hot encoding - A representation of a categorical variable as a binary vector with one element active.
- Timestamp (RNN context) - A parameter indicating the number of tokens/sequence length, defining RNN loop executions.
- Unfolding - Visualizing an RNN's recurrent loop as a series of discrete, repeated timesteps.
- Hidden state - The output from an RNN's hidden layer at a timestep, fed back as input to the next timestep.
- Many-to-Many (Encoder-Decoder) - An RNN architecture that processes a full input sequence before generating an output sequence.
- Vanishing gradient - A training problem where gradients become extremely small, preventing weight updates in early layers.
- Exploding gradient - A training problem where gradients become extremely large, causing unstable weight updates.
- Long-term dependency - A relationship in sequential data between elements that are far apart.
- LSTM (Long Short-Term Memory) - An RNN variant designed to learn long-term dependencies using a cell state and gating mechanisms.
- Cell state - The long-term memory pathway in an LSTM, regulated by gates.
- Gates (LSTM) - Neural network layers that control the flow of information in an LSTM (forget, input, output).
Follow-ups
- Detailed mathematical formulation of how the hidden state is combined with new input at each RNN step.
- Training process and weight update