(self, s: str, bos: bool, eos: bool)
| 19 | |
| 20 | |
| 21 | def encode(self, s: str, bos: bool, eos: bool) -> List[int]: |
| 22 | assert type(s) is str |
| 23 | t = self.tokenizer.encode(s) |
| 24 | while t[0] == self.bos_id: |
| 25 | t = t[1:] |
| 26 | while t[-1] == self.eos_id: |
| 27 | t = t[:-1] |
| 28 | |
| 29 | if bos and self.bos_id is not None: |
| 30 | t = [self.bos_id] + t |
| 31 | if eos and self.eos_id is not None: |
| 32 | t = t + [self.eos_id] |
| 33 | return t |
| 34 | |
| 35 | def decode(self, t: List[int]) -> str: |
| 36 | return self.tokenizer.decode(t) |