Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- masked-diffusion
|
| 5 |
+
- discrete-diffusion
|
| 6 |
+
- llada
|
| 7 |
+
- educational
|
| 8 |
+
- experiment
|
| 9 |
+
language:
|
| 10 |
+
- en
|
| 11 |
+
library_name: pytorch
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# KB-Diffusion Model B — word-level masked diffusion
|
| 15 |
+
|
| 16 |
+
A 4.75M-parameter masked diffusion language model trained on 8,000 five-letter
|
| 17 |
+
English words. This is the "generalization companion" experiment suggested in
|
| 18 |
+
[KB-Diffusion](https://github.com/PastelRuntime/KB-Diffusion-Optimized) (an
|
| 19 |
+
educational masked-diffusion project by Bijan Bowen / OminousIndustries):
|
| 20 |
+
swap the repo's four keyboard layouts for thousands of words and see if the
|
| 21 |
+
same recipe still works.
|
| 22 |
+
|
| 23 |
+
It does, with a much harder hypothesis space. Trained in ~11 minutes on a free
|
| 24 |
+
Kaggle T4.
|
| 25 |
+
|
| 26 |
+
## The recipe (identical in shape to the keyboard model)
|
| 27 |
+
|
| 28 |
+
- Bidirectional transformer, no causal mask: vocab 27 (a-z + [MASK]), seq len 5,
|
| 29 |
+
dim 256, 6 layers, 4 heads, ff 1024
|
| 30 |
+
- LLaDA-style training: masking ratio t ~ U(0.05, 1), cross-entropy on masked
|
| 31 |
+
positions only, weighted by 1/t
|
| 32 |
+
- AdamW, lr 3e-4, 8000 steps, batch 1024
|
| 33 |
+
|
| 34 |
+
## Results
|
| 35 |
+
|
| 36 |
+
256 samples per sampler, checked against the full ~16k list of English
|
| 37 |
+
5-letter words:
|
| 38 |
+
|
| 39 |
+
| Sampler | Valid English | Unique |
|
| 40 |
+
|---|---|---|
|
| 41 |
+
| One-shot parallel (all 5 letters at once) | 2.0% | 256/256 |
|
| 42 |
+
| k=2 commits per step | 39.5% | 256/256 |
|
| 43 |
+
| Ancestral (commit 1, re-condition, repeat) | 68.4% | 254/256 |
|
| 44 |
+
| Greedy ancestral (no sampling) | 100% | 1/64 ("bales") |
|
| 45 |
+
|
| 46 |
+
The model's from-scratch letter predictions also track exact analytic unigram
|
| 47 |
+
statistics to mean total variation 0.0374 — the "transformer learns Bayes'
|
| 48 |
+
rule from corrupted examples" effect, at 8000 classes instead of 4.
|
| 49 |
+
|
| 50 |
+
Two takeaways:
|
| 51 |
+
|
| 52 |
+
1. The sampler is half the model. Identical weights produce 2% or 68% valid
|
| 53 |
+
output depending only on how commitments are made. Coherence is bought
|
| 54 |
+
with iteration, not parameters.
|
| 55 |
+
2. 68.4% of outputs were valid English but only 66.4% came from the training
|
| 56 |
+
list — it generalizes past its vocabulary, producing words it never saw.
|
| 57 |
+
|
| 58 |
+
## Usage
|
| 59 |
+
|
| 60 |
+
```python
|
| 61 |
+
import torch
|
| 62 |
+
from model_b_word_diffusion import Net, CH, MASK, N # from the GitHub repo
|
| 63 |
+
|
| 64 |
+
model = Net()
|
| 65 |
+
sd = torch.load("modelb_v2.pt", map_location="cpu", weights_only=True)
|
| 66 |
+
model.load_state_dict(sd)
|
| 67 |
+
model.eval()
|
| 68 |
+
# then use the ancestral confidence-commit sampler from the repo's script
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
See the GitHub repo for the full training/eval script and writeup.
|
| 72 |
+
|
| 73 |
+
## Intended use & limitations
|
| 74 |
+
|
| 75 |
+
An educational experiment, not a production model. 27-token vocabulary,
|
| 76 |
+
5-position sequences, memorization-adjacent scale on purpose. It exists to
|
| 77 |
+
make the masked-diffusion mechanism (parallel prediction, confidence
|
| 78 |
+
commits, re-masking, posterior sharpening) measurable and visible.
|