adnb34g 发表于 2019-4-19 11:06:34

HanLP vs LTP 分词功能测试


文章摘自github,本次测试选用 HanLP 1.6.0 , LTP 3.4.0 测试思路 使用同一份语料训练两个分词库,同一份测试数据测试两个分词库的性能。 语料库选取1998年01月的人民日报语料库。199801人民日报语料 该词库带有词性标注,为了遵循LTP的训练数据集格式,需要处理掉词性标注。 测试数据选择SIGHan2005提供的开放测试集。 SIGHan2005的使用可以参见其附带的readme。 HanLP java -cp libs/hanlp-1.6.0.jar com.hankcs.hanlp.model.perceptron.Main -task CWS -train -reference ../OpenCorpus/pku98/199801.txt -model cws.bin mkdir -p data/model/perceptron/pku199801 mv -f cws.bin data/model/perceptron/pku199801/cws.bin 默认情况下,训练的迭代次数为5。 修改 src/main/resouces 文件: root=../test-hanlp-ltp 打包命令: gradle clean build ​ SIGHan2005的MSR测试集 执行命令: java -cp build/libs/test-hanlp-ltp-1.0-SNAPSHOT.jarcom.zongwu33.test.TestForSIGHan2005 ../NLP/icwb2-data/testing/msr_test.utf8    segment-msr-result.txt将分词的结果生成到segment-msr-result.txt文件里。 利用SIGHan2005的脚本生成分数: perl ../NLP/icwb2-data/scripts/score ../NLP/icwb2-data/gold/msr_training_words.utf8 \    ../NLP/icwb2-data/gold/msr_test_gold.utf8 segment-msr-result.txt > score-msr.ut8可以得到 HanLP在MSR数据集上的测试结果: === TOTAL TRUE WORDS RECALL:        0.870=== TOTAL TEST WORDS PRECISION:        0.848=== F MEASURE:        0.859SIGHan2005的PKU测试集 java -cp build/libs/test-hanlp-ltp-1.0-SNAPSHOT.jarcom.zongwu33.test.TestForSIGHan2005 ../NLP/icwb2-data/testing/pku_test.utf8segment-pku-result.txtperl ../NLP/icwb2-data/scripts/score ../NLP/icwb2-data/gold/pku_training_words.utf8../NLP/icwb2-data/gold/pku_test_gold.utf8   segment-pku-result.txt > score-pku.utf8结果: === TOTAL TRUE WORDS RECALL:        0.894=== TOTAL TEST WORDS PRECISION:        0.915=== F MEASURE:        0.905Docker安装 LTP LTP 生成符合LTP训练格式的训练集文件: java-cp build/libs/test-hanlp-ltp-1.0-SNAPSHOT.jarcom.zongwu33.test.CreateSimpleCorpus ../OpenCorpus/pku98/199801.txtsimple-199801.txtsimple-199801.txt 即为结果。 训练集 和开发集都指定为这个文件: ../LTP/ltp-3.4.0/tools/train/otcws learn--model model-test --reference simple-199801.txt --development simple-199801.txt--max-iter5SIGHan2005的MSR测试集 测试: ../LTP/ltp-3.4.0/tools/train/otcws test--model model-test--input /data/testLTP/icwb2-data/testing/msr_test.utf8> msr_result.txt利用SIGHan2005的脚本生成分数: perl icwb2-data/scripts/score icwb2-data/gold/msr_training_words.utf8 \    icwb2-data/gold/msr_test_gold.utf8 msr_result.txt > ltp-msr-score.utf8查看ltp-msr-score.utf8 : === TOTAL TRUE WORDS RECALL:        0.886=== TOTAL TEST WORDS PRECISION:        0.854=== F MEASURE:        0.870SIGHan2005的PKU测试集 ../LTP/ltp-3.4.0/tools/train/otcws test--model model-test--input /data/testLTP/icwb2-data/testing/pku_test.utf8> pku_result.txtperl icwb2-data/scripts/score icwb2-data/gold/pku_training_words.utf8\    icwb2-data/gold/pku_test_gold.utf8pku_result.txt > ltp-pku-score.ut8=== TOTAL TRUE WORDS RECALL:        0.928=== TOTAL TEST WORDS PRECISION:        0.939=== F MEASURE:        0.934对比 MSR测试集:
性能测试 阿里云ECS机器配置: 机器配置:Intel Xeon CPU *4 2.50GHz,内存16G 测试数据集 20M的网络小说,约140315句(不含空行)。 HanLP java -cp test-hanlp-ltp-1.0-SNAPSHOT.jar com.zongwu33.test.PerformanceTest../NLP/strict-utf8-booken.txtinit model: 313 mstotal time:15677 ms total num:140315 需要15.677 s,可以计算得到处理速度 1375k/s 。 LTP ../LTP/ltp-3.4.0/tools/train/otcws test--model model-test--inputstrict-utf8-booken.txt> /dev/null 2018-03-26 17:04:19 ||| ltp segmentor, testing ... 2018-03-26 17:04:19 report: input file = strict-utf8-booken.txt 2018-03-26 17:04:19 report: model file = model-test 2018-03-26 17:04:19 report: evaluate = false 2018-03-26 17:04:19 report: sequence probability = false 2018-03-26 17:04:19 report: marginal probability = false 2018-03-26 17:04:19 report: number of labels = 4 2018-03-26 17:04:19 report: number of features = 491820 2018-03-26 17:04:19 report: number of dimension = 1967296 2018-03-26 17:05:13 Elapsed time 53.680000需要53s。处理速度389k/s。 对比图2 开源协议 Apache License Version 2.0
页: [1]
查看完整版本: HanLP vs LTP 分词功能测试