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