Downloads · 30 days
0
alea-institute/kl3m-tokenizer-003-64k
kl3m-tokenizer-003-64k 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 65,536 token variant of the KL3M (Kelvin Legal Large Language Model) whitespace tokenizer experiment, trained on legal domain text with separate space tokens for cleaner word embeddings.
Downloads · 30 days
0
Access
Public
Updated Nov 28, 2025
Repo size
—
Likes
0
Public
Click a slice to open those files.
.json4.5 MB · 100%
From the Hugging Face model README
This is the 65,536 token variant of the KL3M (Kelvin Legal Large Language Model) whitespace tokenizer experiment, trained on legal domain text with separate space tokens for cleaner word embeddings.
The KL3M whitespace tokenizers v5 are a 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:
Ġ prefix merging)Key difference from GPT-2 style tokenizers: These tokenizers do NOT merge spaces with following words. Instead, spaces get their own token (Ġ), and words are tokenized independently without the space prefix.
Standard BPE tokenizers (GPT-2, LLaMA, etc.) prepend spaces to tokens, so "the" and " the" become different tokens with different embeddings. This is efficient for compression but creates semantic inconsistency:
| Standard BPE | KL3M Whitespace |
|---|---|
[The][ the][ THE] = 3 different embeddings | [The][Ġ][the][Ġ][THE] = same word, same embedding |
| "contract" and " contract" are different | "contract" always has ONE embedding |
GPT-2 style: [The][ United][ States] (3 tokens, each word has space baked in)
KL3M Whitespace: [The][Ġ][United][Ġ][States] (5 tokens, spaces explicit)
On legal documents, these tokenizers trade compression for semantic clarity:
| Tokenizer | Vocab Size | Compression |
|---|---|---|
| KL3M v5-64K | 65,536 | ~3.1 chars/token |
| KL3M v5-32K | 32,768 | ~3.0 chars/token |
| KL3M v5-16K | 16,384 | ~2.9 chars/token |
| KL3M v5-8K | 8,192 | ~2.7 chars/token |
| KL3M v5-4K | 4,096 | ~2.5 chars/token |
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 |
|---|---|
| 4,096 (4K) | alea-institute/kl3m-tokenizer-003-4k |
| 8,192 (8K) | alea-institute/kl3m-tokenizer-003-8k |
| 16,384 (16K) | alea-institute/kl3m-tokenizer-003-16k |
| 32,768 (32K) | alea-institute/kl3m-tokenizer-003-32k |
| 65,536 (64K) | alea-institute/kl3m-tokenizer-003-64k |
→ You are viewing: 65,536 (64K)
By keeping spaces as separate tokens, words have consistent embeddings:
Token IDs 0-4,095 are identical across all tokenizer sizes. This enables:
Trained on the KL3M corpus (44GB of legal text):
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) |
from transformers import PreTrainedTokenizerFast
# Load tokenizer
tokenizer = PreTrainedTokenizerFast.from_pretrained(
"alea-institute/kl3m-tokenizer-003-64k"
)
# 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-tokenizer-003-64k"
)
# 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-tokenizer-003-64k"
)
# 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...
Ġ) is a separate token, never merged with wordsUse KL3M Whitespace tokenizers when:
Use standard BPE tokenizers (GPT-2 style) when:
MIT License
The ALEA Institute develops open-source tools and datasets for legal AI, including the KL3M corpus and tokenizers.
For questions or issues, please visit: github.com/alea-institute