Every component was written from the ground up: tokenizer, attention mechanism, positional encoding, training loop, and generation pipeline.
ZeroNet-1 is a small but architecturally modern language model designed to demonstrate genuine understanding of Transformer internals. It is trained on the TinyStories dataset and generates coherent short-form English text.
Input Token IDs
│
▼
┌─────────────┐
│ Token │
│ Embedding │ (no positional embedding — RoPE handles position)
└──────┬──────┘
│
▼
┌──────────────────────────────────┐
│ Transformer Block (×6) │
│ │
│ ┌─────────────────────────┐ │
│ │ LayerNorm │ │
│ │ Causal Self-Attention │ │
│ │ └─ RoPE on Q, K │ │
│ │ └─ Causal Mask │ │
│ │ + Residual Connection │ │
│ ├─────────────────────────┤ │
│ │ LayerNorm │ │
│ │ SwiGLU Feed-Forward │ │
│ │ + Residual Connection │ │
│ └─────────────────────────┘ │
└──────────────┬───────────────────┘
│
▼
┌──────────────────┐
│ Final LayerNorm │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ Linear Head │ (weight-tied with embedding)
│ → Vocab Logits │
└──────────────────┘
1import torch
2from tokenizers import Tokenizer
3
4# Load tokenizer
5tokenizer = Tokenizer.from_file("zeronet-1-28M/tokenizer.json")
6
7# Define model class (ZeroNet1 from training script), then:
8model = ZeroNet1(config)
9model.load_state_dict(torch.load("zeronet-1-28M/pytorch_model.bin", map_location="cpu"))
10model.eval()
11Text Generation
12Python
13
14prompt = "Once upon a time"
15encoded = tokenizer.encode(prompt)
16input_ids = torch.tensor([encoded.ids])
17
18with torch.no_grad():
19 for _ in range(100):
20 logits, _ = model(input_ids)
21 next_token_logits = logits[0, -1, :] / 0.8 # temperature
22 probs = torch.softmax(next_token_logits, dim=-1)
23 next_token = torch.multinomial(probs, num_samples=1)
24 input_ids = torch.cat([input_ids, next_token.unsqueeze(0)], dim=-1)
25
26output = tokenizer.decode(input_ids[0].tolist())
27print(output)
28Chat Mode
29Python
30
31prompt = "<|user|>\nWhat is the sun?\n<|assistant|>\n"
32# Feed to model and generate as above
33What This Model Demonstrates
34This project demonstrates practical understanding of:
35
36✅ Transformer architecture (not just API calls)
37✅ Custom tokenizer training (BPE from scratch)
38✅ Rotary Positional Embeddings (RoPE)
39✅ SwiGLU activation functions
40✅ Pre-norm architecture
41✅ Weight tying
42✅ Causal masking for autoregressive generation
43✅ Mixed precision training (FP16)
44✅ Cosine learning rate scheduling with warmup
45✅ Gradient clipping
46✅ Next-token prediction objective
47✅ Top-k and top-p (nucleus) sampling
48✅ Chat fine-tuning with masked loss
49✅ Post-training INT8 quantization
50✅ End-to-end ML pipeline
51Limitations
52Be honest about what this model is and is not.
53
54What it IS:
55An educational project demonstrating LLM internals
56A proof of concept for from-scratch training
57A portfolio piece showing engineering competence
58Capable of generating coherent short stories (TinyStories domain)
59What it is NOT:
60❌ A production-ready language model
61❌ Factually reliable
62❌ Safe for deployment without content filters
63❌ Comparable to GPT-4, LLaMA, or any large-scale model
64❌ Trained with RLHF or safety alignment
65❌ Suitable for real-world applications
66Known Limitations:
67Small context window (256 tokens)
68Limited to simple English text (TinyStories domain)
69May produce repetitive or nonsensical output
70No safety filtering or content moderation
71Chat capability is minimal (trained on ~20 QA pairs)
72
73Technical Notes
74Why RoPE instead of absolute positional embeddings?
75Encodes relative position, not absolute
76Better generalization to unseen sequence lengths
77Used in LLaMA, Mistral, Qwen, GPT-NeoX
78Applied to Q and K only (never V)
79Why SwiGLU instead of GELU/ReLU?
80Better gradient flow during training
81Used in LLaMA, PaLM, Mistral
82Slightly more parameters but measurably better performance
83Why Pre-norm instead of Post-norm?
84Easier to train (more stable gradients)
85Standard in all modern LLMs (GPT-2+, LLaMA, etc.)
86Original Vaswani (2017) used post-norm, but the field moved on
87Why Weight Tying?
88Reduces parameter count
89Embedding and output head share the same weight matrix
90Standard practice since GPT-2
91Citation
92If you use this model or code for educational purposes:
93
94Hardware
95Component Specification
96Training Device NVIDIA GPU
97Also runs on CPU (slower), Apple MPS
98VRAM Required ~4 GB minimum
99Training Time 1-3 hours (GPU), 12-24 hours (CPU)
100Contact
101For questions about the architecture or training process, open an issue in the repository.
102
103Built from scratch. No shortcuts. No pretrained weights. No API wrappers.
104
105text
106
107
108---
109
110## What Each Metadata Field Maps To
111
112| HF Metadata Field | Value in YAML | Purpose |
113|---|---|---|
114| `license` | `mit` | Shows license badge |
115| `datasets` | `roneneldan/TinyStories` | Links to dataset page |
116| `language` | `en` | Shows language tag |
117| `metrics` | `perplexity` | Shows evaluation metric |
118| `pipeline_tag` | `text-generation` | Enables inference widget category |
119| `library_name` | `pytorch` | Shows framework badge |
120| `tags` | list of tags | Searchable tags on HF Hub |
121| `model-index` | eval results block | Populates eval results table |
122
123## Important
124
125**Before committing, update these placeholder values:**
126
127| Placeholder | Replace With |
128|---|---|
129| `Your Name` in citation | Your actual name |
130| `value: 0.0` in metrics | Your actual perplexity score from training |
131| Contact section | Your actual contact method |