All Projects → deepcs233 → Jieba_fast

deepcs233 / Jieba_fast

Licence: mit
Use C Api and Swig to Speed up jieba 高效的中文分词库

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Jieba fast

Shogun
Shōgun
Stars: ✭ 2,859 (+499.37%)
Mutual labels:  swig
Simpleelastix
Multi-lingual medical image registration library
Stars: ✭ 332 (-30.4%)
Mutual labels:  swig
Intel Cmt Cat
User space software for Intel(R) Resource Director Technology
Stars: ✭ 400 (-16.14%)
Mutual labels:  swig
Chinese Text Classification
Chinese-Text-Classification,Tensorflow CNN(卷积神经网络)实现的中文文本分类。QQ群:522785813,微信群二维码:http://www.tensorflownews.com/
Stars: ✭ 284 (-40.46%)
Mutual labels:  jieba
Cbmc
C Bounded Model Checker
Stars: ✭ 309 (-35.22%)
Mutual labels:  swig
Mixin
🚀 the Mixin TEE-BFT-DAG network reference implementation
Stars: ✭ 351 (-26.42%)
Mutual labels:  dag
Rasa nlu gq
turn natural language into structured data(支持中文,自定义了N种模型,支持不同的场景和任务)
Stars: ✭ 256 (-46.33%)
Mutual labels:  jieba
Simpleitk
SimpleITK: a layer built on top of the Insight Toolkit (ITK), intended to simplify and facilitate ITK's use in rapid prototyping, education and interpreted languages.
Stars: ✭ 458 (-3.98%)
Mutual labels:  swig
Ggdag
↙️ ↘️ An R package for working with causal directed acyclic graphs (DAGs)
Stars: ✭ 317 (-33.54%)
Mutual labels:  dag
Go Spacemesh
Go Implementation of the Spacemesh protocol full node. 💾⏰💪
Stars: ✭ 389 (-18.45%)
Mutual labels:  dag
Dag Diagram
VUE plugin for DAG graph , u can use it 4 flow diagram or machine learning visualization
Stars: ✭ 286 (-40.04%)
Mutual labels:  dag
Jiebar
Chinese text segmentation with R. R语言中文分词 (文档已更新 🎉 :https://qinwenfeng.com/jiebaR/ )
Stars: ✭ 302 (-36.69%)
Mutual labels:  jieba
Media Server Go
WebRTC media server for go
Stars: ✭ 362 (-24.11%)
Mutual labels:  swig
Textmining
Python文本挖掘系统 Research of Text Mining System
Stars: ✭ 268 (-43.82%)
Mutual labels:  jieba
Serving
A flexible, high-performance carrier for machine learning models(『飞桨』服务化部署框架)
Stars: ✭ 403 (-15.51%)
Mutual labels:  dag
Go Vite
Official Go implementation of the Vite protocol
Stars: ✭ 257 (-46.12%)
Mutual labels:  dag
Go Interlang
Examples of calls between Go and C/C++ (and how to call a Go shared object from Node/Ruby/Python/Java)
Stars: ✭ 346 (-27.46%)
Mutual labels:  swig
Flapigen Rs
Tool for connecting programs or libraries written in Rust with other languages
Stars: ✭ 473 (-0.84%)
Mutual labels:  swig
Wiringpi Python
Unofficial Python-wrapped version of Gordon Henderson's WiringPi version 2.
Stars: ✭ 438 (-8.18%)
Mutual labels:  swig
Elasticsearch Jieba Plugin
jieba analysis plugin for elasticsearch 7.0.0, 6.4.0, 6.0.0, 5.4.0,5.3.0, 5.2.2, 5.2.1, 5.2, 5.1.2, 5.1.1
Stars: ✭ 379 (-20.55%)
Mutual labels:  jieba

jieba_fast

使用cpython重写了jieba分词库中计算DAG和HMM中的vitrebi函数,速度得到大幅提升。 使用import jieba_fast as jieba 可以无缝衔接源代码。

特点

  • 对两种分词模式进行的加速:精确模式,搜索引擎模式
  • 利用cython重新实现了viterbi算法,使默认带HMM的切词模式速度大幅提升
  • 利用cython重新实现了生成DAG以及从DAG计算最优路径的算法,速度大幅提升
  • 基本只是替换了核心函数,对源代码的侵入型很小
  • MIT 授权协议

安装说明

代码目前对 Python 2/3 兼容,对*unix兼容良好,windows本地编译测试通过,但不保证。

关于windows的编译过程中可能会有一些坑,可以尝试我编译好的版本,将编译好的放在了windows/下,分别对应的是python2.7与python3.5。 如果你想安装python2版本的jiaba_fast,将python2下的所有目录与文件拷至对应python的lib/site-packages下就ok。

算法

  • 基于前缀词典实现高效的词图扫描,生成句子中汉字所有可能成词情况所构成的有向无环图 (DAG)
  • 采用了动态规划查找最大概率路径, 找出基于词频的最大切分组合
  • 对于未登录词,采用了基于汉字成词能力的 HMM 模型,使用了 Viterbi 算法

主要功能

详情见 https://github.com/fxsjy/jieba

代码示例

# encoding=utf-8
import jieba_fast as jieba

text = u'在输出层后再增加CRF层,加强了文本间信息的相关性,针对序列标注问题,每个句子的每个词都有一个标注结果,对句子中第i个词进行高维特征的抽取,通过学习特征到标注结果的映射,可以得到特征到任>      意标签的概率,通过这些概率,得到最优序列结果'

print("-".join(jieba.lcut(text, HMM=True))
print('-'.join(jieba.lcut(text, HMM=False)))

输出:

-输出-层后--增加-CRF---加强--文本--信息--相关性--针对-序列-标注-问题--每个-句子--每个----一个-标注-结果---句子---i---进行-高维-特征--抽取--通过-学习-特征--标注-结果--映射--可以-得到-特征--任意-标签--概率--通过-这些-概率--得到-最优-序列-结果
-输出----增加-CRF---加强--文本--信息--相关性--针对-序列-标注-问题--每个-句子--每个----一个-标注-结果---句子---i---进行-高维-特征--抽取--通过-学习-特征--标注-结果--映射--可以-得到-特征--任意-标签--概率--通过-这些-概率--得到-最优-序列-结果

性能测试

测试机器 mbp17, i7, 16G

测试过程: 先按行读取文本《围城》到一个数组里,然后循环对《围城》每行文字作为一个句子进行分词。然后循环对围城这本书分词50次。分词算法分别采用【开启HMM的精确模式】、【关闭HMM的精确模式】、【开启HMM的搜索引擎模式】、【开启HMM的搜索引擎模式】 具体测试数据如下:

开启HMM的精确模式 关闭HMM的精确模式 开启HMM的搜索引擎模式 关闭HMM的搜索引擎模式
jieba 65.1s 39.9s 67.5s 40.5s
jieba_fast 24.5s 18.2s 25.3s 20.4s

可以看出在开启HMM模式下时间缩减了60%左右,关闭HMM时时间缩减了50%左右。

一致性测试

为了保证jieba_fast和jieba分词结果相同,做了如下测试。

对《围城》,《红楼梦》分词结果进行比较,其分词结果完全一致

---- Test of 围城 ----
nums of jieba      results:  164821
nums of jieba_fast results:  164821
Are they exactly the same?  True
----Test of 红楼梦 ----
nums of jieba      results:  597151
nums of jieba_fast results:  597151
Are they exactly the same?  True

鸣谢

"结巴"中文分词作者: SunJunyi

源码见 source/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].