vdw:

train_iter = BucketDataset(X_train, y_train, lengths_train, batch_size)


To get your code to work I had to pass both the inputs, targets and lengths as np.arrays not as lists. Otherwise when __next__ tries to return the indexes I got the error: list indices must be integers or slices, not list because you can’t get multiple indices from a list.