SentencePiece的中文测试实践

许多自然语言处理程序中都用到了谷歌开源的SentencePiece作为词切分的基础工作之一,于是跟踪学习了下。

1、基本介绍

What is SentencePiece?

SentencePiece is a re-implementation of sub-word units, an effective way to alleviate the open vocabulary problems in neural machine translation. SentencePiece supports two segmentation algorithms, byte-pair-encoding (BPE) [Sennrich et al.] and unigram language model [Kudo.]. Here are the high level differences from other implementations.

从上面的介绍可以看出,这是一种词切分技术,可为NMT翻译提供重要支撑。里面提供了两种切词算法,BPE和unigram词模型。

2、安装

安装在官网上提供了两种,一种是python包,另外一种是c++,由于官网只提供英语和日本语的处理,而为了实现中文处理,需要安装C++版本。

安装步骤如下所示,不过由于只需要用到spm_train,因此不需要make install.

% cd /path/to/sentencepiece
% mkdir build
% cd build
% cmake ..
% make -j $(nproc)
% sudo make install
% sudo ldconfig -v

安装效果图如下所示:

3、分词训练

以某部小说的TXT作为导入开始训练,其训练语句如下所示:

ndscai@ndscaigpu01:~/downloads/201907/sentencepiece-master/build/src$ ./spm_train --input=./bingwang.txt --model_prefix=/home/ndscai/downloads/201907/bw

训练完成后,利用python进行调用,其结果呈现如下:

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值