A fast, compact image model that looks at a document page and predicts which writing script(s) it contains, without running OCR. It returns an independent calibrated probability for each of 21 scripts, so a page can have one script, multiple scripts (mixed-script pages), or none the model is confident about (
unknown
). Use it to route pages to the right OCR model or language pack, sort large collections by script, or flag pages whose script does not match their metadata.
Built on
MobileNetV4-conv-small
(2.52M parameters, 10.1 MB as ONNX or
timm
weights), distilled from a 3-family teacher ensemble (
convnext_small
,
hgnetv2_b4
,
caformer_s36
) on
Hugging Face Jobs
. Takes a greyscale page squashed to
640 × 640
and runs in
33 ms
on 1 CPU thread,
11 ms
on 4 threads, or
1,773 pages/s
on an A10G (
bf16
, batch 64).
Try it live:
Page Script ID Demo Space
(runs on free CPU — upload images or PDFs, toggle crop padding, tune thresholds live)
Higher-accuracy sibling:
davanstrien/page-script-id-hgnet
(HGNetV2-B0, 3.99M parameters, 16 MB, 79 ms 1t / 36 ms 4t, 88.0% MDPBench photographed)
Check the thresholds on your own pages.
The default cut-offs (
0.55
for a script,
0.7038
for
unknown
) were chosen on held-out web-PDF validation pages (95% coverage). On government documents this refuses ~8% and on photographed documents ~28%. Run on a few hundred of your own pages and tune
unknown_threshold
and
script_threshold
in
config.json
before bulk routing.
21 scripts:
Arabic (
Arab
), Armenian (
Armn
), Bengali (
Beng
), Cyrillic (
Cyrl
), Devanagari (
Deva
), Ethiopic (
Ethi
), Georgian (
Geor
), Greek (
Grek
), Gujarati (
Gujr
), Han (
Hani
), Hangul (
Hang
), Hebrew (
Hebr
), Japanese (
Jpan
), Kannada (
Knda
), Khmer (
Khmr
), Latin (
Latn
), Malayalam (
Mlym
), Myanmar (
Mymr
), Tamil (
Taml
), Telugu (
Telu
), Thai (
Thai
).
Preprocessing matters: greyscale, bilinear squash to
640 × 640
, float32 values
0..255
. ImageNet normalisation, temperature (
1.15
), and sigmoid are baked into
model.onnx
, which returns the 21 calibrated probabilities directly.
Tip for text-block crops:
raw squashing of wide text-block strips (
~3.5:1
) causes most crops to return
unknown
(
~30%
top-1),
but padding the crop onto a white square before resizing (
--pad
) raises top-1 on real Indic text-block crops to 86.7%
.
Use with
timm
model.safetensors
holds the exact same weights for
timm
(
mobilenetv4_conv_small
, 21 outputs in
label_names
order). It returns raw logits, so apply
sigmoid(logits / 1.15)
yourself.
import json
import sys
from pathlib import Path
import timm
import torch
from huggingface_hub import hf_hub_download
from PIL import Image
model_id = "hf-hub:davanstrien/page-script-id"
model = timm.create_model(model_id, pretrained=True).eval()
cfg = json.loads(Path(hf_hub_download("davanstrien/page-script-id", "config.json")).read_text())["inference"]
size = cfg["input_size"]
mean = torch.tensor(model.pretrained_cfg["mean"]).view(3, 1, 1)
std = torch.tensor(model.pretrained_cfg["std"]).view(3, 1, 1)
defload_page(path):
im = Image.open(path)
if im.format == "JPEG":
im.draft("L", (2 * size, 2 * size))
grey = im.convert("L").resize((size, size), Image.BILINEAR)
x = torch.frombuffer(bytearray(grey.tobytes()), dtype=torch.uint8).float().view(1, size, size) / 255return (x.expand(3, -1, -1) - mean) / std
with torch.inference_mode():
x = torch.stack([load_page(p) for p in sys.argv[1:]])
probs = torch.sigmoid(model(x) / cfg["temperature"])
for path, p inzip(sys.argv[1:], probs):
if p.max() < cfg["unknown_threshold"]:
print(path, ["unknown"])
else:
print(path, [cfg["scripts"][i] for i in p.argsort(descending=True) if p[i] >= cfg["script_threshold"]])
Evaluation
All test benchmarks are strictly held out from training (never trained on test documents, MDPBench, OmniDocBench, Sarvam Indic OCR Bench, or held-out unseen scripts Gurmukhi/Sinhala). Top-1 accuracy is unthresholded (before the
unknown
rule). "2 seeds" is the range over two distilled runs of this recipe (
s0
selected by
r2_val
;
s1
shown for spread).
*(Single-script spurious 2+ rate on
r2_test
:
2.1%
at
0.55
; mixed-script exact set on
r2_test
at
0.50
without gate:
46.6%
.)*
Unseen scripts:
Real 2026 Sinhala (
Sinh
) PDFs
(46 full pages from
CC-MAIN-2026-47
, never trained):
73.9%
refused as
unknown
(2 seeds: 73.9–78.3%).
Clean synthetic unseen (
Guru
,
Sinh
)
(NVIDIA v2 shard 00000, 160 pages):
51.9%
refused.
Exact 18-class leave-out
(
Geor
,
Khmr
,
Telu
removed from training, 855
r3
pages, undistilled
mnv4s
):
61.6%
pooled refused (
Geor
91.9%,
Telu
59.5%,
Khmr
44.6%). On real
r3
Khmr
pages that also contain secondary Latin headers/URLs, multi-label Latin sensitivity fires
Latn
rather than
unknown
. This model is
not
a reliable detector for unseen scripts.
Speed & Parity
Measured on a cloud
a10g-large
box (12 vCPU, 1× A10G), model forward only on random input (image decode adds ~15–30 ms on 1 CPU thread):
Setup
Speed
Notes
ONNX Runtime FP32, 1 CPU thread, batch 1
33.1–34.3 ms / page
10.06 MB
file
ONNX Runtime FP32, 4 CPU threads, batch 1
11.0–13.2 ms / page
PyTorch (
timm
), A10G,
bf16
, batch 64
1,773 pages / sec
ONNX ↔ PyTorch parity
(400
r2_val
pages):
max |prob diff| = 2.0e-6
,
100.0% top-1 agreement
. Post-training INT8 quantization (both static QDQ and dynamic) was tested and
not shipped
: on MobileNetV4 depthwise convolutions, PTQ degraded agreement to 63.8% (static) / 6.5% (dynamic) without improving 1-thread CPU latency.
Run end-to-end on a single
pure-CPU
Hugging Face Job (
cpu-xl
, 16 vCPU,
$1.00/hr
, zero GPU) directly against
hf://buckets/commoncrawl/commoncrawl
:
21,490 pages
across
13,308 real November 2026 web PDFs
(9,335 unique hosts, 30 TLDs) in
10.5 minutes
for
$0.175
(
35.6 pages/s
end-to-end including WARC byte-range fetch, gzip decompress, PyMuPDF text extract + render, and ONNX inference).
98.7%
agreement with PDF text-layer Unicode script counts on answered born-digital pages (
97.9%
unthresholded).
13.4%
of pages (
2,883
) had no usable text layer (
<30
letters); visual routing immediately assigned a script to
74.5%
(
2,147
) across 15+ scripts and refused the remaining
736
blank/chart/unknown pages.
Flagged
119 pages
whose text layer contained
≥60
Latin characters (broken legacy font CMaps or wrong-language OCR) where the vision model identified the true non-Latin script at
≥0.85
confidence (e.g. Cyrillic
0.978
, Armenian
0.995
), plus
276 mixed-script pages
(
1.3%
).
Limits
Unseen scripts & look-alikes:
not an unseen-script detector. Unseen scripts that visually resemble trained scripts (e.g. Gurmukhi → Devanagari, Sinhala → Kannada/Telugu) or appear alongside secondary Latin headers are often accepted with moderate-to-high confidence.
Weakest known scripts (
r3_test
):
Telugu (
60.0%
, 2 seeds 60–62%) and Gujarati (
72.4%
) remain the weakest classes.
Photographed Cyrillic (
ru
):
while digital
ru
reaches 90.0%, severely degraded photographed
ru
is
52.5%
top-1 (often confused with Latin or refused as unknown).
Crops:
raw squashed text-block crops are mostly refused (
~30%
top-1). Use square white padding (
--pad
) if running on crops.
Not a "no-text" detector:
although blank BHL old-book pages had
0.00%
false positives here, pair with a dedicated no-text classifier (e.g.
small-models-for-glam/page-ocr-flags
) if blank detection is critical.
Training & Attribution
Real PDFs:
born-digital & scanned pages from
FinePDFs
(
ODC-By
; we thank its authors), 3,794 fresh 2026 PDFs from
Common Crawl
(
CC-MAIN-2026-47
, page-level Unicode text-layer labels), plus library/archive scans (BHL, US government docs, IDL) labelled by vision-language model agreement. No raw page images are redistributed.
Teachers & Distillation:
3-family ensemble of
timm/convnext_small.fb_in22k_ft_in1k_384
,
timm/hgnetv2_b4.ssld_stage2_ft_in1k
, and
timm/caformer_s36.sail_in22k_ft_in1k_384
(all Apache-2.0) distilled into
timm/mobilenetv4_conv_small.e2400_r224_in1k
(Apache-2.0) for 16 epochs with Asymmetric Loss + soft BCE KD (
alpha=0.50, T=1.5
), oblique/curl/hand/rotation/padded-crop/CutMix augmentation, EMA weights, and
OneCycleLR
.
Compute:
trained on
Hugging Face Jobs
(~52 min on
a10g-small
for the distilled student).
Runs of davanstrien page-script-id on huggingface.co
85
Total runs
1
24-hour runs
42
3-day runs
85
7-day runs
85
30-day runs
More Information About page-script-id huggingface.co Model
page-script-id huggingface.co is an AI model on huggingface.co that provides page-script-id's model effect (), which can be used instantly with this davanstrien page-script-id model. huggingface.co supports a free trial of the page-script-id model, and also provides paid use of the page-script-id. Support call page-script-id model through api, including Node.js, Python, http.
page-script-id huggingface.co is an online trial and call api platform, which integrates page-script-id's modeling effects, including api services, and provides a free online trial of page-script-id, you can try page-script-id online for free by clicking the link below.
davanstrien page-script-id online free url in huggingface.co:
page-script-id is an open source model from GitHub that offers a free installation service, and any user can find page-script-id on GitHub to install. At the same time, huggingface.co provides the effect of page-script-id install, users can directly use page-script-id installed effect in huggingface.co for debugging and trial. It also supports api for free installation.