Exercise

Creating one-hot encoded labels

One-hot encoding is a technique that turns a single integer label into a vector of N elements, where N is the number of classes in your dataset. This vector only contains zeros and ones. In this exercise, you'll create the one-hot encoded vector of the label y provided.

You'll practice doing this manually, and then make your life easier by leveraging the help of PyTorch! Your dataset contains three classes.

NumPy is already imported as np, and torch.nn.functional as F. The torch package is also imported.

Instructions

100 XP
  • Manually create a one-hot encoded vector of the ground truth label y by filling in the NumPy array provided.
  • Create a one-hot encoded vector of the ground truth label y using PyTorch.