Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stripedhyena/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def decode_token(self, token: int):
return str(chr(self.clamp(token)))

def tokenize(self, text: str):
return list(np.fromstring(text, dtype=np.uint8))
return list(np.frombuffer(text.encode(), dtype=np.uint8))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UTF-8 encoding breaks tokenize/detokenize round-trip for non-ASCII

Low Severity

text.encode() defaults to UTF-8, which produces multi-byte sequences for characters with code points 128–255. The old np.fromstring implicitly used Latin-1 encoding (one byte per character). Since detokenize reconstructs text by calling chr() on each individual token, detokenize(tokenize(text)) will return garbled output for any non-ASCII input. Using text.encode('latin-1') would preserve the original 1:1 character-to-token mapping that detokenize expects.

Additional Locations (1)

Fix in Cursor Fix in Web


def tokenize_batch(self, text_batch: Union[List[str], str]):
if isinstance(text_batch, list):
Expand Down
Loading