nanoGPT SLM -- 124.0M Parameter Children's Story Generator
A small language model trained entirely from scratch using a custom nanoGPT (GPT-2 small) implementation.
Pretrained on the TinyStories dataset to generate short, coherent stories for young children (ages 3-5).
What This Model Does
This model generates short children's stories suitable for 3-5 year olds. Give it the beginning
of a story and it will continue writing in simple, age-appropriate language:
Input: "Once upon a time there was a little rabbit"
Output: "Once upon a time there was a little rabbit who lived in a big forest.
The rabbit loved to hop and play with his friends. One day, he
found a shiny red ball near the river..."
Capabilities:
Generates coherent short stories (100-500 words) using the pretrained model from scratch
Uses simple vocabulary appropriate for young children
Follows common story patterns (characters, conflict, resolution)
The TinyStories dataset was specifically designed to study whether small language models
can learn coherent language generation when trained on high-quality, simple text.
Each story was tokenized with Unicode normalization (smart quotes, em dashes, etc.
converted to ASCII) and separated by <|endoftext|> (token 50256) so the model
learns clean story boundaries.
Quick Start
Method 1: Using Gradio Chat UI (Best way to test the model capability)
Image model: Qwen/Qwen-Image-2512 via HF Inference API
Method 2: Programmatically downloading & using the nanogpt_slm_tinystories_best.pth model
Option 1: Run directly (downloads model + generates sample stories with predefined prompts)
bash
1# Download `nanogpt_slm_pretrained_inference_tinystories.py` in working directory23!pip install torch tiktoken huggingface_hub
4!python nanogpt_slm_pretrained_inference_tinystories.py
Option 2: Import and use in your own code to generate children's short stories
python
1# pip install torch tiktoken huggingface_hub2# Download `nanogpt_slm_pretrained_inference_tinystories.py` in working directory34# Method 1 -- Quick story generation5from nanogpt_slm_pretrained_inference_tinystories import tell_story, ask, generate_text
67# story = tell_story("Once upon a time there was a little kitten")8story = tell_story(input("Enter a story prompt (e.g., 'Once upon a time there was a little kitten'): ").strip())9print(story)10print("--------------------")1112# Method 2 -- Simple text completion13# print(ask("The friendly dragon lived in"))14print(ask(input("Enter a prompt for text completion (e.g., 'The friendly dragon lived in'): ").strip()))15print("--------------------")1617# Method 3 -- Fine-grained control18print(generate_text(19"A girl named Lily went to the park",20 max_tokens=500,# generous budget -- EOS stops at story end (Max Context length = 512)21 temperature=0.8,# 0.01=predictable, 0.8=balanced, 1.5=creative22 top_k=40# sampling diversity23))24print("--------------------")
Low-level text generation with full parameter control.
Parameter
Default
Description
prompt / beginning
(required)
Text to continue from
max_tokens
500
Maximum tokens to generate (EOS stops earlier)
temperature
0.8
0.01 = predictable, 0.8 = balanced, 1.5 = wild
top_k
40
Top-k filtering (None = no filtering)
Example Outputs
Prompt: "Once upon a time there was a little bear"
Once upon a time there was a little bear who lived in a big forest. The bear
loved to play with his friends. One sunny day, he went for a walk and found
a beautiful flower. He picked it up and brought it home to show his mama...
Prompt: "The princess looked out her window and saw"
The princess looked out her window and saw a big rainbow in the sky. She was
so happy! She ran outside to get a closer look. A little bird flew down and
sat on her hand. "Hello!" said the princess...
Fine-tuned Variants (experimental versions finetuned on different datasets)