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

Connected

Exercise

One-hot encoded book titles

PyBooks wants to catalog and analyze the book genres in its library. Apply one-hot encoding to a list of book genres to make them machine-readable.

torch has been imported for you.

Instructions

100 XP
  • Define the size of the vocabulary and save to vocab_size.
  • Create one-hot vectors using the appropriate torch technique and vocab_size.
  • Create a dictionary mapping genres to their corresponding one-hot vectors using dictionary comprehension; the dictionary keys should be the genre.