| 203 | |
| 204 | # How to tokenize a text sample to a token sample |
| 205 | def _tokenize(self, text_sample): |
| 206 | if self.tokenizer._pad_token is None: |
| 207 | # Some tokenizers (e.g. GPT2 tokenizer) have no padding token which causes bugs |
| 208 | raise RuntimeError("If tokenizing on-the-fly, tokenizer must have a pad_token_id") |
| 209 | |
| 210 | return self.tokenizer(text_sample["text"], truncation=True, padding="max_length", max_length=self.max_seq_len) |
| 211 | |
| 212 | def _read_binary_tokenized_sample(self, sample: BatchEncoding): |
| 213 | seq_len = sample["len"] if "len" in sample else len(sample["input_ids"]) |