topaz-gregg-shorthand-117m
Topaz-117M is a CTC (Connectionist Temporal Classification)-based model for transcribing Gregg Anniversary Shorthand.
To achieve this, Topaz-117M does not predict English text directly. Instead, it predicts Grascii, which is a representation of Gregg shorthand strokes in ASCII format. This reduces the burden on the model tremendously by limiting its task to the reading of strokes instead of requiring it to perform the complicated language modeling necessary to convert phonetic stroke representations into English tokens. To facilitate the conversion of the output Grascii into an English representation, we provide an intermediate representation consisting of each word in Grascii combined with suggestions from the Grascii to English dictionary, as well as a prompt for instruction-tuned LLMs instructing it to recover the original plain-text from this intermediate representation. We have found that frontier language models produce fairly good results with this setup, as they are quite intelligent and are able to guess a lot from context even in the face of transcription errors.
This model performs worse than (Topaz-61M)[https://huggingface.co/amongglue/topaz-gregg-shorthand-61m], the smaller version, as it was trained for less time.
Evaluation
On the exercises detailed in "Gregg Shorthand Functional Method Part Two" by Louis A. Leslie, the model achieves 83.0% stroke accuracy.
Demonstrations

- Transcription (Topaz-61M): I-L G T-U TH M-A-T
- Intermediate (using Grascii dictionary): I-L (while/I will/why will/isle/aisle) G (good/go) T-U (to/two/too/it you/at you) TH (the/their/there) M-A-T (matter/might/mat/my it/my at)
- Prediction (gpt-6-luna, thinking enabled): I'll go to the mat.

- Transcription (Topaz-61M): T TH R T L-N G L
- Intermediate (using Grascii dictionary): T (it/at) TH (the/their/there) R (are/our/hour) T (it/at) L-N (will not/will in/well in) G (good/go) L (will/well)
- Prediction (Gemini 3.8 flash, medium thinking): At the hour, it will not go well.
The text below this line is AI-generated.
Evaluation details
Error rates are edit distances over stroke tokens (stroke error) or over whole outlines (outline error), divided by the reference length, scored per paragraph. The Functional Method Part Two plates were never trained on; their even paragraphs form a validation half and their odd paragraphs a test half.
The evaluation set was rebuilt for this release. In the earlier version, some printed paragraph numbers on the plates were garbled in the PDF's text layer (ZS2. for 282.), so the lines of 14 paragraphs were scored against only part of their text. The corrected set gives every line its own paragraph's text. Both sets are shown so the numbers stay comparable with earlier reports. The Topaz-61M columns are its current checkpoint (step 52,000); its first release (step 48,100) scored 26.8% and 30.4% stroke error on the original set.
| Data (corrected set) | Topaz-117M stroke | Topaz-117M outline | Topaz-61M stroke | Topaz-61M outline |
|---|---|---|---|---|
| Functional Method Part Two, validation half | 10.0% | 26.8% | 11.0% | 27.4% |
| Functional Method Part Two, test half | 17.0% | 35.4% | 18.3% | 35.8% |
| Data (original set) | Topaz-117M stroke | Topaz-61M stroke |
|---|---|---|
| Functional Method Part Two, validation half | 25.6% | 26.0% |
| Functional Method Part Two, test half | 28.8% | 30.2% |
(Released checkpoint: training step 110,000. Stroke error is much stricter than a word error rate: one missed circle vowel is an error even when the word is still obvious.)
Usage
pip install -r requirements.txt
python -m topaz page.png # -> page.txt, one line of outlines + suggestions per shorthand line
python -m topaz --lines line.png # the image is a single line
python -m topaz --with-prompt -o out/ *.jpg # LLM prompt followed by the transcript
python -m topaz --grascii page.png # Grascii only
From Python:
from topaz import Topaz
topaz = Topaz.from_pretrained(".") # this directory, or a Hugging Face repo id
t = topaz.transcribe("page.png") # lines=True for a single line image
print(t.grascii) # I-L G T-U TH M-A-T
print(t.intermediate()) # I-L (while/I will/...) G (good/go) ...
print(t.llm_prompt()) # paste into an instruction-tuned LLM
Inputs are photos or scans of a page (any size; the line finder rescales it) or a single line. Lines are read one at a time, so a line's reading never depends on what else is on the page. A GPU is used when available; on a CPU a line takes about half a second.
Files
| File | Contents |
|---|---|
model.safetensors, config.json | Recognizer weights (fp32) and the architectures of both networks |
segmenter.safetensors | Line finder weights |
vocab.json | The 73 CTC tokens (index 0 is the blank) |
dictionary.json | About 31,000 outlines, each with its English candidates and scores |
prompt.txt | The LLM prompt used by --with-prompt / llm_prompt() |
topaz/ | Inference code: line finder, line straightening, recognizer, greedy CTC decoding, dictionary lookup |
Dictionary lookup
Each recognized outline is looked up in dictionary.json, built from the 1930 Anniversary dictionary, the Anniversary brief forms, the 1924 phrase book and the Qwertigraphy word lists, ranked by word frequency. In order: exact matches; phrases written as two joined outlines (I-K → I can); failing that, the words of the closest outlines (stroke edit distance ≤ 2); three-part phrases as a last resort. A capital mark (=) capitalizes the suggestions.
Limitations
- The real training data and the evaluation are typeset textbook plates. Personal handwritten notes are harder (irregular proportions, personal abbreviations) and will have higher error rates.
- Only Anniversary (1929) Gregg is supported; other editions (Pre-Anniversary, Simplified, Diamond Jubilee, Centennial) use different outlines.
- The dictionary suggestions are candidates, not a transcription: shorthand is ambiguous by design (
T-Uis to/two/too), and outlines that are not in the dictionary get the words of similar outlines. - The line finder expects horizontal lines of writing; heavily curved or rotated pages and drawings mixed with text may be split into lines incorrectly.
Architecture
The model is structured into two sequential stages: a segmenter that isolates and straightens lines of shorthand from source images, and a recognizer that maps these rectified lines to CTC stroke probabilities.
Segmenter
-
Network: A lightweight U-Net with a checkpoint footprint of approximately 6 MB.
-
Encoder and Decoder: The encoder features five levels with channel dimensions of 16, 32, 64, 128, and 192. The decoder utilizes bilinear upsampling combined with skip connections.
-
Outputs (at half resolution):
- Baseline: A thin band tracing along each line's baseline.
- Body: The primary writing zone situated above the baseline, where height directly defines the line spacing ($L$).
-
Post-Processing:
- The predicted maps are traced into polylines, ordered into reading sequence column-by-column, and split cleanly at vertical rules.
- Each line is rectified by resampling along its traced baseline, effectively straightening any tilted, drifting, or wavy handwriting.
Recognizer
-
Core Design: A CTC-only architecture comprising 116.9 million parameters.
-
Input Format: Grayscale line images scaled to 128 pixels in height (with ink represented as high values) and variable widths (up to 1,600 pixels during training and 2,400 pixels during inference).
-
CNN Backbone (16.0M parameters):
- Features a 3x3 stride-2 stem followed by ResNet-style blocks with channel progressions of 64 $\to$ 128 $\to$ 256 $\to$ 512 $\to$ 512.
- Downsamples height by a factor of 32 and width by 4, resulting in 4 rows and 512 channels per column.
-
Projection: Each column ($4 \times 512 = 2,048$ features) passes through a linear layer to a dimension of 768, giving one output frame per 4 pixels of line width.
-
Transformer Encoder: 14 pre-norm layers, $d_{model} = 768$, 12 attention heads of 64 dimensions, RMSNorm, rotary position embeddings (RoPE) on queries and keys, a SwiGLU feed-forward network with hidden size 2,048, a dropout rate of 0.1, and padding masks for handling variable widths.
-
Classification Head: RMSNorm followed by a linear projection to 73 tokens, decoded using greedy CTC (where blank = token 0).
-
Intermediate CTC: An identical normalization and head applied after encoder layer 7 strictly as a training regularizer.
Training
-
Loss Function: A weighted multi-task loss defined as $0.7 \times \text{CTC} + 0.3 \times \text{intermediate CTC}$.
-
Optimizer & Regularization: AdamW with a weight decay of 0.01, gradient clipping at 1.0, fp16 mixed precision, and a batch size of 64.
-
Learning Rate Schedule: Topaz-61M used a cosine schedule from $3 \times 10^{-4}$ with 2,000 warm-up steps. Topaz-117M restarted it at its growth step: a fresh AdamW, 2,000 warm-up steps to $3 \times 10^{-4}$, then cosine to zero at step 110,000.
-
Data Mix: Each training batch consists of 60% synthetic lines (generated on-the-fly via a 20,000-line replay buffer) and 40% augmented real book lines.
-
Training History:
- Steps 0–16k: An 8-layer encoder paired with a 6-layer attention decoder, trained jointly using CTC and cross-entropy.
- Step 16k: Losslessly converted to CTC-only by inserting 6 identity encoder layers (expanding the encoder from 8 to 14 layers).
- Step 20k+: Real data introduced, with its proportion scaled incrementally ($8% \to 20% \to 30% \to 40%$), keeping each increase only if real test performance improved.
- Step 43k: CNN capacity expanded from 61.2M to 76.6M parameters with 4 extra ResBlocks (one at 1/8 resolution, two at 1/16, one at 1/32), added as exact identity blocks (zero-initialized final batch normalization) with a 2.2x learning rate multiplier. The real-data share rose to 40% at the same time.
- Step 44k: The new blocks' final batch-norm scales were raised from ~0.001 to 0.05 so they receive a useful training signal (this changed no outputs measurably).
- Step 48k: The extra blocks were removed again, back to 61.2M parameters. The optimizer had been shrinking them (to ~4% of an established block's scale) and the real test error had not improved, so the extra CNN capacity was not what the model lacked. Removing them changed no frame's best token on a probe batch; training continued briefly to settle the remaining weights. This checkpoint (step 48,100) is Topaz-61M.
- Step 50k: grown to Topaz-117M. The 61M model's step-50,000 checkpoint was converted without changing its outputs: LayerNorm became RMSNorm with the biases folded into the next layer, the width grew from 512 to 768 with 4 new attention heads whose output projections start at zero, and the ReLU feed-forward became a SwiGLU whose gate starts as a steep sigmoid (behaving like ReLU). Over the next 6,000 steps the gate was faded to SiLU, rotary position embeddings were faded in and the sinusoidal position encodings faded out, so the model moved to the new design gradually.
- Steps 78k to 80k: The evaluation set was rebuilt (see the evaluation details), and the real training books were re-aligned with the model at step 70,000 using the same paragraph-number fix, which returned about 300 more usable lines.
Synthetic Data Pipeline
-
Outlines:
- 17,766 engraved outlines sourced from the 1930 Anniversary dictionary, skeletonized into centerline graphs, and redrawn dynamically with randomized pen profiles.
- A procedural renderer built from primitive strokes following Gregg joining rules via the
grasciilibrary. Dimensions are calibrated against engraved strokes, circle vowels adhere strictly to manual rules, and smooth joins utilize tangent-blending.
-
Handwriting Simulation:
- Simulates realistic pen-motion dynamics (spring-damped pen lag that rounds corners and introduces overshoots).
- Applies elastic distortion alongside variations in slant, size, and spacing.
-
Text Generation:
- Pulls running text from public-domain literature and Wikipedia, converting word-by-word through the lexicon with proper phrasing, punctuation, and capitalization.
- Interleaves frequency-sampled random outlines to prevent the model from relying heavily on sentence context.
-
Page Composition:
- Renders across 7 paper types (white, cream, notebook, steno, legal, graph, aged) and 5 ink variations (black, blue, blue-black, pencil, faded).
- Incorporates ruled lines, margins, and surrounding printed text, placing shorthand into available free space.
- Cuts lines using the identical rectification pipeline applied during inference.
-
Labeling Rule: Labels strictly describe the visible graphical strokes rather than the underlying intended words.
Real Data Pipeline
Scanned historical textbooks with typed key texts aligned line-by-line using a bootstrap CTC model:
- Pages processed via Tesseract OCR to extract initial keys.
- Manual review and correction of OCR errors in the keys (~500 manual fixes).
- Alignment of key words directly to plate lines.
- Filtering out lines where the transcription disagreed with the reference label.
| Textbook Source | Clean Lines |
|---|---|
| Gregg Shorthand Manual, Functional Method vol. 1 | 2,791 |
| Transcription Drills | 938 |
| Fundamental Drills (1932) | 3,141 |
| Gregg Dictation & Transcription (1937) | 3,244 |
| Gregg Speed Studies (1929) | 1,628 |
| Graded Readings in Gregg Shorthand (1930) | 1,483 |
| Total | $\approx$13,200 lines, $\approx$132k words |
Real lines undergo heavy augmentation during training, including stretching, shearing, rotation, curved baseline warping via smooth remaps, stroke thickening/thinning, blurring, contrast adjustment, and background noise injection.