1. 学习
  2. /
  3. 课程
  4. /
  5. Deep Learning for Text with PyTorch

Connected

练习

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.

说明

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.