(self, idx)
| 533 | return word |
| 534 | |
| 535 | def __getitem__(self, idx): |
| 536 | word = self.words[idx] |
| 537 | ix = self.encode(word) |
| 538 | x = torch.zeros(self.max_word_length + 1, dtype=torch.long) |
| 539 | y = torch.zeros(self.max_word_length + 1, dtype=torch.long) |
| 540 | x[1:1+len(ix)] = ix |
| 541 | y[:len(ix)] = ix |
| 542 | y[len(ix)+1:] = -1 # index -1 will mask the loss at the inactive locations |
| 543 | return x, y |
| 544 | |
| 545 | def create_datasets(input_file): |
| 546 |