Views
No views yet
| Vocabulary Size | HuggingFace Repository | File Size |
|---|---|---|
| 4,096 (4K) | alea-institute/kl3m-multi-word-001-4k | 118 KB |
| 8,192 (8K) | alea-institute/kl3m-multi-word-001-8k | 249 KB |
| 16,384 (16K) | alea-institute/kl3m-multi-word-001-16k | 529 KB |
| 32,768 (32K) | alea-institute/kl3m-multi-word-001-32k | 1.2 MB |
| 65,536 (64K) | alea-institute/kl3m-multi-word-001-64k | 2.4 MB |
| 131,072 (128K) | alea-institute/kl3m-multi-word-001-128k | 5.2 MB |
1from tokenizers import Tokenizer
2
3tok4k = Tokenizer.from_file("tokenizer-4096.json")
4tok128k = Tokenizer.from_file("tokenizer-131072.json")
5
6text = "with respect to"
7
8# 4K tokenizer: 3 tokens
9tok4k.encode(text).tokens
10# ['with respec', 't ', 'to']
11tok4k.encode(text).ids
12# [2317, 313, 424]
13
14# 128K tokenizer: 1 token
15tok128k.encode(text).tokens
16# ['with respect to']
17tok128k.encode(text).ids
18# [15903]1text = "Supreme Court"
2
3# 4K tokenizer: 5 tokens
4tok4k.encode(text).tokens
5# ['Sup', 'rem', 'e ', 'Cour', 't']
6tok4k.encode(text).ids
7# [4091, 1878, 296, 3063, 170]
8
9# 128K tokenizer: 1 token
10tok128k.encode(text).tokens
11# ['Supreme Court']
12tok128k.encode(text).ids
13# [81445]1text = "United States"
2
3# 4K: 2 tokens → 128K: 1 token
4tok4k.encode(text).tokens # ['United St', 'ates']
5tok128k.encode(text).tokens # ['United States']1text = "Department of State"
2
3# 4K: 3 tokens → 8K+: 2 tokens
4tok4k.encode(text).tokens # ['Depart', 'ment of ', 'State']
5tok8k.encode(text).tokens # ['Department of ', 'State']1# Example: "of the" has the same token ID across ALL vocabulary sizes
2text = "of the"
3
4tok4k.encode(text).ids # [1877]
5tok8k.encode(text).ids # [1877]
6tok16k.encode(text).ids # [1877]
7tok32k.encode(text).ids # [1877]
8tok64k.encode(text).ids # [1877]
9tok128k.encode(text).ids # [1877]
10
11# Special tokens are identical across all sizes
12tok4k.encode("<|start|>").ids # [0]
13tok4k.encode("<|end|>").ids # [1]
14tok4k.encode("<|pad|>").ids # [2]| Token | ID | Purpose |
|---|---|---|
<|start|> | 0 | Start of sequence (GPT-style) |
<|end|> | 1 | End of sequence |
<|pad|> | 2 | Padding token |
<|unk|> | 3 | Unknown token |
<|cls|> | 4 | Classification token (BERT-style) |
<|sep|> | 5 | Separator token (BERT-style) |
<|mask|> | 6 | Mask token (MLM training) |
⧈ Fact/descriptive claim⚖ Value/ethical claim⏵ Policy/action claim✦ Preference/taste claim⬤ Certain true● Strongly believe true◐ Lean true◌ Undecided◑ Lean false○ Certain false⬆ Approve/good⬇ Disapprove/bad⇆ Mixed⟂ Neutral∴ Therefore∵ Because⋀ And⋁ Or⟷ Equivalent⟶ Supports⟞ Undercuts⇢ Explains⟺ Mutual support⊢ Evidence marker👁 Observation🧪 Experiment📊 Data/statistics📚 Theory/literature🗣 Testimony🤔 Intuition★ Strong evidence☆ Weak evidence⚠ Warning/objection❗ Emphasis❓ Question↻ Revision✎ Reframe« Open agent quote» Close agent quote① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ Circled numbers 1-101from transformers import PreTrainedTokenizerFast
2
3# Load tokenizer
4tokenizer = PreTrainedTokenizerFast.from_pretrained("alea-institute/kl3m-multi-word-001-128k")
5
6# Tokenize text
7text = "The Supreme Court held that the defendant violated due process."
8tokens = tokenizer.tokenize(text)
9ids = tokenizer.encode(text)
10
11print(f"Tokens: {tokens}")
12print(f"Token IDs: {ids}")1from tokenizers import Tokenizer
2
3# Load tokenizer
4tokenizer = Tokenizer.from_pretrained("alea-institute/kl3m-multi-word-001-128k")
5
6# Encode text
7encoding = tokenizer.encode("in accordance with the United States Code")
8print(f"Tokens: {encoding.tokens}")
9print(f"IDs: {encoding.ids}")1from transformers import PreTrainedTokenizerFast
2
3tokenizer = PreTrainedTokenizerFast.from_pretrained("alea-institute/kl3m-multi-word-001-128k")
4
5# Configure special tokens for your model
6tokenizer.pad_token = "<|pad|>"
7tokenizer.eos_token = "<|end|>"
8tokenizer.bos_token = "<|start|>"
9tokenizer.unk_token = "<|unk|>"
10tokenizer.cls_token = "<|cls|>" # For BERT-style models
11tokenizer.sep_token = "<|sep|>" # For BERT-style models
12tokenizer.mask_token = "<|mask|>" # For masked language modelingbbpe (Binary Byte Pair Encoding) Rust crate with multi-word optimization:1zcat /nas4/data/kl3m/kl3m-bbpe-sample.txt.gz | \
2bbpe train -v - \
3 --max-entropy 7.0 \
4 --preprocessor unicode-whitespace \
5 --preprocessor-probability 0.1 \
6 --vocab-size 131072 \
7 --family-size 65536 --family-size 32768 --family-size 16384 \
8 --family-size 8192 --family-size 4096 \
9 --family-template tokenizer-{size}.json \
10 --output tokenizer-131072.jsonmax-entropy 7.0: Entropy threshold balancing multi-word phrases with common tokensfamily-size: Creates nested vocabulary families ensuring ID consistencypreprocessor unicode-whitespace: Whitespace normalization1from transformers import AutoModelForCausalLM, PreTrainedTokenizerFast
2
3tokenizer = PreTrainedTokenizerFast.from_pretrained("alea-institute/kl3m-multi-word-001-128k")
4model = AutoModelForCausalLM.from_pretrained("your-legal-model")
5
6# The model will efficiently process legal terminology
7text = "The Court held that the statute of limitations had expired."
8inputs = tokenizer(text, return_tensors="pt")
9outputs = model(**inputs)1# Train models with different vocabulary sizes
2for vocab_size in ["4k", "8k", "16k", "32k", "64k", "128k"]:
3 tokenizer = PreTrainedTokenizerFast.from_pretrained(
4 f"alea-institute/kl3m-multi-word-001-{vocab_size}"
5 )
6 # Train model and compare convergence, perplexity, downstream performance1# Stage 1: Train with 4K vocabulary
2tokenizer_4k = PreTrainedTokenizerFast.from_pretrained("alea-institute/kl3m-multi-word-001-4k")
3# ... train model ...
4
5# Stage 2: Expand to 16K vocabulary (embeddings for IDs 0-4095 are identical!)
6tokenizer_16k = PreTrainedTokenizerFast.from_pretrained("alea-institute/kl3m-multi-word-001-16k")
7# ... expand model embeddings and continue training ...1@misc{kl3m-multi-word-tokenizers-2025,
2 title={KL3M Multi-Word Tokenizers: Hierarchically Nested BPE for Legal Domain Language Modeling},
3 author={ALEA Institute},
4 year={2025},
5 url={https://huggingface.co/alea-institute/kl3m-multi-word-001-128k}
6}1@article{kl3m-data-2025,
2 title={The KL3M Data Project: Copyright-Clean Training Resources for Large Language Models},
3 author={Bommarito, Michael and others},
4 journal={arXiv preprint arXiv:2504.07854},
5 year={2025}
6}