# create a count vectorizer object
count_vectorizer = CountVectorizer()
# fit the count vectorizer using the text data
count_vectorizer.fit(data['text'])
# collect the vocabulary items used in the vectorizer
dictionary = count_vectorizer.vocabulary_.items()
To my understanding, after count_vectorizer
fits to data['text']
, it generates a list of features. In my case, it generated 25,257
features and these are mapped as dict
data type when I call count_vectorizer.vocabulary_
. Which is still 25,257
tuples. It means, it used all the features.
Problem is, when I call count_vectorizer.vocabulary_.items()
it returns 15,142
tuples as dict_items
. Why the number has been reduced here? Should't all the features be used to make the dictionary
?
Here are the lengths I'm talking about:
len(data['text']) #19579
len(count_vectorizer.get_feature_names()) #25257 items
len(count_vectorizer.vocabulary_) #25257 items
len(dictionary) #15142 items (??????)
len(my_dict)
not equal tolen(my_dict.items())
??? $\endgroup$