session: "6103-advanced-ml/2026-10-06 1830 Advance Machine Learning"
title: "Advance Machine Learning"
date: "2026-10-06 18:30"
duration: "1h 30m"
language: "en"
model: "deepseek-ai/DeepSeek-V3.2"
parts: 2
transcript_chars: 50830
generated: "2026-11-23T02:04:01+05:30"
Advanced Machine Learning
Overview
This class covered two main topics. First, it extended the perceptron model to the Widrow-Hoff learning rule (delta rule), which uses continuous activation and gradient descent, enabling its application to regression problems. Second, it introduced the fundamental challenge of Natural Language Processing (NLP): converting text into numerical data. The lecture began an overview of text vectorization methods, covering basic terminology and deterministic methods like one-hot encoding, Bag-of-Words, n-grams, and an introduction to TF-IDF, including their limitations.
Learning outcomes
- Explain the limitations of the perceptron and the key improvements introduced by the Widrow-Hoff rule.
- Describe the core challenge in NLP and the necessity of text vectorization.
- Define basic NLP terminology: corpus, vocabulary, document.
- Explain and apply deterministic text vectorization methods: one-hot encoding, Bag-of-Words (BoW), and n-grams.
- Calculate and interpret TF-IDF values for terms in a document collection.
Core concepts
Perceptron Model
A binary classification model inspired by the MCP model and Hebb's rule, featuring iterative weight updates. It matters as an early neural network that introduced forward and back propagation, but its limitations (binary-only, discrete activation, non-adaptive convergence) motivated more advanced models like the Widrow-Hoff rule.
Widrow-Hoff Learning Rule (Delta Rule)
An extension of the perceptron that uses a continuous activation function and gradient descent to minimize sum of squared error (SSE). It connects to the perceptron via a similar weight update formula but is significant because it enables regression tasks and continuous error-based learning.
Text Vectorization / Word Embedding
The mandatory process of converting text into numerical vectors/matrices for ML/DL models. This is the core challenge of NLP, as model success heavily depends on how well this conversion captures meaning. It connects to all subsequent NLP modeling.
Deterministic Vectorization Methods
Text vectorization techniques based on word counts or frequencies, including one-hot encoding, Bag-of-Words (BoW), and n-grams. They matter as foundational, interpretable methods but have key limitations (sparsity, OOV problem, loss of semantics) that motivate more advanced predictive methods.
TF-IDF (Term Frequency-Inverse Document Frequency)
A statistical measure used for text vectorization that evaluates a term's importance to a document within a corpus. It matters because it weights terms by their relevance, diminishing common words (stopwords) and highlighting distinctive ones, which is useful for document search and similarity.
Formulas and maths
- Perceptron/Widrow-Hoff Weight Update Rule:
w_new = w_old + learning_rate (t - o) x w_new, w_old: new and old weight vectors.learning_rate: a scalar controlling update step size.t: target value (class label in perceptron, continuous number in Widrow-Hoff).o: model's output/prediction.x: input feature vector.- Used when: Updating model weights during training in perceptron or Widrow-Hoff learning.
- TF-IDF:
TF-IDF(t, d) = TF(t, d) × IDF(t) where IDF(t) = log(N / DF(t)) t: A term (word).d: A specific document.TF(t, d): Term Frequency of t in document d.IDF(t): Inverse Document Frequency of term t.N: Total number of documents in the corpus.DF(t): Document Frequency of term t (number of documents containing t).- Used when: Converting text documents into numerical feature vectors that reflect term importance, or for calculating document similarity.
- Document Frequency:
DF(t) = (number of documents containing term t) / N DF(t): Document Frequency of term t.N: Total number of documents.- Used when: Calculating the base frequency of a term across a document collection, often as a step before computing IDF.
Worked examples
Widrow-Hoff Rule Example
- Predicting a person's salary.
- Actual salary (
t) = 500. - Model prediction (
o) = 200. - The error (
t - o) = 300. This continuous error value (300) is used directly in the weight update formula w_new = w_old + learning_rate (300) x.
One-Hot Encoding Setup Example
- Dataset with two documents:
1. "I love movie"
2. "Movies are good I was good movie"
- Corpus (all words): I, love, movie, movies, are, good, I, was, good, movie.
- Vocabulary (unique words): I, love, movie, movies, are, good, was.
- Each of the 7 unique words becomes a feature column.
One-Hot Encoding Vector Example
- Vocabulary: ["i", "love", "movie", "are", "good", "worst"]
- Sentence "i love movie" → vector: [1, 1, 1, 0, 0, 0]
- Sentence "movie was good" → vector: [0, 0, 1, 0, 0, 0] (assuming "was" is not in the vocabulary, so it is ignored).
Bag-of-Words (BoW) Example
- Sentences: "small dog", "cute cute cat", "cute dog"
- Vocabulary: ["small", "dog", "cute", "cat"]
- Vectors:
- "small dog" → [1, 1, 0, 0]
- "cute cute cat" → [0, 0, 2, 1]
- "cute dog" → [0, 1, 1, 0]
N-gram Example
- Sentence: "I love reading history books and watching documentaries"
- Unigrams (n=1): "I", "love", "reading", "history", "books", "and", "watching", "documentaries"
- Bigrams (n=2): "I love", "love reading", "reading history", "history books", "books and", "and watching", "watching documentaries"
- Trigrams (n=3): "I love reading", "love reading history", "reading history books", "history books and", "books and watching", "and watching documentaries"
Sparsity Example
- For a tweet dataset: Vocabulary size ~20,000 unique words.
- Average tweet length ~20 words.
- Result: The vector for a single tweet is approximately 99% zeros (since only ~20 out of 20,000 positions are non-zero).
TF-IDF Intuition Example (Google Search)
- Search query: "data science"
- Document A: Term Frequency (TF) for "data science" = 15%
- Document B: TF = 0.7%
- Document C: TF = 0.3%
- Conclusion: Document A is more relevant based on higher term frequency.
- For a rare term like "bomb": It may have a very high IDF score, making it significant for document relevance even if its TF is low.
Questions asked in class
- Saurabh's question: What is the difference between images and deep learning?
- Answer: NLP deals specifically with text data, while deep learning is a technique applied to various data types, including text.
- Reg's observation: Regression also uses text vectorization.
- Answer: Confirmed as correct.
- General check: Have you heard the term "text mining"?
- Answer: Students confirmed they have.
- Student observation: Models like Transformer require significant computational power.
- Answer: Instructor agreed and mentioned advanced models would be covered in a dedicated NLP elective.
- Sachin's question: [Unclear from transcript, but instructor addressed parallel processing of independent vectors].
- Question on n-gram vectorization: How does n-gram vectorization work?
- Answer: For n-gram vectorization, the features are the n-grams themselves (e.g., bigrams). If n=1, it behaves like one-hot encoding. The process involves first applying gram-level vectorization (converting each gram to a numeric representation), then sentence-level conversion.
- Saurabh's question: Will n-gram vectors also be sparse matrices?
- Answer: Yes, they will also be sparse.
Key takeaways
- The perceptron is limited to binary classification, uses discrete activation, and is not adaptive.
- The Widrow-Hoff rule extends the perceptron by using continuous activation and gradient descent, enabling regression.
- The fundamental NLP challenge is converting unstructured text into numerical data for ML/DL models.
- Text vectorization/word embedding is a mandatory preprocessing step, and the same method must be used for training and testing.
- One-hot encoding represents a document as a binary vector indicating the presence/absence of vocabulary terms.
- Bag-of-Words (BoW) extends one-hot by capturing term counts or frequencies.
- A major limitation of one-hot and BoW is sparsity (vectors are ~99% zeros in real datasets).
- The Out-of-Vocabulary (OOV) problem occurs when a new term at test time wasn't in the training vocabulary.
- N-grams are contiguous sequences of
n items (words/characters) used to capture local context. - TF-IDF is calculated as
TF(t,d) × IDF(t), where IDF(t) = log(N / DF(t)). - TF-IDF weights terms by their importance, giving less weight to very common terms (stopwords).
- In NLP projects, approximately 90% of the work is on text vectorization and 10% on modeling.
Exam-style questions
1. Question: A perceptron model outputs a prediction o = 0 for an input x. The true label is t = 1, the learning rate is 0.1, and the current weight vector w_old is [0.5, -0.2] for x = [1, 3]. Calculate the updated weight vector w_new using the perceptron learning rule.
- Answer Outline: Apply formula
w_new = w_old + learning_rate (t - o) x. (t - o) = 1. New weights: w_new = [0.5, -0.2] + 0.1 1 [1, 3] = [0.5 + 0.1, -0.2 + 0.3] = [0.6, 0.1].
2. Question: Given a corpus with three documents: D1: "the cat", D2: "the dog", D3: "the cat and the dog". Using a vocabulary of unique words ["the", "cat", "dog", "and"], show the Bag-of-Words (count-based) vector representation for D3.
- Answer Outline: Count occurrences in D3: "the"=2, "cat"=1, "dog"=1, "and"=1. Vector ordered as vocabulary: [2, 1, 1, 1].
3. Question: Explain why TF-IDF might assign a high score to the word "bomb" in a document about cybersecurity, even if the word appears only once, while assigning a low score to the word "the" which appears many times.
- Answer Outline: "Bomb" is likely a rare term across the entire document corpus (low DF), resulting in a high IDF value (
log(N/DF) is large). "The" is a stopword appearing in almost every document (high DF), resulting in a very low IDF. TF-IDF multiplies TF by IDF, so a high IDF can make a term significant despite a low TF.
4. Question: Describe two key limitations of one-hot encoding and Bag-of-Words models for text vectorization.
- Answer Outline: 1) Sparsity: Real-world vectors are extremely sparse (~99% zeros), which is computationally inefficient. 2) Out-of-Vocabulary (OOV) Problem: The model cannot handle words that appear during testing but were not seen during training, as they have no corresponding feature column.
5. Question: For the sentence "machine learning is fun", list all bigrams (n=2).
- Answer Outline: "machine learning", "learning is", "is fun".
Glossary
- Corpus - The total collection of all words present in the entire dataset.
- Vocabulary - The list of unique words in the corpus.
- Document - A single record in a dataset (e.g., one tweet, one email).
- One-hot encoding - A text vectorization method that converts a document into a binary vector indicating term presence/absence.
- Bag-of-Words (BoW) - A text vectorization method that represents a document by the count or frequency of its words.
- Sparsity - A property of vectors where most elements are zero.
- Out-of-Vocabulary (OOV) - A term encountered during testing that was not present in the training vocabulary.
- N-gram - A contiguous sequence of
n items (words or characters) from a given text. - Term Frequency (TF) - The frequency of a term within a specific document.
- Document Frequency (DF) - The proportion of documents in a corpus that contain a specific term.
- Inverse Document Frequency (IDF) - A measure that downweights terms that appear frequently across many documents.
- TF-IDF - A numerical statistic that reflects the importance of a word to a document in a collection.
Follow-ups
- Detailed algorithms and mathematics of gradient descent were mentioned but not covered in this class.
- A detailed TF-IDF calculation example is slated for the next class.
- The concept of "context" will be explored further during discussions on Recurrent Neural Networks (RNNs).
- Applications of TF-IDF, such as document similarity and document searching, will be covered.
- Advanced text vectorization methods (Word2Vec, FastText, GloVe) and models (Transformer, BERT, Encoder-Decoder) are planned for a potential future elective NLP course.
Exam verification — corrections & additions
- Sum of a one-hot vector is always non-zero — a document has at least one word, so at least one position is 1.
- Sum of a BoW vector may be zero — a document containing none of the vocabulary terms gives an all-zero vector. It may also be 1, 10, … because BoW stores counts, not only 0/1.
- Vocabulary vs corpus: vocabulary = unique words, corpus = all words in the whole data set. Vocabulary is never larger than the corpus, but they are equal when every word is unique (so "always smaller" is false).
- Word order: at the document-vector level both one-hot and BoW lose word order and semantic meaning. (In a sequence of one-hot word vectors the order does matter — that is the sense used in the assignment question.)
- OOV (out-of-vocabulary) affects both one-hot and BoW.
- Full 80-question answer key:
C:\PORJECTX\aml-import\AML-FINAL-EXAM-ANSWER-KEY.md