快速 BPE
使用子词单元进行罕见词神经机器翻译 的 C++ 实现,具有 Python API。
使用编译器:
g++ -std=c++11 -pthread -O3 fastBPE/main.cc -IfastBPE -o fast./fast
usage: fastbpe
The commands supported by fastBPE are:
getvocab input1 [input2] extract the vocabulary from one or two text files
learnbpe nCodes input1 [input2] learn BPE codes from one or two text files
applybpe output input codes [vocab] apply BPE codes to a text file
applybpe_stream codes [vocab] apply BPE codes to stdin and outputs to stdoutfastBPE 还支持 stdin 输入。例如,以下两个命令具有相同效果:
./fast getvocab text > vocab
cat text | ./fast getvocab - > vocab但是第一个命令会将输入文件映射到内存中以高效读取文件,速度比 stdin 快两倍以上,对于非常大的文件而言更是如此。同样,以下两个命令具有相同的效果:
./fast applybpe output input codes vocab
cat input | ./fast applybpe_stream codes vocab > output虽然第一种方法在大型数据集上会明显更快,因为它使用多线程来预先计算输入文件中所有单词的 BPE 分割。
./fast learnbpe 40000 train.de train.en > codes暂无开放 Issues,或尚未同步最近议题。