mistral_common.guidance.tokenizer
MistralLLGTokenizer(tokenizer)
Wraps a Tekken tokenizer for use with llguidance.
Adapts Mistral special tokens ([...]) to the angle-bracket format (<...>) llguidance expects, and exposes the vocabulary as byte strings.
Special token strings in square brackets ([INST]) are converted to
angle brackets (
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
Tokenizer
|
The Tekken tokenizer to wrap for llguidance compatibility. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the tokenizer is not a Tekkenizer. |
ValueError
|
If a special token has an invalid format or is duplicated, or the special token count is inconsistent. |
Source code in src/mistral_common/guidance/tokenizer.py
bos_token_id
property
The beginning-of-string token ID.
eos_token_id
property
The end-of-string token ID.
special_token_ids
property
The IDs of all special tokens.
tokens
property
from_mistral_tokenizer(tokenizer)
Creates an llguidance tokenizer from a Mistral tokenizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
MistralTokenizer
|
The Mistral tokenizer to convert. Must wrap a Tekkenizer. |
required |
Returns:
| Type | Description |
|---|---|
LLTokenizer
|
The llguidance tokenizer. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the underlying tokenizer is not a Tekkenizer. |