MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / BaseLlamaTokenizer

Class BaseLlamaTokenizer

llama_cpp/llama_tokenizer.py:14–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class BaseLlamaTokenizer(abc.ABC):
15 @abc.abstractmethod
16 def tokenize(
17 self, text: bytes, add_bos: bool = True, special: bool = True
18 ) -> List[int]:
19 """Tokenize the text into tokens.
20
21 Args:
22 text: The utf-8 encoded string to tokenize.
23 add_bos: Whether to add a beginning of sequence token.
24 special: Whether to tokenize special tokens.
25 """
26 raise NotImplementedError
27
28 @abc.abstractmethod
29 def detokenize(
30 self,
31 tokens: List[int],
32 prev_tokens: Optional[List[int]] = None,
33 special: bool = False,
34 ) -> bytes:
35 """Detokenize the tokens into text.
36
37 Args:
38 tokens: The list of tokens to detokenize.
39 prev_tokens: The list of previous tokens. Offset mapping will be performed if provided.
40 special: Whether to detokenize special tokens.
41 """
42 raise NotImplementedError
43
44
45class LlamaTokenizer(BaseLlamaTokenizer):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…