This line of code creates a tensor containing the corresponding weight value for each sample.
While weights has the shape [num_classes], sample_weights has [num_samples] containing [weights[y0], weights[y1], ...].