1. Learn
  2. /
  3. Courses
  4. /
  5. Deep Learning for Text with PyTorch

Exercise

Bag-of-words for book titles

PyBooks now has a list of book titles that need to be encoded for further analysis. The data team believes the Bag of Words (BoW) model could be the best approach.

The following packages have been imported for you: torch, torchtext.

Instructions

100 XP
  • Import the CountVectorizer class for implementing bag-of-words.
  • Initialize an object of the class you imported, then use this object to transform the titles into a matrix representation.
  • Extract and display the first five feature names and encoded titles with the get_feature_names_out() method.