--- license: mit pipeline_tag: text-to-image library_name: numpy tags: - hand-written-weights - no-training - interpretability - toy-model - childrens-books --- # Hand Weights: a picture-book model with no training Every one of this model's **27,875 parameters was written by hand** or derived from geometry. There is no dataset, no training run and no gradient descent. You can open the weights and say what each number does: one row of a plane tensor is literally the left edge of the cat's ear. It draws simple children's-book scenes from a sentence, and turns a short story into one page per sentence, keeping each character the same colour from page to page. **Try it:** [Space: Vishwasaidev/hand-weights](https://huggingface.co/spaces/Vishwasaidev/hand-weights) (runs in your browser) ![story](story_sheet.png) ![demo](demo_sheet.png) ## Architecture | Stage | What it is | Weights | |---|---|---| | Embedding | 153 words → 46-dim vectors with slots for shape, pronoun, colour, position, size, expression, copula, conjunction, sky, ground | `encoder.embedding` (153×46) | | Binder | gated recurrence with two registers: adjectives carry forward to the next object ("a **sleepy** cat"), position phrases bind back ("a cat **on the left**"), and after a copula adjectives bind back too ("the cat **was sleepy**") | masks, no free weights | | Slot decoder | linear layers that fall back to per-shape default colour / size / height | `decoder.default_*` | | Layout | spreads unplaced objects; a prop that follows a character is held by it (grip point on the prop → hand or foot anchor on the character) | `layout.prop_grip_scale`, `layout.hand` | | Renderer, layer 1 | half-plane neurons per pixel: `s·(d − nx·x − ny·y)` | `renderer..part…` rows of `(nx, ny, d)` | | Renderer, layer 2 | min-pool over a leaf's half-planes (exact AND at any size), then OR / AND-NOT / AND neurons compose leaves: circles and ellipses (32 tangent planes), a 5-point star (pentagon + 5 triangles), smiles (ring ∧ half-plane) | structure in metadata | | Renderer, layer 3 | sigmoid, linear shading neuron, alpha-compositing gate. **Ink outlines** are the same shape with every bias `d` grown by ~2.4 px, drawn first in ink | constants | Characters (cat, bunny, bear, kid) are part stacks plus one of 20 face stacks (`renderer.face..`): happy, sad (frown, brows, tear), sleepy (closed-arc eyes and a Z), surprised, angry. The 27,188 numbers in `weights.safetensors` are the tensors; the rest are per-part colours and flags stored in the `renderer_structure` metadata. Skies, rain, water, grass and stars are hand-written formulas in the code, not neurons. **Story mode is plain code, not weights:** it splits sentences, resolves he/she/it/they to the previous page's characters, remembers each character's colour, and carries the scene forward when a sentence doesn't name one. ## Usage ```bash python handweights.py "a sleepy orange cat with a red balloon on the grass" # -> out/.png python handweights.py --story "The bunny was happy. She found a pink flower. They were sleepy at night." python handweights.py --demo python export_weights.py # regenerates weights.safetensors ``` Requires only `numpy` and `pillow`. `handweights.py` is the source of truth; the safetensors file is an inspectable dump of the same numbers (vocab, embedding layout and renderer structure are in its metadata). ## Vocabulary - **Characters:** cat, bunny, bear, kid (+ kitten, rabbit, teddy, child, boy, girl) - **Feelings:** happy, sad, sleepy, surprised, angry (+ synonyms like tired, grumpy, crying, shocked) - **Props they hold:** balloon, ball, flower, umbrella - **Things:** sun, moon, star, cloud, house, tree, heart, circle, square, triangle - **Colours:** red, orange, yellow, green, blue, purple, pink, white, black, brown, gray, cyan, gold, silver - **Positions / sizes:** left, right, top, bottom, center · tiny, small, medium, big, huge - **Scenes:** day, night, sunset, rain, space · grass, sea, desert, snow (+ synonyms like meadow, beach, winter) ## Limitations - 153 known words; anything else is ignored (the app shows which). - No counting ("two cats" draws one), no actions or poses beyond standing and holding, no relations ("the cat sat under the tree" just places both). Every character faces forward. - "It started to rain" resolves "it" to the last character. That's harmless here, but it shows the pronoun rule is naive. - It can't learn or generalise. Every new character is roughly an hour of hand geometry. ## Why A response to claims that you can "set weights on a new model without training". You can, if the model is small and the task is designed so each neuron has a nameable job. This is what that looks like, and the trade-off is also its strength for children's books: the same character looks identical on every page, and it can only ever draw what is in its parts list.