CoolFace
Modelpublic

mjbommar/glaurung-binary-tokenizer-002

sourceHugging Faceapache-2.0updated 11mo agoView on Hugging Face
1likes
Model Card

glaurung-binary-tokenizer-002

A cross-platform BPE tokenizer for binary executables and machine code. Trained using advanced chunked training with deduplication on 23 GB of diverse binaries spanning Linux and Windows platforms.

๐Ÿ”— Model: `mjbommar/glaurung-binary-tokenizer-002` ๐Ÿ“Š Dataset: `mjbommar/binary-30k-tokenized` ๐Ÿ“„ Paper: Binary BPE: Cross-Platform Tokenization for Binary Analysis (arXiv preprint coming soon)

Overview

  • โ€”Vocabulary Size: 65,536 tokens (2^16)
  • โ€”Token Composition: 256 base bytes + 65,273 learned merges + 7 special tokens
  • โ€”Average Token Length: 3.749 bytes
  • โ€”3-byte Instructions: 16.5% of vocabulary (10,800 tokens)
  • โ€”Compression Ratio: ~2.6 bytes/token on typical binaries

Training Configuration

Training Corpus:

  • โ€”Source: `mjbommar/binary-30k-tokenized`
  • โ€”Size: ~23 GB (24.7 billion bytes)
  • โ€”Processed Chunks: 40,574 total (37,083 unique + 8,454 duplicates reused)
  • โ€”Platforms: Linux (Alpine, Debian, Ubuntu - ELF), Windows (8, 10, 11 - PE)
  • โ€”Architectures: x86-64, x86-32, ARM64

Training Parameters:

  • โ€”Vocabulary size: 65,536 (including 7 special tokens)
  • โ€”Min frequency: 4
  • โ€”Chunk size: 4,194,304 bytes (4 MB)
  • โ€”Training method: Chunked BPE with deduplication and support-based merge combination
  • โ€”Allowed lengths: DEFAULT (1-16 bytes)
  • โ€”Training duration: ~8-9 hours

Vocabulary Statistics

Composition:

  • โ€”Base bytes (0-255): 256 tokens
  • โ€”Learned merges: 65,273 tokens
  • โ€”Special tokens: 7 tokens (<|start|>, <|end|>, <|pad|>, <|unk|>, <|cls|>, <|sep|>, <|mask|>)
  • โ€”Total: 65,536 tokens

Quality Metrics:

  • โ€”All tokens reachable: โœ“ Yes
  • โ€”Valid merges: 65,273 / 65,273
  • โ€”Power-of-2 size: โœ“ Yes (2^16)

Token Length Distribution

LengthCountPercentageDescription
1 byte2560.4%Base bytes
2 bytes28,56143.6%Byte pairs (most common patterns)
3 bytes10,80016.5%Complete x86-64 instructions
4 bytes14,37621.9%Instructions with operands
5 bytes2,7804.2%Complex patterns
6 bytes2,2133.4%Complex patterns
7 bytes1,1671.8%Complex patterns
8 bytes2,3293.6%Multi-byte sequences
9+ bytes3,0454.6%Long patterns

Average Token Length: 3.749 bytes


Byte Content Analysis

Content Categories:

  • โ€”Contains NULL byte (0x00): 17,418 tokens (26.6%)
  • โ€”ASCII printable (0x20-0x7E): 9,478 tokens (14.5%)
  • โ€”All ASCII (<0x80): 20,816 tokens (31.8%)
  • โ€”High bytes (โ‰ฅ0x80): 44,711 tokens (68.2%)

Most Common Bytes in Tokens:

  • โ€”0x00 (NULL): 34,482 occurrences - Padding and alignment
  • โ€”0xFF: 6,545 occurrences - Sentinel values
  • โ€”0x48 (REX.W): 3,419 occurrences - x86-64 REX prefix
  • โ€”0x8B (MOV): 2,486 occurrences - x86-64 MOV opcode
  • โ€”0x40 (@): 4,538 occurrences - ASCII and instruction patterns

Sequence Coverage

N-byte Sequence Diversity: | Length | Learned Tokens | Possible Sequences | Coverage | |--------|----------------|-------------------|----------| | 1-byte | 256 | 256 | 100.00% | | 2-byte | 28,561 | 65,536 | 43.58% | | 3-byte | 10,800 | 16,777,216 | 0.064% | | 4-byte | 14,376 | 4,294,967,296 | 0.00034% |

Notable Achievement: 43.6% coverage of all possible 2-byte sequences - excellent for pattern recognition.


Files

  • โ€”tokenizer-65536.json - Trained tokenizer model (2.4 MB)
  • โ€”analysis_results.json - Detailed analysis statistics
  • โ€”original_README.md - Original README from HuggingFace

Usage

Load from HuggingFace Hub:

python
from tokenizers import Tokenizer

# Load directly from HuggingFace
tokenizer = Tokenizer.from_pretrained("mjbommar/glaurung-binary-tokenizer-002")

Load from local file:

bash
# With bbpe CLI
bbpe encode --tokenizer tokenizer-65536.json /path/to/binary
bbpe info tokenizer-65536.json

Complete Python Example:

python
from tokenizers import Tokenizer

# Load from HuggingFace or local file
tokenizer = Tokenizer.from_pretrained("mjbommar/glaurung-binary-tokenizer-002")
# OR: tokenizer = Tokenizer.from_file("tokenizer-65536.json")

# Read binary file and decode as latin-1 (preserves all byte values 0-255)
with open("/usr/bin/ls", "rb") as f:
    data = f.read()
    data_str = data.decode("latin-1")

# Encode the binary data
encoding = tokenizer.encode(data_str)
print(f"File size: {len(data)} bytes")
print(f"Total tokens: {len(encoding.ids)}")
print(f"Compression: {len(data) / len(encoding.ids):.3f} bytes/token")

# First 10 tokens
for i, (token_id, token) in enumerate(zip(encoding.ids[:10], encoding.tokens[:10])):
    token_bytes = token.encode("latin-1")
    print(f"  Token {i}: ID={token_id:5d} hex={token_bytes.hex():20s} ({len(token_bytes)} bytes)")

# Decode tokens back to bytes
decoded_str = tokenizer.decode(encoding.ids)
decoded_bytes = decoded_str.encode("latin-1")
assert decoded_bytes == data  # Perfect reconstruction

Example output for `/usr/bin/ls` (142,312 bytes):

File size: 142312 bytes
Total tokens: 54537
Compression: 2.609 bytes/token

First 10 tokens:
  Token 0: ID=  127 hex=7f                   (1 bytes)
  Token 1: ID= 2382 hex=454c                 (2 bytes)
  Token 2: ID= 5923 hex=4602                 (2 bytes)
  Token 3: ID=  394 hex=0101                 (2 bytes)
  Token 4: ID=  268 hex=000000000000         (6 bytes)
  Token 5: ID=  259 hex=000000               (3 bytes)
  Token 6: ID=  295 hex=0300                 (2 bytes)
  Token 7: ID= 2124 hex=3e00                 (2 bytes)
  Token 8: ID=  271 hex=01000000             (4 bytes)
  Token 9: ID=59106 hex=306d                 (2 bytes)

Decoded: 7f454c4602010100000000000000000003003e0001000000306d...
(ELF header: 7f 45 4c 46 = ELF magic bytes)

Performance Characteristics

Compression on Real-World Binaries:

BinarySizeTokensbytes/token
bash1.38 MB602,7192.399
python3.127.65 MB2,997,3032.676
gcc-130.98 MB375,3312.726
ls0.14 MB54,5372.609
grep0.18 MB73,5002.542

Average: 2.590 bytes/token

Information-Theoretic Efficiency:

  • โ€”Binary entropy: ~6.5 bits/byte
  • โ€”Theoretical optimal: 2.46 bytes/token
  • โ€”Actual performance: 2.590 bytes/token
  • โ€”Efficiency: 95.0% of theoretical optimum

Key Features

Instruction-Aware Patterns:

  • โ€”REX prefixes: 0x48, 0x4c, 0x4d (x86-64 64-bit operands)
  • โ€”Common opcodes: 0x8b (MOV), 0x89 (MOV), 0xe8 (CALL)
  • โ€”ModR/M patterns: 0xc0, 0x45, 0x5d

Common Binary Patterns:

  • โ€”Padding: 0xcc 0xcc (INT3 debug breakpoints), 0x90 0x90 (NOP sleds)
  • โ€”Alignment: 0x00 0x00 0x00 0x00 (NULL padding)
  • โ€”String terminators: 0x00 at word boundaries

String-Rich Vocabulary:

  • โ€”11.81% of vocabulary contains function names, paths, and library references
  • โ€”Better semantic understanding than standard BPE

Comparison with Other Tokenizers

vs. binary-tokenizer-001 Series (this repository):

Metric4K8K16K64K (this)Improvement
Vocab size4,0968,19216,38465,5364-16x larger
Avg token length3.0003.3123.4983.749+25% vs 4K
3-byte tokens %20.6%21.7%20.5%16.5%Different focus
2-byte coverage3.0%5.6%10.9%43.6%14x better
Compression (ls)2.002.172.392.61+30% vs 4K
Training methodStandardStandardStandardChunked+dedupAdvanced

Key Advantages of 64K Vocabulary:

  • โ€”43.6% 2-byte coverage: Captures nearly half of all possible byte pairs
  • โ€”Chunked training: Deduplication-aware training improves merge quality
  • โ€”Better compression: 2.609 bytes/token vs 2.0 bytes/token (4K)
  • โ€”Longer patterns: 3.749 byte average vs 3.0 bytes (4K)
  • โ€”String-rich: 11.81% vocabulary contains semantic strings

Citation

If you use this tokenizer in your research, please cite:

bibtex
@article{bommarito2025binarybpe,
  title={Binary BPE: Cross-Platform Tokenization for Binary Analysis},
  author={Bommarito II, Michael J.},
  journal={arXiv preprint},
  year={2025},
  note={Preprint coming soon}
}

Also cite the original Glaurung tokenizer:

Glaurung Binary Tokenizer 002
64K Binary Tokenizer for Neural Language Models
Vocabulary: 65,536 tokens (256 base + 65,273 merges + 7 special)
Training: October-November 2025
Training Method: Chunked BPE with deduplication (bbpe v0.3.2)
Dataset: 23GB binaries-small (40,574 chunks, 8,454 duplicates)
Performance: 2.590 bytes/token (95% of theoretical optimum)
HuggingFace: mjbommar/glaurung-binary-tokenizer-002

Author: Michael J. Bommarito II (michael.bommarito@gmail.com)


License

Apache License 2.0

This tokenizer is part of the Glaurung project.


Generated: November 13, 2025 Original Model: mjbommar/glaurung-binary-tokenizer-002 Training Tool: bbpe v0.3.2 Analysis Script: analyze_tokenizer.py