Here is the whole code to generate data
class MyDataset(Dataset):
    def __init__(self, data, targets):
        self.data = torch.from_numpy(data).type(torch.float)
        self.targets = targets

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

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

def numpy_to_dataloader(data, targets, batch_size = 50, validation_split = .2, shuffle_dataset = True):
    
    random_seed= 42
    data = data
    targets = targets
    dataset = MyDataset(data, targets)
    


    dataset_size = len(dataset)
    indices = list(range(dataset_size))
    split = int(np.floor(validation_split * dataset_size))
    if shuffle_dataset :
        np.random.seed(random_seed)
        np.random.shuffle(indices)
    train_indices, val_indices = indices[split:], indices[:split]


    train_sampler = SubsetRandomSampler(train_indices)
    valid_sampler = SubsetRandomSampler(val_indices)

    train_loader = torch.utils.data.DataLoader(dataset, batch_size=batch_size, 
                                               sampler=train_sampler)
    validation_loader = torch.utils.data.DataLoader(dataset, batch_size=batch_size,
                                                    sampler=valid_sampler)
    
    return train_loader, validation_loader

dummy data and run the model

X = torch.randn(30, 20)
y = torch.randint(2, (30, ))
train_loader, valid_loader = numpy_to_dataloader(X, y, batch_size = 20, validation_split = .2, shuffle_dataset = True)
net, train_loss, train_accuracy, val_loss, val_accuracy = train(train_loader,  valid_loader, lr=0.0001, epochs=10,  hidden_units=64, net='RNN')