0–5 min
Real Hook
5–25 min
Core Concept
25–45 min
Live Coding
45–55 min
You Code It
55–60 min
Cheat Sheet
🔥 Real-World Hook (0–5 min)

Flipkart processes 2 million product reviews per day. A human reading all of them? Impossible. An NLP pipeline classifies each review as positive/negative/neutral in real time, feeds the insight to sellers automatically.

Every chatbot, email classifier, autocomplete, and LLM is built on the same foundational NLP primitives you'll learn today.

📈 NLP Pipeline (5–25 min)

💡 Raw Text → Numbers

Tokenize — split text into words/tokens.
Clean — lowercase, remove punctuation, stop words.
Vectorize — TF-IDF, Bag-of-Words, or embeddings → numeric matrix.
Model — feed matrix to classifier (Naive Bayes, Logistic Regression, NN).

💻 Live Demo — Review Sentiment Classifier (25–45 min)

>import re
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report

# Sample product reviews
reviews = [
    "Excellent product, very happy with the quality!",
    "Worst purchase ever. Broke in 2 days.",
    "Good value for money, works as expected.",
    "Terrible quality, do not buy this.",
    "Amazing! Fast delivery and perfect condition.",
    "Disappointed. Not as described in listing.",
    "Superb build quality, highly recommend!",
    "Stopped working after a week. Waste of money.",
    "Average product. Nothing special about it.",
    "Brilliant! Exactly what I needed. Very satisfied.",
]
labels = [1, 0, 1, 0, 1, 0, 1, 0, 0, 1]   # 1=positive, 0=negative

# Clean text
def clean(text):
    text = text.lower()
    text = re.sub(r"[^a-z\s]", "" " , text)
    return text

clean_reviews = [clean(r) for r in reviews]

# TF-IDF: how important is a word to this doc vs the corpus?
vectorizer = TfidfVectorizer(stop_words="english", max_features=500)
X = vectorizer.fit_transform(clean_reviews)

X_tr, X_te, y_tr, y_te = train_test_split(X, labels, test_size=0.3, random_state=42)
clf = LogisticRegression()
clf.fit(X_tr, y_tr)
print(classification_report(y_te, clf.predict(X_te)))

# Predict new review
new = ["Really bad experience, total waste of money!"]
vec = vectorizer.transform(new)
print(f"Sentiment: {'Positive' if clf.predict(vec)[0]==1 else 'Negative'}" )

📋 You Code It (45–55 min)

✍ Task

Add 5 more reviews to the dataset (mix of positive/negative). Print the top 10 TF-IDF features by weight using vectorizer.get_feature_names_out() and clf.coef_. Which words most indicate spam?

⚡ Day 8 Cheat Sheet

TfidfVectorizer(stop_words="english")
Text → TF-IDF matrix
vectorizer.fit_transform(texts)
Learn vocab + transform
vectorizer.transform(new_texts)
Transform new texts
vectorizer.get_feature_names_out()
List of vocabulary words
re.sub(r"[^a-z]", " ", text)
Remove non-alpha chars
text.lower()
Normalize case
clf.coef_[0]
Word importance weights
np.argsort(coef)[-10:]
Top 10 features