Transformers
PyTorch
text2text-generation
cidcodes commited on
Commit
692bfc0
·
verified ·
1 Parent(s): 0de9394

Regenerate the tokenizer.json pipeline from spiece.model

Browse files

`spiece.model` keeps whitespace (`remove_extra_whitespaces: false`) and uses byte fallback, but `tokenizer.json` collapses repeated spaces and has `byte_fallback: false`, and `transformers` v5 additionally rebuilds the T5 pipeline with a whitespace split. Tabs and newlines are lost:

| text | `spiece.model` | current (`transformers` v5) | with this PR |
|---|---|---|---|
| `a\tb` | `▁a`, `<0x09>`, `b` | `▁a`, `▁b` | `▁a`, `<0x09>`, `b` |
| `line one\nline two` | `▁line`, `▁one`, `<0x0A>`, `line`, `▁two` | `▁line`, `▁one`, `▁line`, `▁two` | `▁line`, `▁one`, `<0x0A>`, `line`, `▁two` |
| `two spaces` | `▁two`, `▁`, `▁spaces` | `▁two`, `▁spaces` | `▁two`, `▁`, `▁spaces` |

This PR replaces the normalizer, pre-tokenizer and decoder in `tokenizer.json` with the ones `transformers` generates from `spiece.model`, turns on `byte_fallback`, and sets `"tokenizer_class": "TokenizersBackend"` in `tokenizer_config.json`, as suggested by the transformers maintainers in huggingface/transformers#51269. The vocabulary, the `<extra_id_*>` tokens and the post-processor are unchanged, so token ids do not move.

One deliberate difference from `spiece.model`: text right after a special token such as `<extra_id_0>` gets no extra `▁`, which keeps today's behavior for span-corruption style inputs.

I checked it on 33,013 texts (FLORES-200 sentences in 205 languages, Hindi/Malayalam code-mixed text, and Unicode edge cases): the texts that tokenize differently from `spiece.model` go from 5,102 to 39 (the remaining ones mostly start with whitespace), and decoding matches SentencePiece on all of them. `</s>` is still appended, and the special tokens are unchanged.

Files changed (2) hide show
  1. tokenizer.json +2 -2
  2. tokenizer_config.json +1 -1
tokenizer.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:af904105ce1071b1202bba0059a841f4a7b85b48b6ec179c4948e3483476e0dd
3
- size 16853013
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c081db4f20202314f3336148e556cbadd32adc4a9649ce34a0415bcb48dbdffb
3
+ size 16853695
tokenizer_config.json CHANGED
@@ -309,6 +309,6 @@
309
  "pad_token": "<pad>",
310
  "sp_model_kwargs": {},
311
  "spaces_between_special_tokens": false,
312
- "tokenizer_class": "T5Tokenizer",
313
  "unk_token": "<unk>"
314
  }
 
309
  "pad_token": "<pad>",
310
  "sp_model_kwargs": {},
311
  "spaces_between_special_tokens": false,
312
+ "tokenizer_class": "TokenizersBackend",
313
  "unk_token": "<unk>"
314
  }