Tree-gram generators
The autoregressive tree-gram models that generate the synthetic corpora in hugs-from-a-25/tree-gram-text
A tree-gram of horizon n predicts the next token from the previous n - 1 tokens through a hierarchical structure. Each generator is a folder <source>/<generator>/:
model.safetensors: the weights, float32;config.json: constructor arguments, training hyper-parameters and the release checks;generation.json: information on corpus sampling.
bigram refers to count-based bigram estimation.
The bigram folders hold counts.npz (prev, next, count): p(next | prev) is the count ratio, and a
prev never seen in training backs off to uniform.
Use
modeling_treegram.py needs only torch and safetensors:
from huggingface_hub import snapshot_download
import sys, torch
path = snapshot_download("hugs-from-a-25/tree-gram-generators", allow_patterns=["modeling_treegram.py", "tinystories/n8_d1024/*", "tokenizers/*"])
sys.path.insert(0, path)
from modeling_treegram import load_generator, next_token_logits, sample
model, cfg = load_generator(f"{path}/tinystories/n8_d1024")
tokens = sample(model, n_tokens=200, batch=4, eos_token_id=cfg["eos_token_id"]) # (4, 200) token ids
next_token_logits(model, context) takes a (batch, n - 1) tensor of token ids.
Generators
The folders and entropies for the
TinyStories
| generator | context | width d | exact entropy, nats/token (val) | val loss, nats/token |
|---|---|---|---|---|
tinystories/bigram |
1 | - | 3.5595 | 3.5682 |
tinystories/n3_d1024 |
2 | 1024 | 2.8391 | 2.8462 |
tinystories/n4_d1024 |
3 | 1024 | 2.4906 | 2.4993 |
tinystories/n8_d1024 |
7 | 1024 | 2.0610 | 2.0613 |
tinystories/n16_d1024 |
15 | 1024 | 1.8384 | 1.8476 |
tinystories/n32_d64 |
31 | 64 | 2.5510 | 2.5499 |
tinystories/n32_d128 |
31 | 128 | 2.2876 | 2.2915 |
tinystories/n32_d256 |
31 | 256 | 2.0083 | 2.0142 |
tinystories/n32_d512 |
31 | 512 | 1.8837 | 1.8829 |
tinystories/n32_d1024 |
31 | 1024 | 1.7317 | 1.7407 |
WikiText-103
| generator | context | width d | exact entropy, nats/token (val) | val loss, nats/token |
|---|---|---|---|---|
wikitext103/bigram |
1 | - | 5.0023 | 4.9979 |
wikitext103/n3_d1024 |
2 | 1024 | 4.4252 | 4.4224 |
wikitext103/n4_d1024 |
3 | 1024 | 4.2205 | 4.2182 |
wikitext103/n8_d1024 |
7 | 1024 | 4.0289 | 4.0328 |
wikitext103/n16_d1024 |
15 | 1024 | 3.9372 | 3.9349 |
wikitext103/n32_d64 |
31 | 64 | 4.9110 | 4.9121 |
wikitext103/n32_d128 |
31 | 128 | 4.6588 | 4.6639 |
wikitext103/n32_d256 |
31 | 256 | 4.3353 | 4.3337 |
wikitext103/n32_d512 |
31 | 512 | 4.1734 | 4.1717 |
wikitext103/n32_d1024 |
31 | 1024 | 3.9316 | 3.9298 |
FineWeb-Edu
| generator | context | width d | exact entropy, nats/token (val) | val loss, nats/token |
|---|---|---|---|---|
fineweb-edu/bigram |
1 | - | 5.4301 | 5.4287 |
fineweb-edu/n3_d1024 |
2 | 1024 | 4.9717 | 4.9821 |
fineweb-edu/n4_d1024 |
3 | 1024 | 4.7065 | 4.7133 |
fineweb-edu/n8_d1024 |
7 | 1024 | 4.4455 | 4.4546 |
fineweb-edu/n16_d1024 |
15 | 1024 | 4.2886 | 4.2983 |
fineweb-edu/n32_d64 |
31 | 64 | 5.1356 | 5.1460 |
fineweb-edu/n32_d128 |
31 | 128 | 4.9050 | 4.9117 |
fineweb-edu/n32_d256 |
31 | 256 | 4.6072 | 4.6225 |
fineweb-edu/n32_d512 |
31 | 512 | 4.4973 | 4.5043 |
fineweb-edu/n32_d1024 |
31 | 1024 | 4.2921 | 4.3096 |
Licence
The generators are derived from their training corpora and carry those corpora's terms: TinyStories models
CDLA-Sharing-1.0, WikiText-103 models CC BY-SA 3.0, FineWeb-Edu models ODC-By 1.0. See LICENSE.md.