torch.eye(num_classes) will create a tensor in the shape [num_classes, num_classes] with 1s in its diagonal. [targs.squeeze(1)] will then index this tensor “row-wise” and return the one-hot encoded tensor.
You would get the same output using F.one_hot(targs, num_classes=num_classes).
To dig into the indexing using multiple dimensions, check this example code snippet:
a = torch.arange(10)
b = torch.randint(0, 10, (16,))

# index with "flat" dimension
out_b = a[b]

# index with multiple dimensions
c = b.view(2, 2, 2, 2)
out_c = a[c]

# compare
print((out_b == out_c.view(-1)).all())
> tensor(True)