Skip to main content

ZHLID: Fine-grained Chinese Language Identification Package

Model GitHub Team

English | 简体中文 | 繁體中文

ZHLID is an open-source, model-based language identification tool specialized in fine-grained Chinese varieties.

Features

Unlike general-purpose LID tools, ZHLID focuses on distinguishing between closely related Chinese varieties, including:

Traditional Chinese (繁體中文) – written in the traditional character set, used in formal and classical texts.
Simplified Chinese (簡體中文) – written in the simplified character set, designed for easier reading and writing.
Cantonese (粵語) – written form reflecting spoken Cantonese with unique vocabulary and grammar.
Classical Chinese (Traditional) (繁體文言文) – literary Chinese in traditional characters with concise, classical syntax.
Classical Chinese (Simplified) (簡體文言文) – literary Chinese in simplified characters, used in modern reprints and education.

This makes ZHLID useful for linguistic research, corpus analysis, preprocessing for NLP tasks, or any application requiring accurate recognition of Chinese textual forms.

The following table compares ZHLID with other popular LID tools supporting Chinese detection:

Identification General Chinese Traditional Chinese Simplified Chinese Classical Chinese Cantonese
ZHLID (ours) ✅ ✅ ✅ ✅ ✅
langdetect ✅ ✅ ✅ ❌ ❌
GlotLID ✅ ❌ ❌ ❌ ✅
langid.py ✅ ❌ ❌ ❌ ❌
CLD3 ✅ ❌ ❌ ❌ ❌
Lingua ✅ ❌ ❌ ❌ ❌

Installation

Install via pip

pip install zhlid

Install from source

pip install git+https://github.com/Musubi-ai/ZHLID

Usage

from zhlid import load_model


model = load_model("MusubiAI/ZHLID", device_map="auto")

text = [
    "王夫之者,字而農,衡陽人,明末清初哲學家。張獻忠陷衡州,夫之匿南嶽,賊執其父以為質。夫之自引刀遍刺肢體,舁往易父。",
    "金山阿伯係清末民初時嘅一種現象。金山阿伯係指嗰啲生活喺廣東地方,因為搵唔夠錢畀家人生活,要出洋到舊金山或新金山做苦工,掘金礦。",
    "燧人氏,古之三皇,有巢氏之子。 风姓,讳允婼,华夏族。燧人钻火,教人熟食,立国曰燧明,为后世奉为「火祖」,号燧皇。立一百一十年,崩,子伏羲嗣。\n\n**引据**\n《风俗通义·皇霸篇》\n*",
    "在量子力学中,量子涨落(quantum fluctuation。或量子真空涨落,真空涨落)是在空间任意位置对于能量的暂时变化。 \n从维尔纳·海森堡的不确定性原理可以推导出这结论。",
    "在政治中,政治議程是政府官員以及政府以外的個人在任何給定時間都認真關注的主題或問題/議題的列表。"
]

res = model.predict(text, batch_size=5)
print(res)
# [
#     {'label': 'zhtw_classical', 'confidence_score': 0.9999634027}, 
#     {'label': 'yue', 'confidence_score': 0.9376096725}, 
#     {'label': 'zhcn_classical', 'confidence_score': 0.9999793768}, 
#     {'label': 'zhcn', 'confidence_score': 0.9944804907}, 
#     {'label': 'zhtw', 'confidence_score': 0.9998573065}
# ]

Evaluation

To evaluate ZHLID with our benchmark dataset, simply run:

python evaluate.py

We compare our top-1 accuracy result with GlotLID and langdetect. Note that since GlotLID only provides a general "cmn_Hani" label for Chinese, its performance on Traditional and Simplified Chinese is measured by whether it outputs this label for both categories.

Top-1 accuracy Traditional Chinese Simplified Chinese Classical Chinese (Traditional) Classical Chinese (Simplified) Cantonese
ZHLID (ours) 1.0 1.0 0.9 1.0 0.96
GlotLID 0.98 0.98 - - 0.9
langdetect 0.3 0.9 - - -

Citation

If you use ZHLID in your research, please cite this repository:

@misc{zhlid2025 ,
  title  = {ZHLID: Fine-grained Chinese Language Identification Package},
  author = {Lung-Chuan Chen},
  year   = {2025},
  howpublished = {\url{https://github.com/Musubi-ai/ZHLID}}
}

Metadata

Release files for zhlid 0.1.1

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

Source distribution (sdist)

Source distribution for zhlid 0.1.1
File Size Uploaded
zhlid-0.1.1.tar.gz 537.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zhlid 0.1.1
File Interpreter ABI Platform
zhlid-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 545.7 kB

Release files / zhlid-0.1.1.tar.gz

Download URL zhlid-0.1.1.tar.gz
Size 537.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9ecf07ccb86012de1c4bd6bad302d12edde5575242d90e34662f3d48d0782167
BLAKE2b-256 checksum
How to use checksums
87181a889f63e7e8c3f1d90702e0bda8e7beb9c5e1db0e5a10c0496618c930dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release files / zhlid-0.1.1-py3-none-any.whl

Download URL zhlid-0.1.1-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d20663450f07e4a625eaa2b3f5152a00c1e5695dd2ad6f6385484745e0196b5
BLAKE2b-256 checksum
How to use checksums
04d22c6b2c8200b9f6539204d7ff60114d1bf7a0334c43d8c657167e4d527348
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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