Add human-friendly README
Browse files
README.md
CHANGED
|
@@ -1,188 +1,122 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
| 3 |
tags:
|
| 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 |
-
| 3.9875 | 5.4600 | 14600 | 3.8599 |
|
| 121 |
-
| 4.0528 | 5.5348 | 14800 | 3.8533 |
|
| 122 |
-
| 3.9126 | 5.6096 | 15000 | 3.8485 |
|
| 123 |
-
| 4.0453 | 5.6844 | 15200 | 3.8422 |
|
| 124 |
-
| 3.8323 | 5.7592 | 15400 | 3.8367 |
|
| 125 |
-
| 3.9323 | 5.8340 | 15600 | 3.8336 |
|
| 126 |
-
| 3.8529 | 5.9088 | 15800 | 3.8309 |
|
| 127 |
-
| 3.8784 | 5.9835 | 16000 | 3.8198 |
|
| 128 |
-
| 3.9129 | 6.0583 | 16200 | 3.8198 |
|
| 129 |
-
| 3.8845 | 6.1331 | 16400 | 3.8169 |
|
| 130 |
-
| 3.7315 | 6.2079 | 16600 | 3.8141 |
|
| 131 |
-
| 3.8735 | 6.2827 | 16800 | 3.8041 |
|
| 132 |
-
| 3.8643 | 6.3575 | 17000 | 3.8056 |
|
| 133 |
-
| 3.871 | 6.4323 | 17200 | 3.7992 |
|
| 134 |
-
| 3.9184 | 6.5071 | 17400 | 3.8034 |
|
| 135 |
-
| 3.8936 | 6.5819 | 17600 | 3.7936 |
|
| 136 |
-
| 3.8913 | 6.6567 | 17800 | 3.7887 |
|
| 137 |
-
| 3.8066 | 6.7315 | 18000 | 3.7871 |
|
| 138 |
-
| 3.843 | 6.8063 | 18200 | 3.7838 |
|
| 139 |
-
| 3.9506 | 6.8811 | 18400 | 3.7783 |
|
| 140 |
-
| 3.7878 | 6.9559 | 18600 | 3.7754 |
|
| 141 |
-
| 3.877 | 7.0307 | 18800 | 3.7725 |
|
| 142 |
-
| 3.8744 | 7.1055 | 19000 | 3.7680 |
|
| 143 |
-
| 3.8774 | 7.1803 | 19200 | 3.7669 |
|
| 144 |
-
| 3.8095 | 7.2550 | 19400 | 3.7645 |
|
| 145 |
-
| 3.8195 | 7.3298 | 19600 | 3.7638 |
|
| 146 |
-
| 3.9152 | 7.4046 | 19800 | 3.7587 |
|
| 147 |
-
| 3.8205 | 7.4794 | 20000 | 3.7546 |
|
| 148 |
-
| 3.7736 | 7.5542 | 20200 | 3.7520 |
|
| 149 |
-
| 3.8518 | 7.6290 | 20400 | 3.7499 |
|
| 150 |
-
| 3.8738 | 7.7038 | 20600 | 3.7444 |
|
| 151 |
-
| 3.8431 | 7.7786 | 20800 | 3.7438 |
|
| 152 |
-
| 3.7439 | 7.8534 | 21000 | 3.7388 |
|
| 153 |
-
| 3.9137 | 7.9282 | 21200 | 3.7376 |
|
| 154 |
-
| 3.7964 | 8.0030 | 21400 | 3.7338 |
|
| 155 |
-
| 3.7578 | 8.0778 | 21600 | 3.7363 |
|
| 156 |
-
| 3.786 | 8.1526 | 21800 | 3.7312 |
|
| 157 |
-
| 3.7942 | 8.2274 | 22000 | 3.7285 |
|
| 158 |
-
| 3.8115 | 8.3022 | 22200 | 3.7272 |
|
| 159 |
-
| 3.8123 | 8.3770 | 22400 | 3.7248 |
|
| 160 |
-
| 3.8411 | 8.4518 | 22600 | 3.7245 |
|
| 161 |
-
| 3.8563 | 8.5266 | 22800 | 3.7208 |
|
| 162 |
-
| 3.8441 | 8.6013 | 23000 | 3.7179 |
|
| 163 |
-
| 3.8005 | 8.6761 | 23200 | 3.7152 |
|
| 164 |
-
| 3.6688 | 8.7509 | 23400 | 3.7147 |
|
| 165 |
-
| 3.8191 | 8.8257 | 23600 | 3.7098 |
|
| 166 |
-
| 3.8469 | 8.9005 | 23800 | 3.7087 |
|
| 167 |
-
| 3.8563 | 8.9753 | 24000 | 3.7079 |
|
| 168 |
-
| 3.7861 | 9.0501 | 24200 | 3.7058 |
|
| 169 |
-
| 3.7502 | 9.1249 | 24400 | 3.7046 |
|
| 170 |
-
| 3.6903 | 9.1997 | 24600 | 3.7032 |
|
| 171 |
-
| 3.7698 | 9.2745 | 24800 | 3.7019 |
|
| 172 |
-
| 3.6781 | 9.3493 | 25000 | 3.7021 |
|
| 173 |
-
| 3.7236 | 9.4241 | 25200 | 3.6995 |
|
| 174 |
-
| 3.7578 | 9.4989 | 25400 | 3.6996 |
|
| 175 |
-
| 3.6315 | 9.5737 | 25600 | 3.6985 |
|
| 176 |
-
| 3.6605 | 9.6485 | 25800 | 3.6965 |
|
| 177 |
-
| 3.7707 | 9.7233 | 26000 | 3.6958 |
|
| 178 |
-
| 3.7968 | 9.7981 | 26200 | 3.6953 |
|
| 179 |
-
| 3.8238 | 9.8728 | 26400 | 3.6939 |
|
| 180 |
-
| 3.7834 | 9.9476 | 26600 | 3.6938 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
### Framework versions
|
| 184 |
-
|
| 185 |
-
- Transformers 4.57.0
|
| 186 |
-
- Pytorch 2.8.0
|
| 187 |
-
- Datasets 4.0.0
|
| 188 |
-
- Tokenizers 0.22.1
|
|
|
|
| 1 |
---
|
| 2 |
+
language: en
|
| 3 |
+
license: mit
|
| 4 |
tags:
|
| 5 |
+
- text-generation
|
| 6 |
+
- gpt2
|
| 7 |
+
- transformers
|
| 8 |
+
- custom-tokenizer
|
| 9 |
+
datasets:
|
| 10 |
+
- wikitext
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# 🤖 Nano GPT - Built From Scratch
|
| 14 |
+
|
| 15 |
+
Hey there! Welcome to my tiny language model. I built this GPT from scratch as a learning project, and honestly, it was pretty fun watching it learn to generate text!
|
| 16 |
+
|
| 17 |
+
## What is this?
|
| 18 |
+
|
| 19 |
+
This is a super small GPT-2 style language model that I trained on my laptop. It's not going to write your essays or solve world hunger, but it's a cool demonstration of how these language models actually work under the hood.
|
| 20 |
+
|
| 21 |
+
Think of it as a baby GPT - it can generate text, but don't expect Shakespeare. More like... an enthusiastic toddler who just learned to talk.
|
| 22 |
+
|
| 23 |
+
## Model Stats
|
| 24 |
+
|
| 25 |
+
- **Parameters**: ~1,065,728 (yes, that's million with an M, not billion!)
|
| 26 |
+
- **Layers**: 4 transformer layers
|
| 27 |
+
- **Embedding Size**: 128 dimensions
|
| 28 |
+
- **Attention Heads**: 4 heads
|
| 29 |
+
- **Context Length**: 128 tokens
|
| 30 |
+
- **Vocab Size**: 2000 tokens
|
| 31 |
+
- **Training Data**: WikiText-2 (5,000 samples)
|
| 32 |
+
- **Training Time**: 10 epochs on my laptop
|
| 33 |
+
|
| 34 |
+
## Quick Start
|
| 35 |
+
|
| 36 |
+
Want to try it out? Here's how:
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
from transformers import pipeline
|
| 40 |
+
|
| 41 |
+
# Load the model
|
| 42 |
+
generator = pipeline('text-generation', model='Tanaybh/nano-gpt-from-scratch')
|
| 43 |
+
|
| 44 |
+
# Generate some text
|
| 45 |
+
output = generator(
|
| 46 |
+
"The meaning of life is",
|
| 47 |
+
max_new_tokens=30,
|
| 48 |
+
do_sample=True,
|
| 49 |
+
temperature=0.8
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
print(output[0]['generated_text'])
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## Example Output
|
| 56 |
+
|
| 57 |
+
I gave it the prompt: "**The **"
|
| 58 |
+
|
| 59 |
+
And it generated:
|
| 60 |
+
|
| 61 |
+
> The × 60 munitions, and injuries were found in the taxonomy in the south, the east of the
|
| 62 |
+
|
| 63 |
+
Not bad for a tiny model trained in a few hours, right?
|
| 64 |
+
|
| 65 |
+
## Training Details
|
| 66 |
+
|
| 67 |
+
I trained this model from scratch using:
|
| 68 |
+
- Custom BPE tokenizer (trained on the same data)
|
| 69 |
+
- GPT-2 architecture (just way smaller)
|
| 70 |
+
- AdamW optimizer with a learning rate of 0.0005
|
| 71 |
+
- Batch size of 8
|
| 72 |
+
- Trained for 10 epochs
|
| 73 |
+
|
| 74 |
+
The whole thing runs on a regular laptop - no fancy GPU clusters needed!
|
| 75 |
+
|
| 76 |
+
## Limitations
|
| 77 |
+
|
| 78 |
+
Let's be real here:
|
| 79 |
+
- This model is TINY. Like, really tiny. It has 1,065,728 parameters vs GPT-3's 175 billion.
|
| 80 |
+
- It was only trained on 5,000 Wikipedia samples, so its knowledge is... limited.
|
| 81 |
+
- It might generate weird or nonsensical text sometimes. That's part of the charm!
|
| 82 |
+
- Maximum context length is only 128 tokens, so don't expect long conversations.
|
| 83 |
+
- It's a base model with no instruction tuning, so it just continues text rather than following commands.
|
| 84 |
+
|
| 85 |
+
## Why I Made This
|
| 86 |
+
|
| 87 |
+
I wanted to understand how language models work by building one myself. Sure, I could've just fine-tuned a pre-trained model, but where's the fun in that? This project taught me about:
|
| 88 |
+
- Tokenizer training
|
| 89 |
+
- Transformer architecture
|
| 90 |
+
- Training dynamics
|
| 91 |
+
- How LLMs actually generate text
|
| 92 |
+
|
| 93 |
+
Plus, now I can say I trained a language model from scratch on my laptop. Pretty cool, right?
|
| 94 |
+
|
| 95 |
+
## Future Improvements
|
| 96 |
+
|
| 97 |
+
Some things I might try:
|
| 98 |
+
- Train on more data (maybe the full WikiText dataset)
|
| 99 |
+
- Experiment with different model sizes
|
| 100 |
+
- Try different tokenizer configurations
|
| 101 |
+
- Add instruction tuning
|
| 102 |
+
- Fine-tune it for specific tasks
|
| 103 |
+
|
| 104 |
+
## License
|
| 105 |
+
|
| 106 |
+
MIT - Feel free to use this however you want! Learn from it, break it, improve it. That's what it's here for.
|
| 107 |
+
|
| 108 |
+
## Acknowledgments
|
| 109 |
+
|
| 110 |
+
Built with:
|
| 111 |
+
- 🤗 Hugging Face Transformers
|
| 112 |
+
- PyTorch
|
| 113 |
+
- The WikiText dataset
|
| 114 |
+
- Too much coffee ☕
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
**Note**: This is a learning project and experimental model. Use it for fun and education, not production systems!
|
| 119 |
+
|
| 120 |
+
If you found this interesting or helpful, feel free to star the repo or reach out. Always happy to chat about ML stuff!
|
| 121 |
+
|
| 122 |
+
*Last updated: October 05, 2025*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|