Knegis-Tokenizer-V2
A compact 2,048-piece SentencePiece unigram tokenizer for lowercase Swedish and English. It was built for speech transcripts, such as Swedish workplace conversation that mixes in English and technical terms, and suits the output vocabulary of a speech recognition model.
- Swedish and English share one vocabulary: common words in both languages are single pieces, and rarer words split into a few subword pieces.
- Common English contractions are single pieces:
let's,don't,it's,i'm. - Works on lowercase, normalized text. A matching normalizer is included.
- No special tokens besides
<unk>.
Usage
import sys
import sentencepiece as spm
from huggingface_hub import snapshot_download
path = snapshot_download("Knegis/Knegis-Tokenizer-V2")
sys.path.insert(0, path)
from knegis_normalize import normalize # plain Python; needs the `regex` package
sp = spm.SentencePieceProcessor(model_file=f"{path}/tokenizer.model")
text = normalize("Vi ses på mötet i morgon kl. 14:30, okej?")
print(text) # vi ses på mötet i morgon kl 14:30 okej
print(sp.encode(text, out_type=str))
# ['▁vi', '▁se', 's', '▁på', '▁', 'möte', 't', '▁i', '▁morgon', '▁kl', '▁', '1', '4', ':', '3', '0', '▁okej']
text = normalize("Let's deploy it — I don't think it's ready, but that's fine.")
print(text) # let's deploy it i don't think it's ready but that's fine
print(sp.encode(text, out_type=str))
# ['▁let's', '▁deploy', '▁it', '▁i', '▁don't', '▁think', '▁it's', '▁read', 'y', '▁but', '▁that's', '▁fin', 'e']
Always run normalize first. It lowercases, applies Unicode NFC, unifies quotes and
dashes, and removes punctuation except inside words, numbers, e-mail addresses, paths and
URLs. It keeps å ä ö é ü and spells other accented letters with plain ones (ø → ö,
æ → ä, ß → ss, ç → c). The tokenizer applies no normalization of its own, so
capital letters and any character outside its 59 supported characters become <unk>. For
normalized text, sp.decode(sp.encode(text)) == text.
What changed from KnegisTokenizerV1
- Vocabulary closer to workplace and technical speech. Pieces for finance, politics,
place names and web addresses were replaced by technical and everyday words, such as
deploy,server,cloud,code,version,featureandjavascript. - Contractions. 27 common English contractions are single pieces, and
's,'dand'llare endings. V1 needed three pieces for each (let's→▁let ' s). - Fewer characters. 59 instead of 85. The 27 accented letters that Swedish and English speech does not need are spelled with plain letters by the normalizer.
The two tokenizers are not interchangeable: piece ids differ, and each needs its own normalizer.
Performance
Tokens per word on held-out text that was not used to train this model. Each tokenizer uses its own normalizer. Lower is better.
| Text | Words | V1 | V2 | Change |
|---|---|---|---|---|
| English meeting transcripts | 521,836 | 1.50 | 1.38 | −8.0% |
| English, mixed sources | 845,319 | 1.55 | 1.51 | −2.4% |
| Swedish professional podcast transcripts (43 shows) | 1,534,129 | 1.49 | 1.48 | −0.8% |
| Swedish, mixed sources | 928,683 | 1.79 | 1.79 | +0.2% |
Neither tokenizer produced an unknown token on this text. V2 needs more tokens than V1 on parliamentary speech and financial market commentary, because their vocabulary was removed on purpose. These are text measurements; speech recognition accuracy has not been measured.
Settings
| Setting | Value |
|---|---|
| Model type | Unigram, 2,048 pieces including <unk> (id 0) |
| Special tokens | None besides <unk>: no BOS, EOS or padding ids |
| Characters | 59: a–z, å ä ö é ü, digits, space and # $ % & ' + , - . / : @ \ _ ~ £ €; no byte fallback |
| Splitting | By whitespace and into single digits; a piece may join letters and an apostrophe |
| Maximum piece length | 32 characters |
| Training text | 16.5 million words, about half Swedish and half English |
Trained with SentencePiece 0.2.2; the model loads with the standard sentencepiece
package. train_config.json has the full training settings.
Limitations
- Lowercase only, and no byte fallback: unnormalized text produces
<unk>. - Accented letters other than
å ä ö é üare not kept, so a name such asSørenis writtensören. - With 2,048 pieces, rarer words take several pieces, and numbers are always spelled digit
by digit. Product names such as
kubernetesorgithubtake four to six pieces. - Contractions are single pieces only when written with an apostrophe.
Files
| File | Contents |
|---|---|
tokenizer.model |
SentencePiece model (SHA-256 e67cf6cd786011bacbeff6625f625ac97111ca88c4f3e26c4d869aa369a3db34) |
tokenizer.vocab |
The 2,048 pieces with their scores |
knegis_normalize.py |
The matching text normalizer, version 2.0.0 |
config.json |
Summary: format, vocabulary size, files and normalizer version |
train_config.json |
Training settings |
Licence
The tokenizer is released under CC BY-NC 4.0. The normalizer is MIT-licensed, Copyright (c) 2026 Knegis.
- Downloads last month
- 37