Every Egyptian hieroglyph has a catalogue number. Egyptologists use Alan Gardiner's sign list, so the owl is G17, the reed leaf is M17, the water ripple is N35. I wanted to see how far a small convolutional network could get at the first step of reading a wall: look at one carved sign and say which one it is.
The answer, on held-out glyphs: 96.9% right at the first guess and 99.7% within five guesses, across 59 signs. The more useful part of the story is the first model, which failed, and what fixed it.
The data
The GlyphDataset (Franken and van Gemert, ACM Multimedia 2013, MIT licence) has 4,210 manually labelled glyphs cut from ten photographs of the Pyramid Texts in the pyramid of Unas at Saqqara, each a 50×75 px greyscale crop. It covers 172 signs, but most of them appear only a handful of times, so I kept the 59 signs with at least ten examples: 3,674 glyphs, split 70/10/20 with stratification (2,571 train, 368 validation, 735 test).
The imbalance is the defining feature of this dataset. The most common sign has about 290 examples; the rarest kept signs have 10.
Run 1: a textbook setup that overfitted
My first model was the setup you see in most tutorials: three convolutional blocks, global average pooling, a dense head, heavy augmentation, and full inverse-frequency class weights to handle the imbalance.
It overfitted badly. Training accuracy reached 71% while validation accuracy stayed under 50% and fell as training went on. Three choices were working against each other:
- Full inverse-frequency weights made a 10-glyph sign count 29 times as much as a 290-glyph one. The network chased the rare signs and the loss became noisy.
- Global average pooling throws away where a feature sits in the crop. For hieroglyphs that is part of the identity: a stroke at the top of the frame and the same stroke at the bottom can belong to different signs.
- Heavy augmentation (big rotations and shifts, black fill) produced images that do not look like carved signs on light stone.
Run 2: the published model
Same data, same split, same seed, so the comparison is fair. I changed four things:
- A Flatten head instead of global pooling, so position inside the crop survives.
- Square-root-damped class weights: rare signs still count for more, but by a factor of about 5 rather than 29.
- Lighter augmentation with white fill, which matches the light stone behind the glyphs.
- BatchNorm after the dense layer, and early stopping on validation accuracy with a long patience.
It trained for 54 epochs (best at epoch 34) in 14 minutes on a laptop CPU. The model has 2.1 million parameters and is 25 MB.
| Metric (735 held-out glyphs) | Value |
|---|---|
| Top-1 accuracy | 96.9% |
| Top-5 accuracy | 99.7% |
| Macro F1 | 0.939 |
I reran the same script on a Kaggle GPU as a check: 96.7% top-1, 99.5% top-5, macro F1 0.951, in two minutes. Differences of that size are normal between runs on different hardware; the result holds.
Where it is weak
Every sign with an F1 below 0.8 has fewer than 20 training glyphs. The errors are a data problem rather than a capacity problem: more photographs would move the number, a bigger network would not.
Using it the way it would really be used
A model that is right 96.9% of the time is still wrong on one glyph in thirty. On a real wall I would not let it answer alone, so I added a confidence gate: accept the prediction only when the top probability is at least 0.95, and hand the rest to a person. At that threshold the model answers 90% of glyphs on its own at 99.5% accuracy and leaves 10% for review. That trade is easy to tune, and it is the number I would give anyone deciding whether to use it.
What it does not do
- The training photographs come from one monument, carved in one style and lit one way. A glyph from a painted tomb or a papyrus will look different.
- It names single signs that have already been cropped. Finding the signs in a wall photograph is a detection problem, and translating them is another project entirely.
- Signs with fewer than ten examples in the dataset are not covered at all.
Try it
- Live demo: Hugging Face Space (Hieroglyphs tab): drop in a glyph crop and get the top five Gardiner codes.
- Model: omaressamrme/hieroglyph-classifier
- Code, both training runs and the figures: github.com/engomaressam/hieroglyph-classifier
- GPU notebook: Kaggle
Dataset: M. Franken and J. C. van Gemert, "Automatic Egyptian Hieroglyph Recognition by Retrieving Images as Texts", ACM Multimedia, 2013.
Omar Essam El Sherbiny. Head of Data at WalaPlus. Data platforms on Google Cloud, data governance, applied ML. More at omaressam.web.app.



Top comments (0)