11

几种中文分词工具对比

 3 years ago
source link: https://jdhao.github.io/2020/11/20/chinese_text_seg_tools/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

几种中文分词工具对比

2020-11-20538 words 2 mins read 127 times read

对几种中文分词工具进行了调研,简单总结一下。

这里只用了三种开源的分词工具,分别是 jieba, pkuseg, 还有 LAC。jieba 在分词领域还挺有名的一个工具,pkuseg 是北京大学开源的一个分词工具,LAC 是百度 NLP 团队开源的基于百度自家的 PaddlePaddle 分词工具。

简单使用和速度对比:

from LAC import LAC
import pkuseg
import jieba

my_str = "索引图是一种特殊的图 ,它的存在主要是为了节省空间,索引图附带了一个 color palette/table 或者叫 color map,对应了 256 种颜色(所以 color table 大小为 256x3)),然后图像像素每个位置值在 0-255 之间,数值代表该处像素在 color table 对应的颜色的索引值,实际展示该图片的时候,我们利用这个索引就能在 color table 中找到真正要展示的颜色。从这个描述可以看出,索引图一个像素只需要 1 比特,所以索引图占的空间大小约为 RGB 图的 1/3 ,大大减少了存储占用"
bseg = LAC(mode='seg')
pseg = pkuseg.pkuseg()

print(bseg.run(my_str))
print(pseg.cut(my_str))
print(list(jieba.cut(my_str)))   # jieba.cut() 返回的是 iterator,所以转成了 list 显示

同时也对比了一下三者的速度,

In [39]: %timeit bseg.run(my_str)
7.84 ms ± 77.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [40]: %timeit list(jieba.cut(my_str))
740 µs ± 8.93 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

In [41]: %timeit pseg.cut(my_str)
5.27 ms ± 93.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

可以看出 jieba 的速度是最快的,其次是 pkuseg,最后是百度的 LAC。检查分词的结果,发现 jieba 的分词准确率不及 pkuseg 和 LAC,pkuseg 和 LAC 结果比较接近。

非专业测评,结果仅供参考。

Author jdhao

LastMod 2020-11-21

License CC BY-NC-ND 4.0

Reward
Prev Next

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK