Decode tokens to string. Args: tokens: List of token IDs errors: How to handle decode errors ('replace', 'ignore', 'strict') Returns: Decoded string
(self, tokens: Sequence[int], errors: str = "replace")
| 274 | raise TokenDaggerError(f"Decoding failed: {e}") |
| 275 | |
| 276 | def decode(self, tokens: Sequence[int], errors: str = "replace") -> str: |
| 277 | """Decode tokens to string. |
| 278 | |
| 279 | Args: |
| 280 | tokens: List of token IDs |
| 281 | errors: How to handle decode errors ('replace', 'ignore', 'strict') |
| 282 | |
| 283 | Returns: |
| 284 | Decoded string |
| 285 | """ |
| 286 | try: |
| 287 | decoded_bytes = self.decode_bytes(tokens) |
| 288 | return decoded_bytes.decode("utf-8", errors=errors) |
| 289 | except Exception as e: |
| 290 | raise TokenDaggerError(f"Decoding failed: {e}") |
| 291 | |
| 292 | # ==================== |
| 293 | # Utility methods |