Skip to content

Lstmdataloader

Bases: pl.LightningDataModule

Data loader for the LSTM model.

Initialize the data loader.

Parameters:

Name Type Description Default
train_sequences List[Tuple[pd.DataFrame, float]]

List of training sequences.

required
val_sequences List[Tuple[pd.DataFrame, float]]

List of validation sequences.

required
test_sequences List[Tuple[pd.DataFrame, float]]

List of test sequences.

required
train_batch_size int

Batch size for training.

required
val_batch_size int

Batch size for validation.

required
train_workers int

Number of workers for training.

2
val_workers int

Number of workers for validation.

1
Source code in make_us_rich/pipelines/training/dataloader.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def __init__(self,
    train_sequences: List[Tuple[pd.DataFrame, float]],
    val_sequences: List[Tuple[pd.DataFrame, float]],
    test_sequences: List[Tuple[pd.DataFrame, float]],
    train_batch_size: int,
    val_batch_size: int,
    train_workers: int = 2,
    val_workers: int = 1,
):
    """
    Initialize the data loader.

    Parameters
    ----------
    train_sequences: List[Tuple[pd.DataFrame, float]]
        List of training sequences.
    val_sequences: List[Tuple[pd.DataFrame, float]]
        List of validation sequences.
    test_sequences: List[Tuple[pd.DataFrame, float]]
        List of test sequences.
    train_batch_size: int
        Batch size for training.
    val_batch_size: int
        Batch size for validation.
    train_workers: int
        Number of workers for training.
    val_workers: int
        Number of workers for validation.
    """
    super().__init__()
    self.train_sequences = train_sequences
    self.val_sequences = val_sequences
    self.test_sequences = test_sequences
    self.train_batch_size = train_batch_size
    self.val_batch_size = val_batch_size
    self.train_workers = train_workers
    self.val_workers = val_workers
    self.test_workers = val_workers

setup(stage=None)

Load the data.

Parameters:

Name Type Description Default
stage str

Name of the stage.

None
Source code in make_us_rich/pipelines/training/dataloader.py
54
55
56
57
58
59
60
61
62
63
64
65
def setup(self, stage: str = None) -> None:
    """
    Load the data.

    Parameters
    ----------
    stage: str
        Name of the stage. 
    """
    self.train_dataset = CryptoDataset(self.train_sequences)
    self.val_dataset = CryptoDataset(self.val_sequences)
    self.test_dataset = CryptoDataset(self.test_sequences)

test_dataloader()

Return the test data loader.

Source code in make_us_rich/pipelines/training/dataloader.py
88
89
90
91
92
93
94
95
def test_dataloader(self):
    """Return the test data loader."""
    return DataLoader(
        self.test_dataset, 
        batch_size=self.val_batch_size, 
        shuffle=False,
        num_workers=self.test_workers
    )

train_dataloader()

Return the training data loader.

Source code in make_us_rich/pipelines/training/dataloader.py
68
69
70
71
72
73
74
75
def train_dataloader(self):
    """Return the training data loader."""
    return DataLoader(
        self.train_dataset, 
        batch_size=self.train_batch_size, 
        shuffle=False,
        num_workers=self.train_workers
    )

val_dataloader()

Return the validation data loader.

Source code in make_us_rich/pipelines/training/dataloader.py
78
79
80
81
82
83
84
85
def val_dataloader(self):
    """Return the validation data loader."""
    return DataLoader(
        self.val_dataset, 
        batch_size=self.val_batch_size, 
        shuffle=False,
        num_workers=self.val_workers
    )

Last update: 2022-05-04