Model Card for ESP32 Bard Lite
A 2.9-million-parameter transformer (1.1 million in its core), trained from scratch on Shakespeare's plays, that writes new scenes on an ESP32-S3 microcontroller (M5Stack CoreS3). The CoreS3 types each scene into a computer as a USB keyboard, as the model writes it.
Model Details
Model Description
The model starts at its end-of-text token and writes speeches in this layout: a speaker's name and a colon on one line, the lines spoken, a blank line, then the next speaker. It runs on the ESP32-S3 with 4-bit weights at about 13 tokens a second, up to 256 tokens a scene.
- Developed by: Justin McLean
- Model type: decoder-only transformer with per-layer embeddings, byte-level BPE tokenizer with 2,048 tokens learnt from the plays
- Language: English (Early Modern)
- License: MIT
- Inference code: justinmclean/esp32-ai, a fork of slvDev/esp32-ai (MIT)
Model Sources
- Repository: https://github.com/justinmclean/esp32-bard-lite
Uses
Direct Use
Writing made-up Shakespeare scenes for fun, demos and learning, on an ESP32-S3 board.
Out-of-Scope Use
Anything that needs the text to make sense or be accurate Shakespeare: quotes, study notes, or text passed off as his.
Bias, Risks, and Limitations
- The scenes don't make sense for long: lines sound right, but the meaning wanders within a sentence or two.
- About one word in 30 (3.6%) isn't in Shakespeare, and names get blended.
- Characters from different plays meet in the same scene.
- It reflects the plays' language and attitudes, from around 1600.
Recommendations
Use temperature 0.8 (the device's setting) with top-k 40.
How to Get Started with the Model
On an M5Stack CoreS3, from the GitHub repository's firmware/ folder, with the CoreS3 in
download mode (hold reset about 3 seconds until the green LED lights):
pio run -t upload_model
pio run -t upload
Tap reset to start it, then tap Write a scene.
Files
model.bin: the device model, 4-bit weights (1.5 MB). Flashed at 0xC00000.tokenizer.json: the byte-level BPE tokeniser (2,048 tokens).bard-lite.safetensors: full-precision weights (11 MB), for fine-tuning. The repository'straining/weights.pyturns them into a checkpoint training can start from.
Training Details
Training Data
The plays from Project Gutenberg's Complete Works of William Shakespeare (ebook 100, public
domain). The repository's training/convert_complete_works.py keeps the speeches (29,711,
by 928 speakers, 4.4 MB) and drops title pages, cast lists, act and scene headings, stage
directions, the sonnets and poems, and Project Gutenberg's licence text. Curly quotes,
dashes and accented letters become plain ASCII. The speeches are cut into pieces of a few
whole speeches (up to about 600 characters), each ending in the end-of-text token: 1.5
million tokens. The last 5% (The Winter's Tale and part of The Two Noble Kinsmen) is held
out for validation.
Training Procedure
Trained from random weights for 1,600 steps (batch 16 x 256 tokens, about 4 passes over the data; AdamW, learning rate 1e-3 with 100 warmup steps and cosine decay), on next-token prediction. A 5,000-step run showed held-out loss best at about 1,500 steps, then rising as the model began memorising lines, so training stops at 1,600. The last 300 steps are quantisation-aware: forward and backward use the weights rounded to 4 bits as the device has them, and updates go to the full-precision weights.
Speeds, Sizes, Times
- 2.9 million parameters (1.1 million in the core); 1.5 MB on the device at 4 bits
- About 4 minutes of training on an Apple M3 MacBook
- On the device: about 13 tokens a second
Evaluation
Results
- Held-out loss 3.99 (perplexity 54).
- 12 scenes, 1,523 words: 3.6% of words aren't anywhere in the complete works, against 10% for a first version trained on tiny Shakespeare (a quarter as much text).
- No copying: none of 1,516 runs of 8 words appears in the plays.
Technical Specifications
Model Architecture and Objective
6 transformer layers, width 96, 4 attention heads, SwiGLU feed-forward, RoPE positions, per-layer embeddings of width 128, output head tied to the token embedding, 2,048-token vocabulary. Context 256 tokens. Next-token cross-entropy.
Compute Infrastructure
- Training: Apple M3 MacBook (PyTorch, MPS)
- Inference: ESP32-S3 (M5Stack CoreS3) with 8 MB PSRAM
Licence
MIT. Shakespeare's plays are public domain; the text is from Project Gutenberg.
