(self, model_path: str)
| 12 | |
| 13 | class Tokenizer: |
| 14 | def __init__(self, model_path: str): |
| 15 | # reload tokenizer |
| 16 | assert os.path.isfile(model_path), model_path |
| 17 | self.sp_model = SentencePieceProcessor(model_file=model_path) |
| 18 | logger.info(f"Reloaded SentencePiece model from {model_path}") |
| 19 | |
| 20 | # BOS / EOS token IDs |
| 21 | self.n_words: int = self.sp_model.vocab_size() |
| 22 | self.bos_id: int = self.sp_model.bos_id() |
| 23 | self.eos_id: int = self.sp_model.eos_id() |
| 24 | self.pad_id: int = self.sp_model.pad_id() |
| 25 | logger.info( |
| 26 | f"#words: {self.n_words} - BOS ID: {self.bos_id} - EOS ID: {self.eos_id}" |
| 27 | ) |
| 28 | assert self.sp_model.vocab_size() == self.sp_model.get_piece_size() |
| 29 | |
| 30 | def encode(self, s: str, bos: bool, eos: bool) -> List[int]: |
| 31 | assert type(s) is str |
nothing calls this directly
no outgoing calls
no test coverage detected