from sklearn.feature_extraction.text import CountVectorizer# list of text documentstext = ["The quick brown fox jumped over the lazy dog."]# create the transformvectorizer = CountVectorizer()# tokenize and build vocabvectorizer.fit(text)# summarizeprint(vectorizer.vocabulary_)# encode documentvector = vectorizer.transform(text)# summarize encoded vectorprint(vector.shape)print(type(vector))print(vector.toarray())
-- | --
from sklearn.feature_extraction.text import CountVectorizer# list of text documentstext = ["The quick brown fox jumped over the lazy dog."]# create the transformvectorizer = CountVectorizer()# tokenize and build vocabvectorizer.fit(text)# summarizeprint(vectorizer.vocabulary_)# encode documentvector = vectorizer.transform(text)# summarize encoded vectorprint(vector.shape)print(type(vector))print(vector.toarray())
-- | --