资讯 文档
技术能力
语音技术
文字识别
人脸与人体
图像技术
语言与知识
视频技术

Tokenzier(C++)

本文主要介绍文心 C++版本tokenizer的使用说明,用户需要根据自己的任务类型进行配置,tokenizer根据配置,选择对应的切字逻辑。

  1. 下载分词工具包,并解压
wget -O output.tar.gz --no-check-certificate --header "IREPO-TOKEN:a290f776-ed9a-4046-9358-ceb1e3c0c42f" "https://irepo.baidu-int.com/rest/prod/v3/baidu/nlp/wenxin-data-process/releases/1.0.2.1/files"
tar zxf output.tar.gz && rm -rf output.tar.gz
  1. 文心非ernie模型使用wordseg的phrase粒度进行切词,由于wordseg词典比较大,需要单独下载,ernie模型不需要下载。
cd output
wget ftp://yq01-inf-yq01-tianqi55.yq01.baidu.com:/home/disk2/nlpt/nlpc_wordseg_3016.tar
#如果上述ftp链接失效,请使用下面链接
http://bj.bcebos.com/wenxin-models/nlpc_wordseg_3016.tar
tar xf nlpc_wordseg_3016.tar && rm nlpc_wordseg_3016.tar
  1. 登陆文心平台网站(http://nlp.baidu-int.com/wenxin/apply),创建项目,将AK&SK复制下来,填到配置文件(conf/tokenizer.conf)中的ak/sk配置项。
  2. 修改配置文件conf/tokenizer.conf:
[GlobalData]
# wenxin模型对应的词典,如果是ernie任务,请使用vocab目录下词典,如果通用任务,用户需要使用提交训练任务使用的词典。注意,这里的词典编码要求转成utf8格式。
#   ernie sim: ./vocab/ernie_base.txt
#   ernie tiny: ./vocab/ernie_tiny.txt
#   ernie base: ./vocab/ernie_base.txt
#   ernie large: ./vocab/ernie_large.txt
vocab: ./vocab/ernie_base.txt

# 标识任务是否是ernie任务,1:ernie任务,0:非ernie任务
is_ernie: 1

# 标识任务是否是ernie tiny任务: 1: tiny任务,0:非tiny任务
is_tiny: 0

# 序列标注任务需要配置成1,其他任务默认是0
is_sequence: 0

# 生成任务下Seq2Seq + Attention任务需要设置成1,其他任务不需要配置。如果不配置,默认是0
is_seq2seq: 0

# sentence_piece模型所在路径,is_tiny为1的时候需要配置
sentence_piece_model: ./vocab/sentence_piece/spm_cased_simp_sampled.model

# wssp_dict词典路径, is_tiny为1的时候需要配置
wssp_dict: ./vocab/sentence_piece/wssp_dict.txt

# wordseg分词词典路径, is_ernie为0的时候需要配置
seg_dict_dir : ./nlpc_wordseg_3016/conf/nlp_data

[Auth]
# 用户需要复制NLPC平台上的AK/SK, 填写到下面的ak/sk配置项,用于鉴权;
# NLPC平台申请地址:http://nlp.baidu-int.com/wenxin/apply
ak: xxxxxxxxxxxxxx
sk: xxxxxxxxxxxxxx

# 鉴权server地址,请保持默认值
url: bns://group.opera-onlineOperate-wenxinStatistics-all-hb.NLPC.all
  1. 调用切词工具,输入数据要求是utf8编码:
cat input.txt |./bin/wenxin-tokenize
上一篇
C++ API
下一篇
编码识别及转换工具