রোডম্যাপ
PHASE 1 · অধ্যায় 5

স্টপ ওয়ার্ড অপসারণ

Stop Words Removal

অপ্রয়োজনীয় common words বাদ দিয়ে meaning কে clean করা।

ভূমিকা

একটা sentence এর কথা ভাবুন: 'The cat is on the mat'। এখানে 'the', 'is', 'on' — এগুলো কি real meaning carry করে? — খুব একটা না। এই 'কম-meaning' শব্দগুলোর নাম Stop Words। এগুলো বাদ দিলে text হালকা হয় এবং important word গুলো ফোকাসে আসে।

ধারণা

Stop Words হলো সেই common words যেগুলো ভাষায় খুব frequent কিন্তু individually meaning কম carry করে — যেমন English এ 'a', 'an', 'the', 'is', 'of', 'and', বাংলায় 'এবং', 'কিন্তু', 'যে', 'এই'। Stop words removal হলো এই words গুলোকে text থেকে বাদ দেওয়ার process — যাতে model এর focus important content words এর উপর থাকে।

সহজ ব্যাখ্যা

একটা ছবির background blur করে দিলে subject টা বেশি pop করে — stop words removal এর কাজ অনেকটা সেরকম। 'I love Bangla NLP' থেকে 'I' বাদ দিলে থাকে 'love Bangla NLP' — meaning hardly changes কিন্তু processing fast হয়। তবে সব ক্ষেত্রে stop words বাদ দেওয়া উচিত না — যেমন sentiment analysis এ 'not' খুব important!

বাস্তব ব্যবহার

  • Google Search — query থেকে stop words বাদ দিয়ে index এ match করে।
  • Document classification — feature space ছোট করার জন্য stop words remove করা হয়।
  • Keyword extraction — শুধু meaningful word রাখার জন্য essential।
  • TF-IDF calculation — stop words না সরালে false high score আসে।
  • Spam filter — stop words বাদ দিলে content words এর pattern স্পষ্ট হয়।

ধাপে ধাপে বিশ্লেষণ

1
Step 1 — Stop words list load করুন
NLTK বা spaCy থেকে predefined list নেওয়া।
2
Step 2 — Text tokenize করুন
প্রথমে word-level tokenization।
3
Step 3 — Filter করুন
প্রতিটা token check করে যদি stop word হয়, বাদ দিন।
4
Step 4 — Case normalize করুন
Comparison এর আগে lowercase — না হলে 'The' আর 'the' আলাদা হবে।
5
Step 5 — Custom list বানান
Domain-specific stop words (যেমন medical, legal) নিজে add করুন।

Python কোড

import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize

nltk.download("punkt", quiet=True)
nltk.download("punkt_tab", quiet=True)
nltk.download("stopwords", quiet=True)

text = "The quick brown fox jumps over the lazy dog in the garden."

# 1. Get English stop words
stop_words = set(stopwords.words("english"))
print("Total stop words:", len(stop_words))
print("Sample:", list(stop_words)[:10])

# 2. Tokenize
tokens = word_tokenize(text.lower())

# 3. Filter
filtered = [w for w in tokens if w not in stop_words and w.isalpha()]
print("Original tokens:", tokens)
print("After removal:", filtered)

# 4. Bangla example with custom stop words
bangla_text = "আমি এবং তুমি একসাথে বাংলা NLP শিখব"
bangla_stops = {"এবং", "কিন্তু", "যে", "এই", "ও", "তাই"}
bangla_tokens = bangla_text.split()
bangla_filtered = [w for w in bangla_tokens if w not in bangla_stops]
print("Bangla filtered:", bangla_filtered)
ব্যাখ্যা

NLTK তে প্রায় ১৭৯টা English stop word আছে। আমরা set ব্যবহার করেছি কারণ set এ lookup O(1) — list এ O(n)। বাংলার জন্য NLTK এ built-in list নাই, তাই আমরা custom set বানালাম। `.isalpha()` দিয়ে punctuation ও বাদ দিলাম। মনে রাখবেন — sentiment analysis এ 'not', 'no' রাখা important, তাই custom list এ সেগুলো exclude করতে হবে।

সাধারণ ভুল

  • Sentiment analysis এ 'not' remove করা — 'not good' হয়ে যাবে 'good', meaning উল্টে যাবে!
  • Case-sensitive compare করা — 'The' stop word list এ নেই (শুধু 'the' আছে)।
  • Domain-specific stop words উপেক্ষা করা — medical text এ 'patient' হয়তো stop word।
  • সব সময় সব text এ stop word remove করা — translation/generation এ এটা ক্ষতিকর।

অনুশীলন

  1. 'I do not like this movie' — stop word remove করুন। Result দেখে বুঝুন কেন sentiment task এ ভুল হতে পারে।
  2. NLTK এর English stop words list print করুন এবং top ২০টা frequent ones identify করুন।
  3. নিজের ২০টা বাংলা stop word এর list বানান এবং একটা paragraph clean করুন।

ছোট প্রজেক্ট

Mini Project: Smart Stop Word Remover

একটা function `remove_stopwords(text, language='english', keep=None)` লিখুন। Parameters: text, language ('english' বা 'bangla'), এবং keep — একটা list যেখানে যে stop words রাখতে চান (যেমন ['not', 'no']) তা দিতে পারবেন। Output: cleaned text। বাংলার জন্য আপনার custom list use করুন।

সারাংশ

  • Stop words = common low-meaning words (the, is, এবং, ও)।
  • Remove করলে text হালকা হয়, processing fast হয়, important word focus এ আসে।
  • Sentiment/translation task এ সাবধান — 'not', 'no' রাখা দরকার।
  • NLTK English list ready, বাংলার জন্য custom list বানাতে হবে।