Model Card for ESP32 Recipe Maker
An 8.2-million-parameter transformer (1.1 million in its core) that writes new recipes, in Australian style, on an ESP32-S3 microcontroller (M5Stack CoreS3), with nothing off the chip. Pick a main ingredient and a kind of dish, and it writes a title, an ingredient list and a method in 20 to 30 seconds.
Model Details
Model Description
The model is prompted with Main: <main>, Dish: <dish> and Title:, and writes the
rest of the recipe as text. There are 14 mains (chicken, beef, lamb, pork, prawns, fish,
pasta, rice, eggs, potato, pumpkin, mushroom, chocolate, banana) and 12 kinds of dish
(soup, salad, curry, stir-fry, pasta, stew, roast, pie, BBQ, patties, dessert, anything);
110 of the pairs have enough training recipes to use. It runs on the ESP32-S3 with 4-bit
weights at 9 to 10 tokens a second.
- Developed by: Justin McLean
- Model type: decoder-only transformer with per-layer embeddings, byte-level BPE tokenizer with 8,192 tokens
- Language: English (Australian)
- License: CC BY-NC 4.0
- Inference code: justinmclean/esp32-ai, a fork of slvDev/esp32-ai (MIT)
Model Sources
Uses
Direct Use
Writing made-up recipes for fun, demos and learning, on an ESP32-S3 board or on a
computer (the repository's host/recipe.c).
Out-of-Scope Use
Real cooking without checking the recipe first, and anything where food safety matters (cooking temperatures and times, allergens, preserving). Commercial use: the training data's terms allow only non-commercial research and educational use (see Licence).
Bias, Risks, and Limitations
- The recipes are invented. Quantities, cooking times and temperatures can be wrong, and a method can skip an ingredient or use one the list lacks.
- The training recipes come from US websites, converted to Australian style by rules. Some American dishes and ingredients remain.
- Recipes are sampled, so quality varies from one to the next.
Recommendations
Read a recipe through before cooking it, and check cooking temperatures and times. Use temperature 0.7 (the device's setting): higher gives more variety and more mistakes.
How to Get Started with the Model
On a computer, with only a C compiler, from the GitHub repository:
cc -O2 -o recipe host/recipe.c -lm
./recipe pumpkin soup
On an M5Stack CoreS3, from the repository's firmware/ folder:
pio run -e m5stack-cores3 -t upload_model
pio run -e m5stack-cores3 -t upload
Files
model.bin: the device model, 4-bit weights (4.2 MB). Flashed at 0x190000.tokenizer.json: the byte-level BPE tokenizer (8,192 tokens).recipe-maker.safetensors: full-precision weights (33 MB), for fine-tuning. The repository'straining/weights.pyturns them into a checkpoint training can start from.
Training Details
Training Data
RecipeNLG (2.2 million recipes from US websites; the copy at
SandhyaKilari/RecipeNLG_dataset),
converted to Australian style by the repository's training/convert_recipenlg.py: metric
units and standard can and packet sizes, Australian ingredient names and spelling, and
Celsius. Each kept recipe is filed under a main and a kind of dish. About 9% of
RecipeNLG is kept: 42% is dropped as coming from two US sites (cookbooks.com and
kraftrecipes.com), 29% has no main from the picker, 9% is too long for the 256-token
window, 6% has no proper method, and 5% is built on US convenience products. Ingredient lists are sorted A to Z and
repeated lines removed. 191,930 recipes remain (34.9 million training tokens); the 5,496
from Australian websites appear three times.
Training Procedure
Next-token prediction, plus three unlikelihood penalties inside each recipe: against listing an ingredient already listed (weight 3), against a method using ingredient words its list lacks (weight 3) and against repeating a word within a list in a method step (weight 1). Then 1,000 steps of quantisation-aware training: each step runs on the weights rounded to 4 bits as the device holds them and updates the full-precision ones. Rounding cost the model 0.112 in held-out loss before this stage and 0.004 after it.
Training Hyperparameters
- 20,000 steps, batch 16 x 256 tokens, AdamW, learning rate 1e-3 with 200 warmup steps and cosine decay
- Quantisation-aware fine-tune: 1,000 steps, learning rate 1e-4 with 20 warmup steps
- Training regime: fp32; each training window starts at the start of a recipe
Speeds, Sizes, Times
- 8,177,120 parameters: 1,099,232 in the transformer core, 6,291,456 in the per-layer embedding table and 786,432 in the token embedding (also the output layer)
- 4.2 MB on the device at 4 bits
- About 85 minutes of training on an Apple M3 MacBook
- 9 to 10 tokens a second on an ESP32-S3 at 240 MHz; a recipe takes 10 to 25 seconds
Evaluation
Testing Data, Factors & Metrics
260 recipes, 20 for each of 13 picks covering every kind of dish, at temperature 0.7,
written with the weights rounded to 4 bits as on the device and checked by the
repository's training/pick_test.py for:
- Layout: a title, an ingredient list and a numbered method.
- Main in the list: the main ingredient picked appears in the ingredient list.
- Method strays: the method uses an ingredient the list does not have.
- Repeats: an ingredient listed twice.
Results
| Recipes | |
|---|---|
| Layout right | 251 of 260 |
| Main ingredient in the list | 236 of 260 (91%) |
| Method strays | 20 of 260 (8%) |
| Ingredient listed twice | 7 of 260 (3%) |
Validation loss on the device's 4-bit weights 1.976 (perplexity 7.2). Before the quantisation-aware fine-tune it was 2.050, with the main ingredient in 220 of 260 lists and an ingredient listed twice in 20.
Technical Specifications
Model Architecture and Objective
6 transformer layers, width 96, 4 attention heads, SwiGLU feed-forward (hidden width 379), RoPE positions, per-layer embeddings of width 128, output head tied to the token embedding. Context 256 tokens.
Compute Infrastructure
- Training: Apple M3 MacBook (PyTorch, MPS)
- Inference: ESP32-S3 (M5Stack CoreS3) with 8 MB PSRAM, or any computer
Licence
CC BY-NC 4.0. Trained on RecipeNLG (Bień et al., 2020), whose terms allow only non-commercial research and educational use.
