1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Deep Learning with PyTorch

Connected

Exercise

Creating one-hot encoded labels

One-hot encoding converts a single integer label into a vector with N elements, where N is the number of classes. This vector contains zeros and a one at the correct position.

In this exercise, you'll manually create a one-hot encoded vector for y, and then use PyTorch to simplify the process. Your dataset has three classes (0, 1, 2).

numpy (np), torch.nn.functional (F), and torch are already imported for you.

Instructions

100 XP
  • Manually one-hot encode the ground truth label y using the provided NumPy array and save it as one_hot_numpy.
  • Use PyTorch to one-hot encode y and save it as one_hot_pytorch.