用Python API实现对具有子字单位的罕见词的神经机器翻译的C++实现。

fastBPE的Python项目详细描述


快速业务伙伴关系

C++实现的Neural Machine Translation of Rare Words with Subword Units,带有python API。

安装

编译时使用:

g++ -std=c++11 -pthread -O3 fastBPE/main.cc -IfastBPE -o fast

用法:

列出命令

./fast
usage: fastbpe <command> <args>

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 stdout

fastbpe还支持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

对列车应用代码

./fast applybpe train.de.40000 train.de codes
./fast applybpe train.en.40000 train.en codes

获取列车词汇

./fast getvocab train.de.40000 > vocab.de.40000
./fast getvocab train.en.40000 > vocab.en.40000

对有效和测试应用代码

./fast applybpe valid.de.40000 valid.de codes vocab.de.40000
./fast applybpe valid.en.40000 valid.en codes vocab.en.40000
./fast applybpe test.de.40000  test.de  codes vocab.de.40000
./fast applybpe test.en.40000  test.en  codes vocab.en.40000

python api

要安装python api,只需运行:

python setup.py install

注意:对于mac osx用户,在执行上述安装命令之前/期间,视情况将export MACOSX_DEPLOYMENT_TARGET=10.x(x=9或10,取决于您的版本)或-stdlib=libc++添加到extra_compile_argssetup.py中。

使用:

importfastBPEbpe=fastBPE.fastBPE(codes_path,vocab_path)bpe.apply(["Roasted barramundi fish","Centrally managed over a client-server architecture"])>>['Ro@@ asted barr@@ am@@ un@@ di fish','Centr@@ ally managed over a cli@@ ent-@@ server architecture']

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaPax考试:从非标准Maven存储库解析Karaf特性存储库(XML文件)   java Spring启动Bean创建异常   java中将ArrayList转换为数组的方法   Android Studio的java Unity插件。   java在CheckStyle中从方法计数中排除getter和setter   HibernateJava。sql。SQLSyntaxErrorException:表/视图“序列”不存在   与命令行程序Java vs C通信   java WebView膨胀异常   java在O(n)java8流中寻找两个列表的交集   java使用Gradle运行单元测试时,最大堆大小在哪里设置?   ssl加载java应用程序(CXF)内的jks文件   CI:Jenkins Git:Simple Java项目:希望在特定时间在脚本上发送消息   java根据位置更改数字   java按数值排序字符串数组   macos java版本“1.6.0_65”是否与java 6模棱两可?   Cassandra中的java时间戳