51. What Is Natural Language Processing (NLP)
51.4 Bag-of-Words Intuition
51.4 Bag-of-words intuition
Order बाजूला — word counts चा simple bag. TF-IDF ची foundation.
हे का शिकायचं?
Why. Order बाजूला ठेवून word counts चा simple bag — TF-IDF आणि classical classifiers ची foundation.
हे काय आहे?
What. Bag-of-words = प्रत्येक document साठी “कोणता word किती वेळा”. Grammar deep parse नाही. Beginners साठी fast आणि explainable.
कसं करायचं?
How.
Manual mini bag
- दोन short reviews लिहा.
- Unique words list करा.
- प्रत्येक review साठी count vector कागदावर.
- y = sentiment label known from humans.
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
docs = [
"fresh pedha on time",
"sour dahi late delivery",
"fresh dahi good packing",
]
y = [1, 0, 1] # 1=positive, 0=negative (fictional)
vec = CountVectorizer()
X = vec.fit_transform(docs)
print(vec.get_feature_names_out())
print(X.toarray())
print("y:", y)
Ravindra Bagale's Tip
Bag-of-words only counts words, like items in a basket, and it ignores their order. So a phrase like "not good" is a hard case for it. Even so, it gives a strong baseline for many tasks such as tagging tickets, and TF-IDF in the next chapter makes it smarter.
Ravindra Bagale's Tip – मराठी
Bag-of-words फक्त words मोजतं, जसं basket मधल्या वस्तू मोजतो, आणि त्यांचा क्रम (order) लक्षात घेत नाही. त्यामुळे "not good" सारखा phrase त्याच्यासाठी अवघड case आहे. तरीही tickets ला tag लावण्यासारख्या अनेक कामांसाठी तो एक मजबूत baseline देतो, आणि पुढच्या chapter मधलं TF-IDF त्याला अजून smart बनवतं.
Ravindra Bagale's Tip – हिंदी
Bag-of-words सिर्फ words गिनता है, जैसे basket में रखी चीज़ें गिनते हैं, और उनका क्रम (order) नहीं देखता. इसलिए "not good" जैसा phrase उसके लिए मुश्किल case है. फिर भी tickets को tag करने जैसे कई कामों के लिए यह एक मज़बूत baseline देता है, और अगले chapter का TF-IDF इसे और smart बनाता है.