Archived
core/text: added (non-special) tokens go through the decoder chain, as in HuggingFace
Gemma's tokenizer.json spells runs of 2-31 spaces as added, non-special tokens in U+2581 (ids 138-167). piece_at returned every user-defined token literally, so indentation and double spaces in a Gemma reply came out as U+2581. HuggingFace runs every token it keeps through the decoder; now a user-defined token does too, and only control and unknown tokens stay literal. decode, the Detokenizer and TokenView change together. tokenizer_test covers it with a Gemma-shaped tokenizer.json. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f10c8521cd
commit
df030c7483
2 files changed
+35
-3
No files matched your search
@@ -1470,9 +1470,10 @@ std::string Tokenizer::piece_at(int32_t id, bool render_special, At at) const {
|
||||
if (b >= 0) return std::string(1, (char)b);
|
||||
|
||||
std::string s = v_->text(id);
|
||||
/* User-defined and control tokens are stored as literal text; only normal tokens are in the
|
||||
* vocab's own encoding and need the decoder chain. */
|
||||
if (t == RAD_TT_CONTROL || t == RAD_TT_UNKNOWN || t == RAD_TT_USER_DEFINED) return s;
|
||||
/* Control tokens are stored as literal text. A user-defined (added, non-special) token goes
|
||||
* through the decoder chain like a normal one, as HuggingFace decodes every token it keeps:
|
||||
* Gemma's whitespace runs are added tokens spelled in U+2581 ("\u2581\u2581" is two spaces). */
|
||||
if (t == RAD_TT_CONTROL || t == RAD_TT_UNKNOWN) return s;
|
||||
|
||||
/* No declared decoder means the tokens are already text (true for unigram and wordpiece, not
|
||||
* byte-level BPE). rad-convert emits the chain it read, so the absence is declared. */
|
||||
|
||||
Reference in new issue
Block a user