Executing the count vectorizer

The following are the steps for executing the CountVectorizer:

  1. Import the library required for the count vectorizer:
from sklearn.feature_extraction.text import CountVectorizer
  1. Make a list of the text:
text = [" Machine translation automatically translate text from one human language to another text"]
  1. Tokenize the list of the text and build the vocabulary:
vectorizer.fit(text)

You will get the following output:

  1. Let's take a look at the vocabulary that was created:
print(vectorizer.vocabulary_)

We get the following output:

  1. Now, we have to encode it, as follows:
vector = vectorizer.transform(text)
  1. Let's get a summary of the vector and find out the term matrix:
print(type(vector))
print(vector.toarray())

We get the following output:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.71.28