Instructions to use KateMajzel/tokenizer-pl-32k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use KateMajzel/tokenizer-pl-32k with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("KateMajzel/tokenizer-pl-32k", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -2,42 +2,161 @@
|
|
| 2 |
language:
|
| 3 |
- pl
|
| 4 |
license: mit
|
| 5 |
-
library_name:
|
| 6 |
tags:
|
| 7 |
-
- polish
|
| 8 |
- tokenizer
|
| 9 |
- bpe
|
| 10 |
-
- byte-level
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
# tokenizer-pl-32k
|
| 14 |
|
| 15 |
-
Byte-level BPE
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
Tokenizer wytrenowany na polskim korpusie i zwalidowany eksperymentalnie w projekcie
|
| 19 |
-
[gollem-pl](https://github.com/KateMajzel/gollem-pl) — kontrolowanej ablacji
|
| 20 |
-
|
| 21 |
|
| 22 |
-
Model wytrenowany z tym tokenizerem:
|
| 23 |
-
[KateMajzel/GoLLeM-45M-PL](https://huggingface.co/KateMajzel/GoLLeM-45M-PL).
|
| 24 |
|
| 25 |
## Gęstość
|
| 26 |
|
| 27 |
| | ten tokenizer | GPT-2 |
|
| 28 |
|---|---|---|
|
| 29 |
-
| bajty/token — korpus mieszany PL (2,96 GB) |
|
| 30 |
-
| bajty/token — held-out (2,77 MB) |
|
| 31 |
| tokenów z 2,96 GB tekstu | 731 mln | 1 434 mln |
|
| 32 |
-
|
|
| 33 |
|
| 34 |
-
Fertility na polskiej prozie: ~1,35 tokena na słowo (5,80 znaku/token).
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
z wyselekcjonowanych zdań.
|
| 38 |
|
| 39 |
-
Przykład różnicy w praktyce — słowo
|
| 40 |
-
u GPT-2.
|
| 41 |
|
| 42 |
## Właściwości
|
| 43 |
|
|
@@ -53,18 +172,18 @@ u GPT-2.
|
|
| 53 |
| tokeny „same białe znaki" dłuższe niż 2 zn. | 18 |
|
| 54 |
| tokeny czysto liczbowe | 409 |
|
| 55 |
|
| 56 |
-
Round-trip zweryfikowany m.in. na `Zażółć gęślą jaźń — «cytat» … 😀\ttab`
|
| 57 |
-
|
| 58 |
|
| 59 |
## Tokeny specjalne
|
| 60 |
|
| 61 |
-
`<|endoftext|>` (32568), `<|begin_of_text|>`, `<|pad|>`, `<|unk|>`, tokeny czatowe,
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
`bos_token_id = eos_token_id = 32568`.
|
| 69 |
|
| 70 |
## Użycie
|
|
@@ -89,32 +208,30 @@ Ablacja na modelach 42–51 M parametrów (3 GB korpusu, 3 ziarna losowe) wykaza
|
|
| 89 |
|
| 90 |
- **Przy równym budżecie tekstu tokenizer nie różnicuje jakości modelu.** Cztery
|
| 91 |
niezależne pomiary (BPB, PolEmo2, 8Tags, prywatny held-out) nie wykazały istotnej
|
| 92 |
-
różnicy wobec tokenizera GPT-2, a ich kierunki były niespójne. Różnica BPB między
|
| 93 |
-
|
| 94 |
-
(0,0124).
|
| 95 |
- **Przy równym budżecie obliczeniowym przewaga jest jednoznaczna** — 5,30% BPB
|
| 96 |
(6,4 odchylenia) na korzyść gęstszego tokenizera.
|
| 97 |
-
- **Zysk leży w koszcie:** ten sam poziom BPB osiągnięty w 2,5× krótszym czasie,
|
| 98 |
-
|
| 99 |
|
| 100 |
-
Ten sam wniosek uzyskał niezależnie zespół Bielika v3 PL na skali 11B
|
| 101 |
-
|
| 102 |
-
dedykowany zachowała jakość i niemal podwoiła gęstość reprezentacji.
|
| 103 |
|
| 104 |
## Ograniczenia
|
| 105 |
|
| 106 |
-
-
|
| 107 |
-
|
| 108 |
-
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
-
|
| 112 |
-
|
| 113 |
-
-
|
| 114 |
-
|
| 115 |
- **Koszt embeddingu.** Przy `d_model = 512` tablica embeddingów to 16,8 M parametrów.
|
| 116 |
-
W modelu 42,5 M stanowi to 40% — warto to policzyć, zanim dobierze się rozmiar
|
| 117 |
-
|
| 118 |
|
| 119 |
## Licencja i cytowanie
|
| 120 |
|
|
@@ -127,4 +244,4 @@ MIT. Metodologia i kod: https://github.com/KateMajzel/gollem-pl
|
|
| 127 |
year = {2026},
|
| 128 |
url = {https://huggingface.co/KateMajzel/tokenizer-pl-32k}
|
| 129 |
}
|
| 130 |
-
```
|
|
|
|
| 2 |
language:
|
| 3 |
- pl
|
| 4 |
license: mit
|
| 5 |
+
library_name: transformers
|
| 6 |
tags:
|
|
|
|
| 7 |
- tokenizer
|
| 8 |
- bpe
|
| 9 |
+
- byte-level-bpe
|
| 10 |
+
- polish
|
| 11 |
+
- tokenizer-ablation
|
| 12 |
+
- research
|
| 13 |
---
|
| 14 |
|
| 15 |
# tokenizer-pl-32k
|
| 16 |
|
| 17 |
+
Byte-level BPE for Polish. 32,568 vocabulary entries + 200 special tokens = 32,768
|
| 18 |
+
(2¹⁵, convenient for GPU kernels and tensor parallelism).
|
| 19 |
+
|
| 20 |
+
Trained on a Polish corpus and validated experimentally in the
|
| 21 |
+
[gollem-pl](https://github.com/KateMajzel/gollem-pl) project — a controlled ablation
|
| 22 |
+
comparing it against the GPT-2 tokenizer under an identical training budget.
|
| 23 |
+
|
| 24 |
+
Model trained with this tokenizer: [KateMajzel/GoLLeM-45M-PL](https://huggingface.co/KateMajzel/GoLLeM-45M-PL).
|
| 25 |
+
|
| 26 |
+
## Density
|
| 27 |
+
|
| 28 |
+
| | this tokenizer | GPT-2 |
|
| 29 |
+
|---|---|---|
|
| 30 |
+
| bytes/token — mixed PL corpus (2.96 GB) | 4.050 | 2.066 |
|
| 31 |
+
| bytes/token — held-out (2.77 MB) | 4.103 | 2.134 |
|
| 32 |
+
| tokens from 2.96 GB of text | 731M | 1,434M |
|
| 33 |
+
| relative density | **1.96×** | 1.00× |
|
| 34 |
+
|
| 35 |
+
Fertility on Polish prose: ~1.35 tokens per word (5.80 characters/token). Note: on a real
|
| 36 |
+
corpus — with URLs, numbers and leftover formatting — the figure comes out at 4.05
|
| 37 |
+
bytes/token, which is markedly worse. Fertility should be reported from a corpus, not from
|
| 38 |
+
hand-picked sentences.
|
| 39 |
+
|
| 40 |
+
A practical example of the difference: the word *niejednoznaczny* is 3 tokens here and 9
|
| 41 |
+
under GPT-2.
|
| 42 |
+
|
| 43 |
+
## Properties
|
| 44 |
+
|
| 45 |
+
| | |
|
| 46 |
+
|---|---|
|
| 47 |
+
| type | byte-level BPE (`tokenizers`, `tokenizer.json` format) |
|
| 48 |
+
| normalization | none — lossless round-trip |
|
| 49 |
+
| pre-tokenizer | GPT-4 style: `Isolated` + `ByteLevel(use_regex=false, add_prefix_space=false)` |
|
| 50 |
+
| digits | split into groups of at most 3 (`\p{N}{1,3}`) |
|
| 51 |
+
| `byte_fallback` | not needed (byte-level cannot produce UNK) |
|
| 52 |
+
| tokens with diacritics | 27.9% of the vocabulary |
|
| 53 |
+
| tokens unreachable through merges | 0 (256 bytes + 32,312 merges = 32,568) |
|
| 54 |
+
| whitespace-only tokens longer than 2 chars | 18 |
|
| 55 |
+
| purely numeric tokens | 409 |
|
| 56 |
+
|
| 57 |
+
Round-trip verified on, among others, `Zażółć gęślą jaźń — «cytat» … 😀\ttab`, as well as
|
| 58 |
+
repeated spaces and newlines.
|
| 59 |
+
|
| 60 |
+
## Special tokens
|
| 61 |
+
|
| 62 |
+
`<|endoftext|>` (32568), `<|begin_of_text|>`, `<|pad|>`, `<|unk|>`, chat, FIM and tool-call
|
| 63 |
+
tokens, plus 186 `<|reserved_N|>` slots — headroom for future extensions without changing
|
| 64 |
+
the shape of the embedding matrix.
|
| 65 |
+
|
| 66 |
+
Important when training from scratch: if you use only `<|endoftext|>` as the document
|
| 67 |
+
separator, the remaining special tokens never receive a gradient. In that case it is worth
|
| 68 |
+
blocking them at generation time (`bad_words_ids`) and setting
|
| 69 |
+
`bos_token_id = eos_token_id = 32568`.
|
| 70 |
+
|
| 71 |
+
## Usage
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
from tokenizers import Tokenizer
|
| 75 |
+
|
| 76 |
+
tok = Tokenizer.from_pretrained("KateMajzel/tokenizer-pl-32k")
|
| 77 |
+
ids = tok.encode("Zażółć gęślą jaźń").ids
|
| 78 |
+
print(len(ids), tok.decode(ids))
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
```python
|
| 82 |
+
from transformers import AutoTokenizer
|
| 83 |
+
|
| 84 |
+
tok = AutoTokenizer.from_pretrained("KateMajzel/tokenizer-pl-32k")
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
## What the experiment showed
|
| 88 |
+
|
| 89 |
+
An ablation on 42–51M parameter models (3 GB corpus, 3 random seeds) found:
|
| 90 |
+
|
| 91 |
+
- **Under an equal text budget the tokenizer does not differentiate model quality.**
|
| 92 |
+
Four independent measurements (BPB, PolEmo2, 8Tags, a private held-out set) showed no
|
| 93 |
+
significant difference against the GPT-2 tokenizer, and their directions were
|
| 94 |
+
inconsistent. The BPB difference between two seeds of the same model (0.0186) exceeded
|
| 95 |
+
the difference between tokenizers (0.0124).
|
| 96 |
+
- **Under an equal compute budget the advantage is unambiguous** — 5.30% BPB
|
| 97 |
+
(6.4 standard deviations) in favour of the denser tokenizer.
|
| 98 |
+
- **The gain lies in cost:** the same BPB level reached in 2.5× less time, with 21% fewer
|
| 99 |
+
parameters.
|
| 100 |
+
|
| 101 |
+
The Bielik v3 PL team reached the same conclusion independently at 11B scale
|
| 102 |
+
(arXiv 2604.10799): swapping in a dedicated tokenizer preserved quality and nearly doubled
|
| 103 |
+
representation density.
|
| 104 |
+
|
| 105 |
+
## Limitations
|
| 106 |
+
|
| 107 |
+
- English and code tokenize worse than under GPT-2 — 3.0 and 2.4 characters/token against
|
| 108 |
+
~4.0. This is a deliberate trade-off, but it rules out use on multilingual datasets.
|
| 109 |
+
- The training corpus is skewed toward administrative and press texts — visible in the
|
| 110 |
+
longest tokens (`Ġniepełnosprawności`, `Ġzagospodarowania`). For a model meant to sound
|
| 111 |
+
colloquial, this is worth accounting for in the data mix.
|
| 112 |
+
- The apostrophe rule in the pre-tokenizer is English (`'(?i:[sdmt]|ll|ve|re)`) — dead on
|
| 113 |
+
Polish, but harmless.
|
| 114 |
+
- No `post_processor` — BOS/EOS are not added automatically and offsets are not trimmed.
|
| 115 |
+
Irrelevant for language modeling, relevant for NER/QA.
|
| 116 |
+
- **Embedding cost.** At `d_model = 512` the embedding matrix is 16.8M parameters. In a
|
| 117 |
+
42.5M model that is 40% — worth computing before matching a vocabulary size to a small
|
| 118 |
+
model.
|
| 119 |
+
|
| 120 |
+
## License and citation
|
| 121 |
+
|
| 122 |
+
MIT. Methodology and code: https://github.com/KateMajzel/gollem-pl
|
| 123 |
+
|
| 124 |
+
```bibtex
|
| 125 |
+
@misc{tokenizerpl32k,
|
| 126 |
+
title = {tokenizer-pl-32k: a Polish BPE tokenizer and its ablation},
|
| 127 |
+
author = {Majzel-Pośpiech, Katarzyna},
|
| 128 |
+
year = {2026},
|
| 129 |
+
url = {https://huggingface.co/KateMajzel/tokenizer-pl-32k}
|
| 130 |
+
}
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
---
|
| 134 |
+
|
| 135 |
+
# tokenizer-pl-32k (polski)
|
| 136 |
+
|
| 137 |
+
Byte-level BPE dla języka polskiego. 32 568 pozycji słownika + 200 tokenów specjalnych
|
| 138 |
+
= 32 768 (2¹⁵, wygodne dla kerneli GPU i tensor-parallel).
|
| 139 |
|
| 140 |
Tokenizer wytrenowany na polskim korpusie i zwalidowany eksperymentalnie w projekcie
|
| 141 |
+
[gollem-pl](https://github.com/KateMajzel/gollem-pl) — kontrolowanej ablacji porównującej
|
| 142 |
+
go z tokenizerem GPT-2 przy identycznym budżecie treningowym.
|
| 143 |
|
| 144 |
+
Model wytrenowany z tym tokenizerem: [KateMajzel/GoLLeM-45M-PL](https://huggingface.co/KateMajzel/GoLLeM-45M-PL).
|
|
|
|
| 145 |
|
| 146 |
## Gęstość
|
| 147 |
|
| 148 |
| | ten tokenizer | GPT-2 |
|
| 149 |
|---|---|---|
|
| 150 |
+
| bajty/token — korpus mieszany PL (2,96 GB) | 4,050 | 2,066 |
|
| 151 |
+
| bajty/token — held-out (2,77 MB) | 4,103 | 2,134 |
|
| 152 |
| tokenów z 2,96 GB tekstu | 731 mln | 1 434 mln |
|
| 153 |
+
| gęstość względna | **1,96×** | 1,00× |
|
| 154 |
|
| 155 |
+
Fertility na polskiej prozie: ~1,35 tokena na słowo (5,80 znaku/token). Uwaga: na realnym
|
| 156 |
+
korpusie — z URL-ami, liczbami, resztkami formatowania — wychodzi 4,05 bajtu/token, czyli
|
| 157 |
+
wyraźnie gorzej. Fertility należy podawać z korpusu, nie z wyselekcjonowanych zdań.
|
|
|
|
| 158 |
|
| 159 |
+
Przykład różnicy w praktyce — słowo *niejednoznaczny* to 3 tokeny tutaj i 9 u GPT-2.
|
|
|
|
| 160 |
|
| 161 |
## Właściwości
|
| 162 |
|
|
|
|
| 172 |
| tokeny „same białe znaki" dłuższe niż 2 zn. | 18 |
|
| 173 |
| tokeny czysto liczbowe | 409 |
|
| 174 |
|
| 175 |
+
Round-trip zweryfikowany m.in. na `Zażółć gęślą jaźń — «cytat» … 😀\ttab` oraz
|
| 176 |
+
wielokrotnych spacjach i znakach nowej linii.
|
| 177 |
|
| 178 |
## Tokeny specjalne
|
| 179 |
|
| 180 |
+
`<|endoftext|>` (32568), `<|begin_of_text|>`, `<|pad|>`, `<|unk|>`, tokeny czatowe, FIM
|
| 181 |
+
i tool-call oraz 186 pozycji `<|reserved_N|>` — zapas na przyszłe rozszerzenia bez zmiany
|
| 182 |
+
kształtu tablicy embeddingów.
|
| 183 |
|
| 184 |
+
Ważne przy trenowaniu od zera: jeśli korzystasz tylko z `<|endoftext|>` jako separatora
|
| 185 |
+
dokumentów, pozostałe tokeny specjalne nigdy nie dostaną gradientu. Warto je wtedy
|
| 186 |
+
zablokować przy generowaniu (`bad_words_ids`) i ustawić
|
| 187 |
`bos_token_id = eos_token_id = 32568`.
|
| 188 |
|
| 189 |
## Użycie
|
|
|
|
| 208 |
|
| 209 |
- **Przy równym budżecie tekstu tokenizer nie różnicuje jakości modelu.** Cztery
|
| 210 |
niezależne pomiary (BPB, PolEmo2, 8Tags, prywatny held-out) nie wykazały istotnej
|
| 211 |
+
różnicy wobec tokenizera GPT-2, a ich kierunki były niespójne. Różnica BPB między dwoma
|
| 212 |
+
ziarnami tego samego modelu (0,0186) przewyższała różnicę między tokenizerami (0,0124).
|
|
|
|
| 213 |
- **Przy równym budżecie obliczeniowym przewaga jest jednoznaczna** — 5,30% BPB
|
| 214 |
(6,4 odchylenia) na korzyść gęstszego tokenizera.
|
| 215 |
+
- **Zysk leży w koszcie:** ten sam poziom BPB osiągnięty w 2,5× krótszym czasie, przy 21%
|
| 216 |
+
mniejszej liczbie parametrów.
|
| 217 |
|
| 218 |
+
Ten sam wniosek uzyskał niezależnie zespół Bielika v3 PL na skali 11B (arXiv 2604.10799):
|
| 219 |
+
wymiana tokenizera na dedykowany zachowała jakość i niemal podwoiła gęstość reprezentacji.
|
|
|
|
| 220 |
|
| 221 |
## Ograniczenia
|
| 222 |
|
| 223 |
+
- Angielski i kod tokenizują się gorzej niż w GPT-2 — 3,0 i 2,4 znaku/token wobec ~4,0.
|
| 224 |
+
To zamierzony kompromis, ale wyklucza użycie do zbiorów wielojęzycznych.
|
| 225 |
+
- Korpus treningowy przechylony w stronę tekstów administracyjno-prasowych — widać to
|
| 226 |
+
w najdłuższych tokenach (`Ġniepełnosprawności`, `Ġzagospodarowania`). Przy modelu, który
|
| 227 |
+
ma brzmieć potocznie, warto to uwzględnić w miksie danych.
|
| 228 |
+
- Reguła apostrofów w pre-tokenizerze jest angielska (`'(?i:[sdmt]|ll|ve|re)`) — na polskim
|
| 229 |
+
martwa, ale nieszkodliwa.
|
| 230 |
+
- Brak `post_processor` — BOS/EOS nie są dodawane automatycznie, offsety nie są trymowane.
|
| 231 |
+
Bez znaczenia dla modelowania języka, istotne przy NER/QA.
|
| 232 |
- **Koszt embeddingu.** Przy `d_model = 512` tablica embeddingów to 16,8 M parametrów.
|
| 233 |
+
W modelu 42,5 M stanowi to 40% — warto to policzyć, zanim dobierze się rozmiar słownika
|
| 234 |
+
do małego modelu.
|
| 235 |
|
| 236 |
## Licencja i cytowanie
|
| 237 |
|
|
|
|
| 244 |
year = {2026},
|
| 245 |
url = {https://huggingface.co/KateMajzel/tokenizer-pl-32k}
|
| 246 |
}
|
| 247 |
+
```
|