|
|
@@ -16,14 +16,10 @@ class PretrainDataset(Dataset):
|
|
|
|
|
|
def __getitem__(self, index):
|
|
|
sample = self.samples[index]
|
|
|
- encoding = self.tokenizer(
|
|
|
- str(sample['text']),
|
|
|
- max_length=self.max_length,
|
|
|
- padding='max_length',
|
|
|
- truncation=True,
|
|
|
- return_tensors='pt'
|
|
|
- )
|
|
|
- input_ids = encoding.input_ids.squeeze()
|
|
|
+ tokens = self.tokenizer(str(sample['text']), add_special_tokens=False).input_ids
|
|
|
+ tokens = [self.tokenizer.bos_token_id] + tokens[:self.max_length - 2] + [self.tokenizer.eos_token_id]
|
|
|
+ input_ids = tokens + [self.tokenizer.pad_token_id] * (self.max_length - len(tokens))
|
|
|
+ input_ids = torch.tensor(input_ids, dtype=torch.long)
|
|
|
labels = input_ids.clone()
|
|
|
labels[input_ids == self.tokenizer.pad_token_id] = -100
|
|
|
return input_ids, labels
|