File size: 4,872 Bytes
892b5b4 9d43dda 892b5b4 9d43dda 892b5b4 9d43dda 892b5b4 9d43dda 892b5b4 9d43dda 892b5b4 9d43dda 892b5b4 9d43dda 892b5b4 9d43dda 892b5b4 9d43dda 892b5b4 9d43dda |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
---
license: mit
tags:
- binary-neural-network
- zero-tokenization
- wire-speed-learning
- bit-level
- byte-level
language:
- en
pipeline_tag: text-generation
---
# Binary Transformers: Learning Language from Raw Binary
**Zero-tokenization transformers that learn directly from network bytes, bits, and beyond.**
This repository contains four novel transformer architectures exploring the limits of minimal vocabulary learning:
| Model | Vocab | Input | Weights | Description |
|-------|-------|-------|---------|-------------|
| **Byte-level** | 256 | bytes (0x00-0xFF) | real | One token per byte value |
| **Bit-level** | 2 | bits (0, 1) | real | Pure binary, 8 tokens per byte |
| **Dibit** | 4 | dibits (00,01,10,11) | real | 2-bit tokens, 4 per byte |
| **Pure Binary** | 2 | bits (0, 1) | **binary (-1/+1)** | BITS ALL THE WAY DOWN |
## Why?
Traditional LLMs use tokenizers (BPE, SentencePiece) with 32k-256k vocabulary. This creates:
- Tokenizer overhead and complexity
- Language/domain bias baked into vocabulary
- Preprocessing bottleneck
**What if we eliminated tokenization entirely?**
These models learn directly from raw binary data - no tokenizer, no preprocessing, just bytes flowing into neural networks. The ultimate goal: **wire-speed learning** where models absorb network traffic in real-time.
## Results (Live Experiments - 16 Jan 2026)
### Byte-Level (vocab=256)
```
Data: 350KB web crawl
BPB: 4.68 (vs 8.0 random = 41% compression)
Speed: 8.7 KB/s learning rate
Params: 0.6M
```
Learns HTML structure, XML tags, timestamps from raw bytes.
### Bit-Level (vocab=2)
```
Data: 550KB
Entropy: 1.008 bit/bit (vs 1.0 random = 0.8% compression)
Speed: 0.7 KB/s
Params: 85M
```
Pure binary learning - discovers byte boundaries and ASCII from 0s and 1s.
### Dibit (vocab=4: 00,01,10,11)
```
Data: 437KB
BPB: 7.55 (vs 8.0 random = 5.7% compression)
Speed: 0.25 KB/s
Params: 37.8M
```
2-bit tokens provide 2x context efficiency vs bit-level. **Best compression so far!**
### Pure Binary (vocab=2, binary weights)
```
Data: 806KB
Entropy: 0.995 bit/bit (0.5% compression)
Binary params: 99.8%
Params: 4.7M
```
**BITS ALL THE WAY DOWN** - input bits, binary weights (-1/+1), output bits.
On specialized hardware, this enables XNOR+popcount operations instead of multiply-accumulate.
## Architecture
All models use standard transformer architecture with:
- Causal self-attention
- GELU activation
- LayerNorm
- AdamW optimizer
- Straight-Through Estimator (STE) for binary weight gradients
### Key Innovation: Online Learning
Unlike traditional batch training, these models learn from streaming data:
- Micro-batches (32-512 tokens)
- Single-pass, no data curation
- Real-time network stream compatible
## Usage
### Byte-Level
```bash
# Pipe any data source
cat data.bin | python byte_trainer.py
curl -s http://example.com | python byte_trainer.py
zcat crawl.jsonl.gz | python byte_trainer.py
```
### Bit-Level
```bash
cat data.bin | python bit_trainer.py
```
### Dibit (2-bit tokens)
```bash
cat data.bin | python dibit_trainer.py
```
### Pure Binary (binary weights)
```bash
cat data.bin | python purebit_trainer.py
```
## Configuration
Edit the CONFIG dict in each trainer:
```python
CONFIG = {
"d": 256, # embedding dimension
"layers": 6, # transformer layers
"heads": 8, # attention heads
"vocab": 2, # vocabulary size
"ctx": 2048, # context length
}
```
## Files
```
byte_trainer.py # Vocab=256, one token per byte
bit_trainer.py # Vocab=2, pure bits
dibit_trainer.py # Vocab=4, 2-bit tokens (00,01,10,11)
purebit_trainer.py # Vocab=2 + binary weights (-1/+1)
```
## Insights
1. **Byte-level is sweet spot** - 256 vocab captures ASCII structure efficiently while eliminating tokenizer overhead
2. **Bit-level works but slow** - 8x longer sequences mean 8x less context per forward pass
3. **Dibit balances** - 2-bit tokens give 2x context vs bit-level while staying "pure binary"
4. **Binary weights viable** - 99.8% binary params learn almost as well as real weights, enabling massive hardware speedups
5. **HTML is natural SFT** - Web data contains instruction-following patterns: `<h3>Question</h3><p>Answer`, `<dt>Term</dt><dd>Definition</dd>`, JSON Q&A
## Future Work
- Scale to billions of parameters
- Custom CUDA kernels for binary ops (XNOR + popcount)
- FPGA/ASIC implementation for true wire-speed learning
- Hierarchical binary models (bit → byte → word emergence)
## Citation
```bibtex
@misc{opentransformer2026binary,
title={Binary Transformers: Learning Language from Raw Binary},
author={OpenTransformer},
year={2026},
publisher={HuggingFace},
url={https://huggingface.co/OpenTransformer/binary-transformers}
}
```
## License
MIT
## Acknowledgments
Built with PyTorch. Trained on vast.ai GPU instances. Part of the AGILLM research project.
|