import torch


def encode_labels(y, labels):
    """
    Convert string labels to autoincrementing integers.
    """
    mapping = {l: i for i, l in enumerate(labels)}
    return torch.as_tensor([mapping[l] for l in y])