Encodes text corresponding to a single token to its token value. NOTE: this will encode all special tokens. Raises `KeyError` if the token is not in the vocabulary. ``` >>> enc.encode_single_token("hello") 31373 ```
(self, text_or_bytes: str | bytes)
| 243 | return self._core_bpe.encode_with_unstable(text, allowed_special) |
| 244 | |
| 245 | def encode_single_token(self, text_or_bytes: str | bytes) -> int: |
| 246 | """Encodes text corresponding to a single token to its token value. |
| 247 | |
| 248 | NOTE: this will encode all special tokens. |
| 249 | |
| 250 | Raises `KeyError` if the token is not in the vocabulary. |
| 251 | |
| 252 | ``` |
| 253 | >>> enc.encode_single_token("hello") |
| 254 | 31373 |
| 255 | ``` |
| 256 | """ |
| 257 | if isinstance(text_or_bytes, str): |
| 258 | text_or_bytes = text_or_bytes.encode("utf-8") |
| 259 | return self._core_bpe.encode_single_token(text_or_bytes) |
| 260 | |
| 261 | # ==================== |
| 262 | # Decoding |