human
Write me a the Python code you requested given the following:
I am working on the file ".ipynb_checkpoints/jpx-tokyo-simple-lstm-network-scuec-checkpoint.ipynb".
The first task is:
Use Pytorch dataloader to recall data for each mini-batch.
Can you write Python code for it?
assistant
#Here is the Python code you requested.

from torch.utils.data.sampler import SubsetRandomSampler

class MyDataset(torch.utils.data.Dataset):
    def __init__(self, X, sequence_num=31, y=None, mode='train'):
        self.data = X
        self.teacher = y
        self.sequence_num = sequence_num
        self.mode = mode
    
    def __len__(self):
        return len(self.teacher)

    def __getitem__(self, idx):
        out_data = self.data[idx]
        if self.mode == 'train':
            out_label = self.teacher[idx[-1]]
            return out_data, out_label
        else:
            return out_data

        
def create_dataloader(dataset, dataset_num, sequence_num=31, input_size=8, batch_size=32, shuffle=False):
    sampler = np.array([list(range(i, i+sequence_num)) for i in range(dataset_num-sequence_num+1)])
    if shuffle is True:
        np.random.shuffle(sampler)
    dataloader = torch.utils.data.DataLoader(dataset, batch_size, sampler=sampler)
    return dataloader

test_df.loc[test_df['Date'] == "2021-12-06"]