MCPcopy
hub / github.com/hunkim/PyTorchZeroToAll / TextDataset

Class TextDataset

text_loader.py:8–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class TextDataset(Dataset):
9 # Initialize your data, download, etc.
10
11 def __init__(self, filename="./data/shakespeare.txt.gz"):
12 self.len = 0
13 with gzip.open(filename, 'rt') as f:
14 self.targetLines = [x.strip() for x in f if x.strip()]
15 self.srcLines = [x.lower().replace(' ', '')
16 for x in self.targetLines]
17 self.len = len(self.srcLines)
18
19 def __getitem__(self, index):
20 return self.srcLines[index], self.targetLines[index]
21
22 def __len__(self):
23 return self.len
24
25
26# Test the loader

Callers 4

13_3_char_rnn.pyFile · 0.90
14_1_seq2seq.pyFile · 0.90
text_loader.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected