Hello, I am working with DataLoader for the first time and have some problems.
I have my data in json file like {“doc_id_1”: [sentence1, sentence2, …], …} and want to create a DataLoader with these data to get then a sentence embedding. The problem is that, there are no labels (doc_id is not a true label, it is just the id of the document).
I have defined the class straightforward like in the example above:
class DocDataset(Dataset):
    def __init__(self, json_file):
        self.data = json.load(open(json_file))

    def __getitem__(self, index):
        x = self.data[index]
        return x

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

json_file = 'dataset.json'
dataset = DocDataset(json_file)
loader = DataLoader(dataset, batch_size=5, num_workers=2, shuffle=True)

I might have a problem in getitem function, because I have a “KeyError”.
Thank you an advance!