jieba_fast_dat: 高效能中文分詞與詞性標註工具
由於自己在使用時發現隨著字典的增加, 字典載入速度越來越久(甚至超過 10 秒),
且原始 jieba 與 jieba_fast 由於久未維護, 有些依賴已經與現在主流 python 版本已經有警告訊息出現(看著不舒服)
所以在支援原有功能的狀態下(大部分), 進行更新與開發, 主要優化內容如下:
技術優化內容
- DAT 詞典結構: 詞典採用均 Double-Array Trie (DAT) 結構,實現低記憶體佔用和極速查詢。
- C++ 核心算法: 關鍵算法(如 Viterbi)在 C++ 中實現,並透過
pybind11無縫暴露給 Python,結合了 Python 的靈活性和 C++ 的高效能。 - CPU 優先原則: 所有算法和庫的選擇都符合 CPU 執行效率,不依賴 GPU。
- 繁體強化: 將預設的系統字典與 idf 均直接改用
jieba原廠提供的繁體優化字典, 無須額外修改設定
重大差異:為了極速,我們做出一個取捨
- Python 版本限制:我們擁抱現代開發!僅支持 Python >= 3.10。
- Platform Support: 支援 Linux 與 macOS (Intel/Apple Silicon)。暫不支援 Windows。
changelog
- pypi 累積安裝次數: 3k(20260506)
- 20260506 支援 macOS 與改善 Linux GLIBC 相容性,加入 GitHub Actions 自動化建置,upgrade version to 0.59。
- 20251222 優化快取結構, refactor c++, 大幅提昇效能, upgrade version to 0.58
- 20251221 優化使用者字典載入, 調整整體結構更多轉入c++ , 修復 IO 邏輯, 再次提昇效能, upgrade version to 0.57
- 20251204 強化cedar, 增加自定義字典cache機制, upgrade version to 0.56
- 20251124 整體大幅重構, 確保結果與原生jieba相同, 修復字典錯誤, upgrade version to 0.55
- 20251106 [0.54] 核心分詞引擎重構,將 Viterbi 完整遷移至 C++ 實現,執行效能大幅提升,並升級至 C++17 標準。
數字會說話:最高 62 倍速 的極致效能!
我們使用大型繁體字典(包含 130 萬筆資料)進行了深度效能對比。結果顯示,jieba_fast_dat 在各項指標上均徹底超越了原始 jieba。
效能對比數據 (Final Summary: Performance Comparison)
| 評測項目 (Metric) | 原生 Jieba | jieba_fast_dat | 加速倍率 (Speedup) |
|---|---|---|---|
| 主字典載入 (Cold Init) | 2.579 s | 1.035 s | 2.49x |
| 主字典載入 (With Cache) | 1.847 s | 0.021 s | 86.07x |
| HMM 模型載入 (Import Load) | 0.110 s | 0.062 s | 1.78x |
| 自定義字典載入 (No Cache) | 4.508 s | 1.591 s | 2.83x |
| 自定義字典載入 (With Cache) | 5.592 s | 0.011 s | 515.88x |
| 分詞速度 (HMM=False) | 0.843 s | 0.014 s | 61.27x |
| 詞性標注 (HMM=False) | 0.909 s | 0.036 s | 24.99x |
| 分詞速度 (HMM=True) | 0.962 s | 0.015 s | 62.93x |
| 詞性標注 (HMM=True) | 1.013 s | 0.040 s | 25.33x |
測試環境:Linux, Python 3.12, 採用大型繁體字典進行測試,分詞/標註數據為多次執行之總和時間。
🚀 安裝
pypi 安裝最新
pip install jieba_fast_dat
github 安裝最新
pip install git+https://github.com/carycha/jieba_fast_dat
github 安裝指定版號
pip install git+https://github.com/carycha/jieba_fast_dat@0.58
🛠️ 使用方式
基本分詞
import jieba_fast_dat as jieba
text = "東北季風發威!4縣市豪大雨特報「雨下整夜」 一路濕到這天"
print("精確模式:", "/".join(jieba.cut(text)))
print("全模式:", "/".join(jieba.cut(text, cut_all=True)))
print("搜尋引擎模式:", "/".join(jieba.cut_for_search(text)))
詞性標註
import jieba_fast_dat.posseg as pseg
text = "東北季風發威!4縣市豪大雨特報「雨下整夜」 一路濕到這天"
words = pseg.cut(text)
for word, flag in words:
print(f"{word}/{flag}")
載入使用者詞典
import jieba_fast_dat as jieba
# userdict.txt 範例內容:
# 創新模式 3
# 程式設計 5 n
jieba.load_userdict("userdict.txt")
print("載入使用者詞典後:", "/".join(jieba.cut("雨要下到什麼時候?氣象署:今雨勢最猛 週日長榮馬拉松要穿雨衣")))
分詞與詞性標註結果比較
統一用以下文字測試
東北季風發威!4縣市豪大雨特報「雨下整夜」 一路濕到這天
分詞差異
| 模式 | 原始 jieba_fast | jieba_fast_dat |
|---|---|---|
| HMM OFF | 東/北/季/風/發/威/!/4/縣/市/豪/大雨/特/報/「/雨/下/整夜/」/ /一路/濕/到/這/天 | 東北/季風/發威/!/4/縣市/豪/大雨/特報/「/雨/下/整夜/」/ /一路/濕/到/這天 |
| HMM ON | 東北/季風/發威/!/4/縣市/豪/大雨/特報/「/雨下/整夜/」/ /一路/濕到/這天 | 東北/季風/發威/!/4/縣市/豪/大雨/特報/「/雨下/整夜/」/ /一路/濕到/這天 |
詞性標注差異
| 模式 | 原始 jieba_fast | jieba_fast_dat |
|---|---|---|
| HMM OFF | 東/zg 北/ns 季/n 風/zg 發/zg 威/ns !/x 4/eng 縣/x 市/n 豪/n 大雨/n 特/d 報/zg 「/x 雨/n 下/f 整夜/b 」/x /x 一路/m 濕/x 到/v 這/zg 天/q | 東北/ns 季風/n 發威/v !/x 4/eng 縣市/n 豪/n 大雨/n 特報/n 「/x 雨/n 下/f 整夜/b 」/x /x 一路/m 濕/x 到/v 這天/r |
| HMM ON | 東北/ns 季風/n 發威/v !/x 4/m 縣/n 市豪/n 大雨/n 特報/n 「/x 雨/n 下/f 整夜/b 」/x /x 一路/m 濕到/v 這天/r | 東北/ns 季風/n 發威/v !/x 4/x 縣市/n 豪/n 大雨/n 特報/n 「/x 雨/n 下/f 整夜/b 」/x /x 一路/m 濕到/x 這天/r |
支持與鼓勵
如果您重視效率、速度、穩定性,並認同我們為中文 NLP 提昇的小小貢獻:
⭐ 點擊 Star! 您的肯定是我們持續開發的最大動力!
📢 轉發擴散! 讓所有還在飽受載入慢之苦的開發者知道這個工具!
🤝 提出 Issue/PR! 歡迎加入我們,讓這個神器更加完美!
📄 許可證
jieba_fast_dat 採用 MIT 許可證。詳情請參閱 LICENSE 文件。
🤝 貢獻
歡迎任何形式的貢獻!如果您有任何建議、功能請求或錯誤報告,請隨時提出 Issue 或提交 Pull Request。
🌟 鳴謝
本專案基於 jieba 與 jieba_fast 庫進行優化和增強。感謝原作者及所有貢獻者。
Metadata
Release files for jieba-fast-dat 0.59
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jieba_fast_dat-0.59.tar.gz | 8.8 MB | With provenance | Details for jieba_fast_dat-0.59.tar.gz |
Built distributions (wheels)
Total release size: 100.7 MB
Release files / jieba_fast_dat-0.59.tar.gz
| Download URL | jieba_fast_dat-0.59.tar.gz |
|---|---|
| Size | 8.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7a772b3c0b2f00534afef0efe142a0c1b1b93c6de7434ddf86339c7cb51f788
|
|
BLAKE2b-256 checksum How to use checksums |
c501f163ad63dfb227a7d5e9d5e4f7c1176aa7feae5312f0b68a44f9817cdbcc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 6, 2026.
Transparency logRelease files / jieba_fast_dat-0.59-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | jieba_fast_dat-0.59-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 13.9 MB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1b933cfff4d854656f6f9e895202702cd7ea1370138a8e36a1cf0f23a538986e
|
|
BLAKE2b-256 checksum How to use checksums |
d5ac3e795b99b8500bb3c618f43ae3a39ed237c8a089c1beb4e5c3c06ae2fa25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 6, 2026.
Transparency logRelease files / jieba_fast_dat-0.59-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | jieba_fast_dat-0.59-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 9.1 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0ee72ba1e6e40fee7028c9fbfc4ceb853491e5e599033d553a712a3ba7c8e993
|
|
BLAKE2b-256 checksum How to use checksums |
36968c3f91646501d1fb8150c535d9ecd82c0e505e71da12c488411313b5b9b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 6, 2026.
Transparency logRelease files / jieba_fast_dat-0.59-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | jieba_fast_dat-0.59-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 13.9 MB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
f4e389c2a1570325490ad14d499bbeeb473c82cb00b12d2d1b1014da82a5928d
|
|
BLAKE2b-256 checksum How to use checksums |
431a35abaf79c41695d82d0a64efec1f045c062f774c54aac6b5f00de8f8a8b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 6, 2026.
Transparency logRelease files / jieba_fast_dat-0.59-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | jieba_fast_dat-0.59-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 9.1 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8135b9c9084e62f18444239f0e6eb34ed1a1e2373595af421eba2f888773a4f7
|
|
BLAKE2b-256 checksum How to use checksums |
8da0945649b24a4a3f031927fc9a91c494127d93b65563ff86645d661c5f9dfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 6, 2026.
Transparency logRelease files / jieba_fast_dat-0.59-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | jieba_fast_dat-0.59-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 13.9 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
b5233e8c3b9716e56fd2a0f4c32b1cdca7b193d636804712d48df5fd28f90268
|
|
BLAKE2b-256 checksum How to use checksums |
c19df62713686170b3a685c74122d41ad0b3ae6fbe113d9f6e9eee0a46b5e5f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 6, 2026.
Transparency logRelease files / jieba_fast_dat-0.59-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | jieba_fast_dat-0.59-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 9.1 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8cbd5b8f46d368e73061d051dea8ca3ae2414239f9dbeeeeb7530830fea4226d
|
|
BLAKE2b-256 checksum How to use checksums |
13c9291504c6d538f8efa0d2adcd915917506024895d27d7109ffcc68a67accf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 6, 2026.
Transparency logRelease files / jieba_fast_dat-0.59-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | jieba_fast_dat-0.59-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 13.8 MB |
| Tags | CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
9f09ef9fefe0b192d0d770f305474a604fe84ae19e6c949b322f1b43d135267b
|
|
BLAKE2b-256 checksum How to use checksums |
9de8650f01a489f7b2fc7ebca2b1f890c881a3ab538e7bdfd327bc3337aaacd1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 6, 2026.
Transparency logRelease files / jieba_fast_dat-0.59-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | jieba_fast_dat-0.59-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 9.1 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4890c3d38cbfa99462fcc89fdebd195cd4ba9d505ed774908963cd9cec77ea3d
|
|
BLAKE2b-256 checksum How to use checksums |
2ad8cfe7fc624dd9f00ef5a1d1a245275a257cf7034e6406e879012171753392
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 6, 2026.
Transparency logSecurity for jieba-fast-dat 0.59
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
All 9 files in this release have been uploaded with provenance metadata.
Attestation for jieba_fast_dat-0.59.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 May 6, 2026.
Transparency logA 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.