Downloads · 30 days
0
alea-institute/kl3m-multi-word-002-4k
kl3m-multi-word-002-4k is a fill-mask model from alea-institute. Use it when you need the model to fill a missing word. It is set up for transformers. The card lists the license as mit.
This is the 4,096 token variant of the KL3M (Kelvin Legal Large Language Model) multi-word tokenizer family v2, optimized for legal domain text with hierarchical vocabulary nesting.
Downloads · 30 days
0
Access
Public
Updated Nov 24, 2025
Repo size
—
Likes
0
Public
Click a slice to open those files.
.json255 KB · 95%
From the Hugging Face model README
This is the 4,096 token variant of the KL3M (Kelvin Legal Large Language Model) multi-word tokenizer family v2, optimized for legal domain text with hierarchical vocabulary nesting.
The KL3M multi-word tokenizers v2 are an improved family of byte-pair encoding (BPE) tokenizers trained on ~44GB of legal domain text from the KL3M dataset (copyright-clean legal corpus from the ALEA Institute). These tokenizers:
What is multi-word tokenization? Unlike standard tokenizers that split text into subword pieces, these tokenizers capture multiple words as single tokens. This is especially powerful for legal text with common multi-word phrases.
4K vocabulary (16 tokens):
[The][ ][United][ ][States][ ][Department][ of][ ][Trans][port][ation][ is][ ][responsible][ for]
32K vocabulary (10 tokens):
[The][ United][ States][ Department][ of][ ][Transportation][ is][ responsible][ for]
128K vocabulary (8 tokens) - "United States" is ONE token!
[The][ United States][ Department][ of][ Transportation][ is][ responsible][ for]
4K vocabulary (16 tokens):
[In][ ][accordance][ with][ the][ ][terms][ and][ con][ditions][ ][set][ for][th][ ][herein]
32K vocabulary (10 tokens) - "accordance with" is ONE token!
[In][ ][accordance with][ the][ terms][ and][ conditions][ set][ forth][ herein]
128K vocabulary (8 tokens) - "accordance with" and "set forth" are single tokens!
[In][ accordance with][ the][ terms][ and][ conditions][ set forth][ herein]
4K vocabulary (17 tokens):
[The][ S][up][re][me][ C][our][t][ of][ the][ ][United][ ][States][ h][eld][ that]
32K vocabulary (9 tokens):
[The][ Sup][reme][ Court][ of the][ United][ States][ held][ that]
128K vocabulary (7 tokens) - "United States" is ONE token!
[The][ Supreme][ Court][ of the][ United States][ held][ that]
On a realistic 3,743-character legal document (Software License Agreement):
| Tokenizer | Vocab Size | Tokens | Chars/Token | vs GPT-4 |
|---|---|---|---|---|
| KL3M v2-128K | 131,072 | 704 | 5.32 | -7.5% |
| GPT-4o/5 | 200,019 | 757 | 4.94 | +0.5% |
| GPT-4 | 100,277 | 761 | 4.92 | baseline |
| GPT-2 | 50,257 | 858 | 4.36 | +12.7% |
| KL3M v2-64K | 65,536 | 802 | 4.67 | +5.4% |
| KL3M v2-32K | 32,768 | 943 | 3.97 | +23.9% |
Common legal terms as single tokens (128K vocab):
| Term | KL3M v2-128K | GPT-4 | GPT-4o/5 |
|---|---|---|---|
| "Licensee" | 1 token | 2 tokens | 2 tokens |
| "hereinafter" | 1 token | 3 tokens | 3 tokens |
| "indemnification" | 1 token | 4 tokens | 3 tokens |
| "arbitration" | 1 token | 3 tokens | 3 tokens |
| "WHEREAS" | 1 token | 2 tokens | 2 tokens |
| "non-exclusive" | 1 token | 2 tokens | 2 tokens |
This tokenizer is part of a hierarchically nested family. Token IDs in smaller vocabularies are identical across all larger vocabularies, enabling seamless vocabulary expansion:
| Vocabulary Size | HuggingFace Repository | File Size |
|---|---|---|
| 4,096 (4K) | alea-institute/kl3m-multi-word-002-4k | 248 KB |
| 8,192 (8K) | alea-institute/kl3m-multi-word-002-8k | 516 KB |
| 16,384 (16K) | alea-institute/kl3m-multi-word-002-16k | 1.1 MB |
| 32,768 (32K) | alea-institute/kl3m-multi-word-002-32k | 2.1 MB |
| 65,536 (64K) | alea-institute/kl3m-multi-word-002-64k | 4.4 MB |
| 131,072 (128K) | alea-institute/kl3m-multi-word-002-128k | 8.9 MB |
→ You are viewing: 4,096 (4K)
Legal text contains frequent multi-word phrases that benefit from being treated as single tokens. The larger vocabularies capture increasingly sophisticated legal terminology:
4K vocabulary examples:
32K vocabulary examples:
128K vocabulary examples:
Token IDs 0-4,095 are identical across all tokenizer sizes. This enables:
Trained on the KL3M corpus (44GB of legal text):
This specialized training produces:
Seven essential special tokens for language model training:
| Token | ID | Purpose |
|---|---|---|
<|start|> | 0 | Start of sequence |
<|end|> | 1 | End of sequence |
<|pad|> | 2 | Padding token |
<|unk|> | 3 | Unknown token |
<|cls|> | 4 | Classification (BERT) |
<|sep|> | 5 | Separator (BERT) |
<|mask|> | 6 | Mask token (MLM) |
Note: v2 removes experimental symbols (⧈, ⚖, ⏵) from v1 for cleaner design.
from transformers import PreTrainedTokenizerFast
# Load tokenizer
tokenizer = PreTrainedTokenizerFast.from_pretrained(
"alea-institute/kl3m-multi-word-002-4k"
)
# Tokenize text
text = "The Licensor hereby grants to Licensee a non-exclusive license."
tokens = tokenizer.encode(text)
print(f"Tokens: {len(tokens)}")
# Decode
decoded = tokenizer.decode(tokens)
print(f"Decoded: {decoded}")
from tokenizers import Tokenizer
# Load tokenizer
tokenizer = Tokenizer.from_pretrained(
"alea-institute/kl3m-multi-word-002-4k"
)
# Encode
encoding = tokenizer.encode(text)
print(f"Tokens: {encoding.tokens}")
print(f"IDs: {encoding.ids}")
from transformers import AutoConfig, AutoModelForMaskedLM, PreTrainedTokenizerFast
# Load tokenizer
tokenizer = PreTrainedTokenizerFast.from_pretrained(
"alea-institute/kl3m-multi-word-002-4k"
)
# Create model config
config = AutoConfig.from_pretrained(
"bert-base-uncased",
vocab_size=tokenizer.vocab_size,
)
# Initialize model
model = AutoModelForMaskedLM.from_config(config)
# Train with HuggingFace Trainer...
bbpe train \
--max-entropy 7.0 \
--preprocessor unicode-whitespace \
--preprocessor-probability 0.1 \
--vocab-size 131072 \
--family-size 65536 --family-size 32768 \
--family-size 16384 --family-size 8192 --family-size 4096
Legal Document Processing (contracts, patents, briefs):
Resource-Constrained Environments:
Experimentation / Research:
Choose vocab size based on your model parameter count:
| Model Size | Recommended Vocab | Embedding Parameters |
|---|---|---|
| <200M params | 4K-8K | 3-6M |
| 200M-500M params | 8K-16K | 6-13M |
| 500M-1B params | 16K-32K | 13-26M |
| 1B-3B params | 32K-64K | 26-52M |
| >3B params | 64K-128K | 52-104M |
If you use these tokenizers in your research, please cite:
@misc{kl3m-multi-word-002,
title={KL3M Multi-Word Tokenizers v2: Hierarchically Nested BPE for Legal Domain},
author={ALEA Institute},
year={2025},
publisher={HuggingFace},
url={https://huggingface.co/alea-institute/kl3m-multi-word-002-4k}
}
MIT License
The ALEA Institute develops open-source tools and datasets for legal AI, including the KL3M corpus and multi-word tokenizers.
For questions or issues, please contact: [contact information TBD]