There's more...

It is worth mentioning the motivation behind limiting the sentence's (or text) size. In this example, we limited the text size to 25 words. This is a common practice with bag-of-words because it limits the effect of text length on the prediction. As you can imagine, if we find a word, for example, meeting, that is predictive of a text being ham (not spam), then a spam message might get through by putting in many occurrences of that word at the end. In fact, this is a common problem with imbalanced target data. Imbalanced data might occur in this situation, since spam may be hard to find and ham may be easy to find. Because of this fact, the vocabulary that we create might be heavily skewed toward words represented in the ham ...

Get TensorFlow Machine Learning Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.