Downloads · 30 days
0
soda-research/marin-mimi-bpe-8cb-16k-tokenizer
marin-mimi-bpe-8cb-16k-tokenizer is a machine learning model from soda-research. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This tokenizer extends the stanford-crfm/marin-tokenizer with audio tokens (8-codebook Mimi tokens) and new special tokens.
Downloads · 30 days
0
Access
Public
Updated Oct 9, 2025
Repo size
20.2 MB
Likes
1
Public
Click a slice to open those files.
.json23 MB · 100%
From the Hugging Face model README
This tokenizer extends the stanford-crfm/marin-tokenizer with audio tokens (8-codebook Mimi tokens) and new special tokens.
<|text_start|>, <|text_end|>, <|audio_start|>, <|audio_end|>This tokenizer is meant to be used with raw text (readable) and unicode string of audio tokens (not readable). For example,
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("potsawee/marin-mimi-bpe-8cb-16k-tokenizer")
interleaved_str = "<|begin_of_text|><|audio_start|>ﶮ𑅆𐄋𐨫𑊚﵄𐅔𑌳𑨸𐰆𐹴𑿘𐰆𑀫𑨸𐛈𑌹𑿘說𐐫𑌳𐅔覆𐰩𑗖勒𐎜𐰥𑵿ᅣ𑇗v𐎃𐕀𑒈𑴅𐮍𑗗﹥𐊾𐭫𐲧𑜃𑤀隷ﱭ𑧄簾𐎧𐺝𑀭𐪋𑛂ﴯ𐆠𐭮𑚖﹃𐘿𑇭𑱼﷿𐀈𐠌𑂅怒𐬊𑙐𑨗ﵳ𐇢𐾉𑛈𑤝ﵳ𐔵𐚭ﳫ𐫗𑚷𑱻酪𐑍𑌬𑤑サ𐒧𑊛句𐏏𑛂ﰉ𐝀𑰘𐓑𐭘𑰅ﵵ𐜞𐿪𑑂﹃𐰯𑇐ﻝ𐰙𑊔𑰡ﱠ𐄼𐾉𑄓𑰦陼𐔱𐤖𑜃゚𑲮索𐊃𑐆ﰭ𐙯𑨏賂𐂗𐧯𑌐ﮅ𑫗;𐌿𑀴𑊃𑩽稜𐎆𐇶𑤱ﴂ𐞮𑘠ᄆ𐫌𑒬ﹽ𑝅𑱖籠𑤑聾𐛣𐧭𑋷稜ﻫ𑙑𐒅𐦖𑚔﮳𐂜𑍢𑱦9𐴷𐛲𑐨;𐞅𐦯𑈨𑰽9𑂷︘𐞢𐡝𑆤𑠏ﯛ𐎫𑋪𑴗︷𐚍𑋂韛𐌵𐮀ﲹ𐾷𑜴𑰫ﺕ𐒱𐩆𑇣𑶩𐒱𐋹𑊥﮺𑒛ᅵ𐀨𐤒𑫳ᄄ𐂑𐲚𑈈x𐎷𑐛𑨶𐹮𑆮𑪸ﶓ𑘁𑵓變𐞐𐪑𑑟ﮎ𐎶摒𐎲𐧞𑓖𑵱諸𐄋𑌹諸𐄋𐣣𑿘﵄𐇡𐰫𑌳ﶪ𐛈𐧞𑆬虜𑤓<|audio_end|><|text_start|>I've also been taught to understand and produce paralinguistic things like sighing, chuckling, or yawning<|text_end|><|end_of_text|>"
tokens = tokenizer(interleaved_str)
Note that each character in the Unicode string corresponds to one audio token (flattened from 8 codebooks), and we apply a unicode offset 0xE000 so that unicodes for audio tokens stay within Private Use Area (i.e., not yet assigned to any other character).
UNICODE_OFFSET = 0xE000
def chars_to_codes(
chars: str,
num_codebooks: int,
codebook_size: int,
return_tensors: Optional[str] = None,
unicode_offset: int = UNICODE_OFFSET,
) -> Union[List[List[int]], np.ndarray, torch.Tensor]:
codes = np.array([ord(c) for c in chars])
codes = codes.reshape(-1, num_codebooks).T
for i in range(codes.shape[0]):
codes[i] -= unicode_offset + i*codebook_size
if return_tensors is None:
codes = codes.tolist()
elif return_tensors == "pt":
codes = torch.tensor(codes)
return codes
def codes_to_chars(
codes: Union[List[List[int]], np.ndarray, torch.Tensor],
codebook_size: int,
copy_before_conversion: bool = True,
unicode_offset: int = UNICODE_OFFSET,
) -> str:
if isinstance(codes, list):
codes = np.array(codes)
copy_before_conversion = False
elif isinstance(codes, torch.Tensor):
codes = codes.cpu().numpy()
if len(codes.shape) != 2:
raise ValueError("codes must be a 2D array of shape (num_codebooks, seq_length).")
if copy_before_conversion:
codes = codes.copy()
for i in range(codes.shape[0]):
codes[i] += unicode_offset + i*codebook_size
codes = codes.T.reshape(-1)
chars = "".join([chr(c) for c in codes])
return chars
Adapted from https://github.com/AbrahamSanders/codec-bpe
To get back the audio waveform from the codes, you can use the following code:
from transformers import MimiModel
model = MimiModel.from_pretrained("kyutai/mimi")
# audio_str is the unicode string of audio tokens (i.e., characters with <|audio_start|> and <|audio_end|>)
codes = chars_to_codes(audio_str, num_codebooks=8, codebook_size=2048, return_tensors="pt").unsqueeze(0)
with torch.no_grad():
audio_decoded = model.decode(codes).audio_values[0]