Is there any good open-source or freely available Chinese segmentation algorithm available?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Chinese text does not use spaces between words, making word segmentation a fundamental NLP task for Chinese language processing. Several excellent open-source libraries are available: jieba is the most popular Python library for its simplicity, pkuseg offers higher accuracy from Peking University, THULAC comes from Tsinghua University, and spaCy supports Chinese through trained pipelines. For deep learning approaches, HanLP and LAC (Baidu) provide state-of-the-art segmentation. This article compares the major tools with installation instructions, code examples, and accuracy/speed tradeoffs.
jieba (Most Popular)
jieba is the most widely used Chinese segmentation library, supporting three modes:
Custom Dictionary
POS Tagging
pkuseg (Higher Accuracy)
Developed by Peking University, pkuseg achieves higher accuracy than jieba through domain-specific models:
THULAC (Tsinghua University)
HanLP (Deep Learning)
HanLP provides state-of-the-art NLP capabilities including segmentation:
spaCy (Multi-Language Framework)
LAC (Baidu)
Comparison
| Library | Accuracy | Speed | Deep Learning | POS Tagging | Custom Dict |
| jieba | Good | Fast | No | Yes | Yes |
| pkuseg | Very Good | Moderate | No | Yes | Limited |
| THULAC | Very Good | Moderate | No | Yes | Yes |
| HanLP | Excellent | Slower | Yes | Yes | Yes |
| spaCy | Good | Fast | Yes | Yes | Yes |
| LAC (Baidu) | Excellent | Moderate | Yes | Yes | Yes |
Common Pitfalls
- Not loading a custom dictionary for domain-specific text: Out-of-the-box models struggle with specialized vocabulary (medical terms, brand names, slang). Always load a custom dictionary with
jieba.load_userdict()or equivalent for your domain. - Confusing jieba's three modes: Precise mode is for general text, full mode finds all possible words (useful for indexing), and search mode provides finer granularity. Using full mode for regular text processing produces excessive, overlapping segments.
- Not initializing jieba before timed benchmarks: jieba loads its dictionary on first use, which takes 1-2 seconds. Call
jieba.initialize()before benchmarking to exclude startup time from measurements. - Assuming all segmenters handle Traditional Chinese: Most tools default to Simplified Chinese. For Traditional Chinese text, convert to Simplified first with
openccor use a model trained on Traditional Chinese (HanLP supports both). - Ignoring encoding issues: Chinese text files may use UTF-8, GBK, or GB2312 encoding. Always specify encoding when reading files:
open("text.txt", encoding="utf-8"). Encoding errors produce garbage segmentation results.
Summary
- Use jieba for quick setup and good-enough accuracy — it is the most popular and easiest to use
- Use pkuseg for higher accuracy on specific domains (news, web, medicine)
- Use HanLP or LAC for state-of-the-art deep learning-based segmentation
- Use spaCy if you need Chinese segmentation integrated with a multi-language NLP pipeline
- Always add domain-specific words via custom dictionaries for best results in specialized applications
Related reading
- Is there any way to detect strings like putjbtghguhjjjanika?
- Is there is difference between the keras layers Masking and Embeddingmask_zero True?
- Issue with embedding layer when serving a Tensorflow/Keras model with TF 2.0
- Java Open Source Text Mining Frameworks
- Is there any simple way to test two PNGs for equality?
- Is there any super fast algorithm for finding LINES on picture?
- Java Stanford NLP Part of Speech labels?
- Javascript text similarity algorithm
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.