文章摘自github,本次測試選用 HanLP 1.6.0 , LTP 3.4.0java
測試思路git
使用同一份語料訓練兩個分詞庫,同一份測試數據測試兩個分詞庫的性能。github
語料庫選取1998年01月的人民日報語料庫。199801人民日報語料網絡
該詞庫帶有詞性標註,爲了遵循LTP的訓練數據集格式,須要處理掉詞性標註。性能
測試數據選擇SIGHan2005提供的開放測試集。測試
SIGHan2005的使用能夠參見其附帶的readme。gradle
HanLPui
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/pku199801lua
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.jar com.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.859
SIGHan2005的PKU測試集
java -cp build/libs/test-hanlp-ltp-1.0-SNAPSHOT.jar com.zongwu33.test.TestForSIGHan2005 ../NLP/icwb2-data/testing/pku_test.utf8 segment-pku-result.txt
perl ../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.905
Docker安裝 LTP
LTP
生成符合LTP訓練格式的訓練集文件:
java -cp build/libs/test-hanlp-ltp-1.0-SNAPSHOT.jar com.zongwu33.test.CreateSimpleCorpus ../OpenCorpus/pku98/199801.txt simple-199801.txt
simple-199801.txt 即爲結果。 訓練集 和開發集都指定爲這個文件:
../LTP/ltp-3.4.0/tools/train/otcws learn --model model-test --reference simple-199801.txt --development simple-199801.txt --max-iter 5
SIGHan2005的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.870
SIGHan2005的PKU測試集
../LTP/ltp-3.4.0/tools/train/otcws test --model model-test --input /data/testLTP/icwb2-data/testing/pku_test.utf8 > pku_result.txt
perl icwb2-data/scripts/score icwb2-data/gold/pku_training_words.utf8 \
icwb2-data/gold/pku_test_gold.utf8 pku_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.txt
init model: 313 ms
total time:15677 ms
total num:140315
須要15.677 s,能夠計算獲得處理速度 1375k/s 。
LTP
../LTP/ltp-3.4.0/tools/train/otcws test --model model-test --input strict-utf8-booken.txt > /dev/null
[INFO] 2018-03-26 17:04:19 ||| ltp segmentor, testing ...
[INFO] 2018-03-26 17:04:19 report: input file = strict-utf8-booken.txt
[INFO] 2018-03-26 17:04:19 report: model file = model-test
[INFO] 2018-03-26 17:04:19 report: evaluate = false
[INFO] 2018-03-26 17:04:19 report: sequence probability = false
[INFO] 2018-03-26 17:04:19 report: marginal probability = false
[INFO] 2018-03-26 17:04:19 report: number of labels = 4
[INFO] 2018-03-26 17:04:19 report: number of features = 491820
[INFO] 2018-03-26 17:04:19 report: number of dimension = 1967296
[INFO] 2018-03-26 17:05:13 Elapsed time 53.680000
須要53s。處理速度389k/s。
對比
開源協議
Apache License Version 2.0