import torch


def int_to_one_hot(class_labels, nb_classes, device, soft_target=1.):
    """ Convert tensor containing a batch of class indexes (int) to a tensor
    containing one hot vectors."""
    one_hot_tensor = torch.zeros((class_labels.shape[0], nb_classes),
                                 device=device)
    for i in range(class_labels.shape[0]):
        one_hot_tensor[i, class_labels[i]] = soft_target

    return one_hot_tensor