52. Text Cleaning and TF-IDF in Python
52.4 Inspect Vocabulary and Rows
52.4 Vocabulary आणि rows inspect करा
Sparse matrix + vocabulary बघितलं की debugging कमी scary.
हे का शिकायचं?
Why. Sparse matrix आणि vocabulary बघितलं की model “चुकीचे words बघतोय” तेव्हा debugging कमी scary.
हे काय आहे?
What. TfidfVectorizer sparse matrix देतो. Tiny demos वरच .toarray(). Bigrams आणि cleaning confirm करायला get_feature_names_out().
कसं करायचं?
How.
Model काय बघेल ते inspect
- Tiny train list वर fit.
- Feature names print.
- एका row चे weights print (rounded).
- Confirm test uses
transform, not a secondfit.
from sklearn.feature_extraction.text import TfidfVectorizer
train = ["fresh pedha good", "sour dahi bad", "fresh dahi good"]
test = ["fresh pedha bad"]
vec = TfidfVectorizer(ngram_range=(1, 2))
Xtr = vec.fit_transform(train)
Xte = vec.transform(test)
print(vec.get_feature_names_out())
print("test row:", Xte.toarray().round(2))