words in the english language (which is what the vocabulary modelsstoring all those zeros would be prohibitiveand waste of memory to look at the actual content of the sparse matrixwe can convert it to "densenumpy array (that also stores all the entriesusing the toarray method: in[ ]print("dense representation of bag_of_words:\ {}formatbag_of_words toarray())out[ ]dense representation of bag_of_words[[ [ ]we can see that the word counts for each word are either or neither of the two strings in bards_words contains word twice let' take look at how to read these feature vectors the first string ("the fool doth think he is wise,"is represented as the first row inand it contains the first word in the vocabulary"be"zero times it also contains the second word in the vocabulary"but"zero times it contains the third word"doth"onceand so on looking at both rowswe can see that the fourth word"fool"the tenth word"the"and the thirteenth word"wise"appear in both strings bag-of-words for movie reviews now that we've gone through the bag-of-words process in detaillet' apply it to our task of sentiment analysis for movie reviews earlierwe loaded our training and test data from the imdb reviews into lists of strings (text_train and text_test)which we will now processin[ ]vect countvectorizer(fit(text_trainx_train vect transform(text_trainprint("x_train:\ {}format(repr(x_train))out[ ]x_trainwith stored elements in compressed sparse row format this is possible because we are using small toy dataset that contains only words for any real datasetthis would result in memoryerror working with text data