neuralpat:

class NameDataset(Dataset):

    def __init__(self):
        self.names = []
        self.labels = []

        for name in all_names:
            self.names.append(encode_name(name))

        for label in all_labels:
            self.labels.append(encode_label(label))

    def __len__(self):
        return len(self.names)

    def __getitem__(self, index):
        name = self.names[index]
        label = all_labels[index]
        return name, label



Ok, I did not notice this before but this is not a good way of consructing a dataset. You are accessing all_names and all_labels from outside of this class without passing any argument that refers to them. Try to make dataset construction standalone by just giving a path, etc.
On the other side, you are using label=all_labels[index] in __getitem__ instead of self.labels[index]. Although these issues are not directly related to PyTorch but makes your debugging easier.