IITP · Semester ISummaries · Quizzes · Assignments

Lecture summary

Advance Machine Learning

03 Nov 2026 · 18:30--2 parts

Source: IITP-big-files\Sem-1\AML\Lectures\2026-11-03 1830 Advance Machine Learning\summary\notes.md

Overview

This class covered the transition from basic RNNs to more advanced sequence-to-sequence models. It began by recapping the limitations of standard RNNs, such as the inability to learn long-term dependencies due to gradient issues, and introduced LSTM as a solution using gating mechanisms. The core focus was on the encoder-decoder architecture, which enables models to handle variable-length input and output sequences, forming the foundation for tasks like machine translation. The lecture detailed the components of this architecture and introduced the training technique of teacher forcing. This session sets the stage for understanding modern transformer models.

Learning outcomes

  • Explain the limitations of standard RNNs and how LSTM addresses them.
  • Describe the purpose and high-level workflow of an encoder-decoder model.
  • Identify key applications suitable for encoder-decoder architectures.
  • Detail the roles of the encoder and decoder components.
  • Explain the concept and purpose of a context vector.
  • Describe the training process of an encoder-decoder model, including the use of start/end tokens and teacher forcing.
  • Understand the necessity of tokenization/vectorization as a preprocessing step.

Core concepts

RNN Limitations and LSTM Solution

Standard RNNs struggle with learning long-term dependencies due to vanishing and exploding gradients during backpropagation. The LSTM (Long Short-Term Memory) network solves this by introducing a cell state and three gates (forget, input, output) that regulate information flow. This matters because it enables the network to retain relevant information over many time steps, which is crucial for processing long sequences, a prerequisite for building effective encoder-decoder models.

Encoder-Decoder Architecture

An encoder-decoder model is a neural network designed to transform one sequence into another, accommodating variable-length inputs and outputs. It matters because many real-world problems, like translation and captioning, involve sequences of different lengths. The encoder compresses the input into a fixed-size context vector, and the decoder expands this vector into the output sequence. This architecture connects directly to the need for a structured way to handle sequential data transformation.

Context Vector

The context vector is a fixed-size, dense representation output by the encoder, summarizing the entire input sequence. It matters because it serves as the sole source of information from the input for the decoder. Its fixed size is a constraint that necessitates effective compression of the input sequence, linking to later concepts like attention mechanisms which alleviate the information bottleneck of a single vector.

Teacher Forcing

Teacher forcing is a training technique where the decoder receives the ground-truth token from the previous time step as input, rather than its own prediction. This matters because it stabilizes and accelerates training by preventing error propagation in early epochs. It connects to the practical training dynamics of sequence generation models, contrasting the ideal autoregressive generation used during inference.

Tokenization and Vectorization

Tokenization is the process of splitting text into tokens (e.g., words), and vectorization converts these tokens into numerical vectors (e.g., via one-hot encoding). This matters because neural networks require numerical input. It is the mandatory first step in processing any textual data for an encoder-decoder model and connects all NLP tasks to the underlying mathematical operations of the network.

Formulas and maths

No explicit new formulas were derived, but the following functions and methods were mentioned: - Softmax Function: Used in the final layer of the decoder. Explanation: Converts the decoder's hidden state outputs into a probability distribution over the target vocabulary. When used: At every time step in the decoder to predict the next token. - Vectorization Methods: one-hot encoding, bag of words, TF-IDF, n-gram, word2vec. Explanation: Techniques to convert textual tokens into numerical feature vectors. When used: During the preprocessing stage before feeding data into the encoder or decoder.

Worked examples

  1. Input Sequence Processing: For the input sentence "The weather is nice", the encoder processes tokens sequentially: the → weather → is → nice.
  2. Context Vector Size: A long input sequence (e.g., 100 tokens like "I love movie that was released in 1997 and add...") is compressed into a small, dense context vector of size 10.
  3. Vocabulary Size: For a translation task, the target vocabulary (output classes) might consist of 20,000 unique tokens/words.
  4. Sequence Length Mismatch: Input "how are you" (3 words) can be translated to an output with 2 words in another language.
  5. One-Hot Encoding: In a vocabulary of size 5, the token "think" is encoded as [1, 0, 0, 0, 0] and "it" as [0, 0, 1, 0, 0].
  6. Decoder Start Input: The decoder's first input is a start token vector, e.g., [1, 0, 0, 0, 0, 0, 0] for a vocabulary of 7 classes (5 words + start + end tokens).
  7. Softmax Output: The decoder's softmax layer might output probabilities like [0.1, 0.3, 0.31, 0.56, 0.2, 0.1, 0.01] over 7 classes. The class with the highest probability (0.56) is selected as the predicted token.
  8. Training Mismatch: During training, the model might predict "low", but the correct target output from the dataset is "SOCH".

Questions asked in class

  • Q: How big models like GPT work on decoder only or if you use encoder, decoder only? Don't we need encoder-decoder for those models?
  • A: GPT is inspired by encoder-decoder, but its architecture is totally different. The transformer model will be covered in the coding class.
  • Q: About start and end tokens: can they be any symbol?
  • A: Start and end tokens can be any symbol, but they should not be part of the dataset vocabulary to avoid ambiguity.
  • Q: What is the first step in encoder-decoder training?
  • A: Tokenization (and vectorization) for both the input and output languages.
  • Q: Is encoder-decoder part of transformer?
  • A: Yes, the encoder-decoder structure is part of the transformer; adding the attention concept turns it into a transformer. It is the backbone of BERT and attention models.

Key takeaways

  • Standard RNNs fail to capture long-term dependencies due to gradient vanishing/exploding problems.
  • LSTM uses gates (forget, input, output) and a cell state to control information flow and mitigate RNN limitations.
  • Encoder-decoder models are designed for sequence-to-sequence tasks with variable input and output lengths.
  • The encoder compresses a variable-length input sequence into a fixed-size context vector.
  • The decoder generates a variable-length output sequence step-by-step, using the context vector as its initial input.
  • The context vector is a bottleneck, representing the encoder's entire understanding of the input in a dense form.
  • Teacher forcing speeds up training by feeding the true previous token to the decoder instead of its own prediction.
  • Special start and end tokens are used to initiate and terminate the decoder's generation process.
  • Tokenization and vectorization (e.g., one-hot encoding) are mandatory preprocessing steps.
  • The decoder acts as a multi-class classifier at each time step, using softmax over the target vocabulary.
  • The encoder and decoder must use the same type of base model (e.g., both RNN or both LSTM).
  • The transformer model, which powers BERT and GPT, builds upon the encoder-decoder architecture by adding attention.

Exam-style questions

  1. Describe the information bottleneck in a basic encoder-decoder model and explain how it impacts performance on long sequences. Outline: The bottleneck is the fixed-size context vector. The encoder must compress all information from the input sequence into this vector. For long sequences, this compression can lead to information loss, as early details may be forgotten or diluted, degrading the decoder's ability to generate accurate outputs.
  2. Compare and contrast the training process of an encoder-decoder model with and without teacher forcing. What is the key advantage of using teacher forcing? Outline: Without teacher forcing, the decoder uses its own previous prediction as input for the next step, which can lead to error accumulation and unstable training. With teacher forcing, the true previous output is used, which provides correct guidance, accelerates convergence, and reduces the number of backpropagation steps needed by preventing early error propagation.
  3. Walk through the steps an encoder-decoder model takes, from receiving the raw input sentence "Think about it" to producing the first output token during training. Assume one-hot encoding is used. Outline: (1) Tokenize input: ["think", "about", "it"]. (2) Vectorize: Convert each token to a one-hot vector (e.g., [1,0,0,0,0]). (3) Encoder processes vectors sequentially, updating hidden/cell states. (4) Final encoder states (context vector) passed to decoder. (5) Decoder's first input is the start token vector. (6) Decoder computes hidden state and applies softmax to produce probability distribution over output vocabulary. (7) The token with highest probability is the first output (though for loss calculation, it's compared to the true first token).

Glossary

  • RNN - A recurrent neural network that processes sequential data but suffers from gradient issues.
  • LSTM - Long Short-Term Memory network; uses gates to control information flow and mitigate RNN limitations.
  • Encoder-Decoder - A model architecture that transforms a variable-length input sequence into a variable-length output sequence.
  • Context Vector - A fixed-size vector output by the encoder, summarizing the input sequence.
  • Teacher Forcing - A training technique where the decoder uses the ground-truth previous token as input.
  • Tokenization - Splitting text into individual units (tokens) like words or subwords.
  • Vectorization - Converting tokens into numerical vectors (e.g., via one-hot encoding).
  • Start/End Token - Special tokens added to sequences to signal the decoder when to start and stop generating.

Follow-ups

  • Detailed architecture of the encoder and decoder components will be discussed further.
  • The specific mechanism of how the encoder transforms input into the context vector will be elaborated.
  • The detailed iterative prediction process of the decoder, especially how output tokens become inputs for subsequent steps, needs clarification.
  • The concept of attention and its integration into encoder-decoder models to create transformers will be covered.
  • Transformer, BERT, and GPT architectures are scheduled for the coding class.
  • The Gated Recurrent Unit (GRU) model, mentioned as similar to LSTM, may be revisited.
  • The practical versus theoretical working of the decoder during prediction was noted as a point for future clarification.
  • The potential issues of using mismatched encoder and decoder architectures (e.g., RNN encoder with LSTM decoder) were flagged.