Skip to main content

zh-glyph-similarity logo

zh-glyph-similarity

Chinese homoglyph table: which characters look alike on a phone?
Visual similarity for every pair of 16,203 Traditional and Simplified Chinese characters, Bopomofo (Zhuyin), digits and Latin letters, scored with one formula on glyphs rendered with real phone fonts.
形近字・形似字相似度總表|繁體中文・簡體中文・注音符號・數字・英文字母

Latest release 16,203 characters Scripts Fonts
Python 3.9+ Code: MIT Data: CC BY 4.0 Downloads

Quick start · How it works · Results · Data files · Download · 繁體中文

Characters and their look-alikes with similarity scores: 0 and O 0.93, l and I 0.95, ㄚ and 丫 0.83, 未 and 末 0.94, 撤 and 徹 0.95, 賴 and 頛 0.88

Scam messages dodge keyword filters by swapping in homoglyphs, characters that look the same: L1NE for LINE, Bopomofo ㄚ for 丫, a rare 頛 for 賴. This project measures how alike any two of 16,203 characters look when a phone draws them, so filters, normalisers and test sets can account for those swaps.

Highlights

  • Every pair, one formula. 16,203 × 16,203 ≈ 262 million scores, all computed the same way, so a 0.90 means the same thing anywhere in the table.
  • Rendered the way phones render. Per-character font fallback, one canvas, one font size, one baseline. The Android table is published; the iOS table builds on your own Mac.
  • Tolerates width, not shape. A stroke-distance metric that lets glyphs stretch a little, so 0 and O come out as near-identical (0.93) while 0 and 8 do not top the list.
  • Checked against known look-alikes. Unicode confusables, a curated list of look-alike pairs, a second font, and Android vs iOS.
  • Easy to use. pip install, three lines of Python, a command-line tool, or a plain TSV.
  • Open and reproducible. Open fonts, pinned character lists, SHA-256 manifests. Code under MIT, data under CC BY 4.0.

Quick start

pip install "git+https://github.com/junwei940302/zh-glyph-similarity"
from glyphsim import GlyphSim

gs = GlyphSim.from_release()      # downloads the table once (~90 MB), then loads from cache

gs.similarity("0", "O")           # 0.933
gs.similarity("ㄚ", "丫")          # 0.831
gs.neighbors("賴", k=3)            # [('頛', 0.878), ('赖', 0.867), ('轒', 0.847)]
gs.lookalikes("l")                # ['i', 'I', '丨']   (score >= 0.85)

From the command line:

$ glyphsim neighbors ㄚ -k 3
  1  丫  U+4E2B  0.831
  2  Y  U+0059  0.800
  3  T  U+0054  0.627

$ glyphsim sim 未 末
0.941

The first call caches the table in ~/.cache/zh-glyph-similarity (set GLYPHSIM_CACHE to change it). Later calls take about 0.2 s.

Without installing anything

Download charset.tsv and neighbors_android_aosp_zh_tw_chamfer_st.tsv from Releases and read them with any tool:

import pandas as pd

nb = pd.read_csv("neighbors_android_aosp_zh_tw_chamfer_st.tsv", sep="\t")
nb[nb.char == "賴"].head(3)
#  char codepoint  rank neighbor neighbor_codepoint   score
#     賴    U+8CF4     1        頛             U+981B  0.8793
#     賴    U+8CF4     2        赖             U+8D56  0.8683
#     賴    U+8CF4     3        轒             U+8F52  0.8466

Use cases

Harden keyword filters. pattern() turns a keyword into a regular expression that also matches look-alike spellings:

import re

rx = re.compile(gs.pattern("LINE", min_score=0.8))   # 'L[Ili丨1ft][NH]E'
bool(rx.search("加L1NE領飆股"))                       # True
bool(rx.search("加LlNE好友"))                         # True

Other uses:

  • Normalise text before classification by mapping rare look-alikes to the common character they imitate.
  • Build adversarial test sets by swapping characters for high-scoring look-alikes and checking how much a model degrades.
  • Rank OCR or spelling-correction candidates by visual closeness.

The most similar characters for a few queries, from the Android table:

Grid of query characters with their eight most similar characters and scores

How it works

Four steps: render 0 and O, measure stroke gaps (0.81), allow width changes (0.93), score every pair

  1. Render like a phone. Each character is drawn with the first font in the platform's fallback list that contains it, on a 64 × 64 canvas at 56 px, all on the same baseline. A narrow l and a full-width 一 keep their real size and position.
  2. Measure stroke gaps. Strokes become point sets; the symmetric chamfer distance averages how far each stroke pixel of one glyph is from the nearest stroke of the other.
  3. Allow width changes. Either glyph may be stretched horizontally by 0.8–1.25×; the best fit is kept, plus a penalty of 0.5 px × |ln s|. Without this step, O ranks fourth for 0, behind D, B and 8: plain chamfer penalises the 7 px width difference along the whole outline.
  4. Score every pair. similarity = exp(−distance / 3 px), stored as round(similarity × 255).

A penalty for a different number of enclosed holes (0 vs 8) was also tried; hole counts are unstable for complex characters at 64 px and it hurt Chinese results, so it is not used. The parameter grid is in experiments/.

Results

Each known look-alike pair counts as found if the partner appears among the top k neighbours. Android table, same 15,537-character set for all three metrics:

Bar charts: share of known look-alikes found in the top 1, 5 and 10 neighbours for three metrics

Final tables (16,203 characters):

Ground truth Pairs Android top 1 Android top 5 Android top 10 iOS top 1 iOS top 5 iOS top 10
Unicode confusables (UTS #39 v18, same skeleton) 92 51% 80% 89% 76% 93% 96%
Curated look-alike pairs (groundtruth/) 140 51% 87% 93% 50% 87% 91%
— of which Chinese–Chinese (未/末, 戊/戌, …) 80 56% 94% 98%
— of which digit–letter (0/O, 1/l, 5/S, …) 14 50% 93% 100%

The pycorrector same_stroke list (2,818 pairs) scores low (top 10: 14%) by design: it lists characters that share a component (丁/盯, 王/琴), which does not make the whole glyphs look alike.

Fonts and platforms

Do the results depend on the font? Ranks do; look-alikes mostly do not.

Look-alike pairs keep high scores in a rounded font; scores of 300,000 random pairs correlate with Spearman 0.93

Comparison Spearman (random pairs) Pairs ≥ 0.85 in A that stay ≥ 0.80 in B …and stay in B's top 50 Top-10 overlap
Noto Sans CJK vs jf open 粉圓 (rounded)¹ 0.93 98.0% 94.2% 0.34
Android (Noto + Roboto) vs iOS (PingFang + SF Pro) 0.93 97.7% 93.0% 0.38

¹ Over the 8,564 Chinese characters both fonts cover. High-scoring pairs are taken from the top 10 of 4,000 random characters (python -m glyphsim.compare --sim-a … --sim-b …).

Use a score threshold rather than a rank cut-off, and take the maximum over platforms if you need to cover both. Differences come from glyph design. Noto draws 刂 in the right half of the box, where it sits inside 到, so on Android its nearest characters have a vertical stroke on the right (习, 书, 泪); on iOS they are other narrow components (丬, 阝, 卩).

Table Latin and digits Chinese and Bopomofo Published
android_aosp_zh_tw Roboto Noto Sans CJK TC (SC as fallback) ✅ in Releases
ios_zh_tw SF Pro (text size) PingFang TC (SC as fallback) Build on your Mac, see why

Android brands may ship their own fonts; the table uses the AOSP defaults. The comparisons above suggest that look-alikes carry over to other sans-serif designs, while exact ranks do not. PingFang TC lacks 238 of the characters (mostly from 通用规范汉字表), so PingFang SC draws them.

Data files

Download from Releases:

File Size Contents
charset.tsv 1 MB The index: index, char, codepoint, sets, name. Row i is row and column i of the matrix.
matrix_android_aosp_zh_tw_chamfer_st.triu.u8.xz 90 MB Full 16,203 × 16,203 matrix: upper triangle, row-major, uint8 (score × 255), xz-compressed. GlyphSim.from_files() or glyphsim.load.load_matrix() restores it.
neighbors_android_aosp_zh_tw_chamfer_st.tsv 26 MB Top 50 neighbours of every character with unrounded scores: char, codepoint, rank, neighbor, neighbor_codepoint, score.
manifest_android_aosp_zh_tw_chamfer_st.json 2 KB Parameters, fonts, renderer and SHA-256 of each file.

The matrix stores scores in steps of 1/255; the TSV keeps the unrounded value, so ties in the matrix can order neighbours slightly differently.

Character set

Group Source Characters
Bopomofo U+3105–U+3129 and the five tone marks 42
Digits and Latin letters ASCII 0–9, A–Z, a–z 62
Traditional (encoding) Big5 level 1 + level 2 5,401 + 7,652
Simplified (encoding) GB2312 level 1 + level 2 3,755 + 3,008
Taiwan standard lists Ministry of Education common + less-common characters 4,808 + 6,343
Mainland standard list 通用规范汉字表, levels 1–3 3,500 + 3,000 + 1,605

The union is 16,203 characters. The first 15,537 (Big5 ∪ GB2312) keep the same positions as in the first version; python -m glyphsim.charset --no-lists rebuilds that set. Each source adds characters the others lack. GB2312 has the radical components (冂 匚 勹 卩 厶 凵 攵) that the Bopomofo letters ㄇ ㄈ ㄅ ㄗ ㄙ ㄩ ㄆ were derived from, which 通用规范汉字表 omits; level 3 of 通用规范汉字表 adds name and place characters that are mostly missing from GB2312. The sets column (big5_1, moe_1, tgh_3, …) lets you slice the matrix to any subset without recomputing.

Build from source

git clone https://github.com/junwei940302/zh-glyph-similarity
cd zh-glyph-similarity
python -m venv .venv && source .venv/bin/activate
pip install -e ".[build]"

# any OS; downloads the open fonts
scripts/run_stack.sh android_aosp_zh_tw
# macOS only; reads the fonts that ship with macOS
scripts/run_stack.sh ios_zh_tw
# writes release/
python -m glyphsim.export android_aosp_zh_tw_chamfer_st
# compare two tables
python -m glyphsim.compare data/topk_android_aosp_zh_tw_chamfer_st.npz data/topk_ios_zh_tw_chamfer_st.npz \
  --sim-a data/sim_android_aosp_zh_tw_chamfer_st.npy --sim-b data/sim_ios_zh_tw_chamfer_st.npy

On a MacBook Air M2 a table takes about a minute (export about two more) and needs about 2.5 GB of RAM and 300 MB of disk. Outputs go to data/; set OUT=/path to write elsewhere. python docs/figures/make_figures.py rebuilds the figures in this README.

The Android table built on Linux (OpenBLAS) and on macOS (Accelerate) gives identical evaluation scores. A few cells can differ by 1/255 because floating-point sums run in a different order, so the SHA-256 in manifest_*.json identifies the released files.

Limitations

  • Shape only. Sound-alike swaps (Bopomofo spelling such as ㄌㄞˋ for 賴, homophones) are not covered.
  • One design per platform. Brand fonts reorder neighbours; use thresholds, not ranks.
  • Regular weight, 64 px. Bold text and very small sizes are not modelled.
  • Ground truth is limited. The curated pairs were assembled by the maintainer; a human-rated benchmark is planned.
  • pattern() matches characters only. Inserted spaces or symbols (L I N E) need separate normalisation.

FAQ

Why not just use Unicode's confusables.txt?

It is built for identifiers and domain names. It contains only 15 lines involving Bopomofo, does not link ㄧ to 一, and treats pairs such as 未/末 and 土/士 as the same character, which is too aggressive for running Chinese text. It also gives a yes/no answer, not a score.

Why is there no iOS table in Releases?

Apple's fonts may only be used on Apple systems and may not be redistributed. The scores are derived from those fonts, so this project ships the code and lets you build the table on your own Mac. Details in NOTICE.md.

How do I get a smaller table?

Filter charset.tsv by the sets column (for example moe_1 and tgh_1 for common characters) and take those rows and columns of the matrix. Scores do not depend on which other characters are in the table.

Citation

If you use this table, please cite it. GitHub's Cite this repository button reads CITATION.cff.

@misc{huang2026zhglyphsimilarity,
  author       = {Huang, Jun-Wei},
  title        = {zh-glyph-similarity: A visual-similarity table for Chinese characters, Bopomofo, digits and Latin letters},
  year         = {2026},
  version      = {1.0.0},
  howpublished = {\url{https://github.com/junwei940302/zh-glyph-similarity}}
}

Acknowledgements

License

Code: MIT. Data (character index, tables, curated pairs, evaluation results): CC BY 4.0. Third-party data and fonts: NOTICE.md.

Metadata

Release files for zh-glyph-similarity 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zh-glyph-similarity 1.0.0
File Size Uploaded Provenance Actions
zh_glyph_similarity-1.0.0.tar.gz 32.2 kB With provenance Details for zh_glyph_similarity-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for zh-glyph-similarity 1.0.0
File Interpreter ABI Platform Actions
zh_glyph_similarity-1.0.0-py3-none-any.whl Python 3 none any Details for zh_glyph_similarity-1.0.0-py3-none-any.whl

Total release size: 63.0 kB

Release files / zh_glyph_similarity-1.0.0.tar.gz

Download URL zh_glyph_similarity-1.0.0.tar.gz
Size 32.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0619ef4717e663eaa928a592e550551ecb65d99fa4ad02349a743669cf4d642e
BLAKE2b-256 checksum
How to use checksums
a7082130c2f2f4d86f333ad6f79869153a5e4ef599ce0f8d4f5796d2165e7e06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / zh_glyph_similarity-1.0.0-py3-none-any.whl

Download URL zh_glyph_similarity-1.0.0-py3-none-any.whl
Size 30.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86ed4a9eb5541baac5a432ccaa00cf5f213e8440f4bddc6ab0b98aa2fa8068bb
BLAKE2b-256 checksum
How to use checksums
3b1d668df405f29a33986680c046fb2e8ed4822c57b1aca7610b30d06cbd27e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for zh-glyph-similarity 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for zh_glyph_similarity-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page