concept Words model in category machine learning

This is an excerpt from Manning's book Machine Learning with TensorFlow, Second Edition.
The challenge with the input in this case is that it’s text and not some nice input vector of numbers like the randomly generated data points that our trusty NumPy library generated for us last chapter. Lucky for you the text and information retrieval community has developed a technique to handle mapping text to a numerical feature vector perfect for machine learning called the Bag of Words model. Let’s learn about it next.
6.1 The Bag of Words model
The Bag of Words model is a method from natural language processing (NLP) that takes as input text in the form of a sentence and turns it into a feature vector by considering the extracted vocabulary words and the frequency of their occurrence. Named such because each word frequency count is like a “bag,” with each occurrence of a word as an item in that bag, the Bag of Words model is a state-of-the-art method to take, for example, a review of a movie and convert it into a feature vector, which you will need to classify its sentiment. Consider the following review snippet text written about a recent Michael Jackson movie:
With all this stuff going down at the moment with MJ i've started listening to his music, watching the odd documentary here and there, watched The Wiz and watched Moonwalker again.The first step in applying the Bag of Words model to processing this review is to preprocess the text and extract only the words with actual meaning. This usually means that you remove any non-letter character such as numbers or additional annotations, including HTML tags, or apostrophes, and generally strip the text down to its bare words. After that, the approach reduces the remaining words in the subset to those that are nouns or verbs or adjectives, and takes out articles, conjunctions, and other stop-words or words that are not distinguishing features of the text itself.
Once that step is complete, the Bag of Words model generates a count histogram of the remaining vocabulary words and that histogram becomes the fingerprint for the input text. Oftentimes the fingerprint is normalized by dividing the counts by the max count, resulting in a feature vector of values between 0 and 1. The whole process is shown in figure 6.1.
Figure 6.1 A visual depiction of the Bag of Words model. Text is analyzed, cleaned, and words are counted to form a histogram, which is then normalized to obtain a feature vector representation of the input text.
![]()