往期回顾

  • 实习日记(一):多语言机器翻译mRASP与mRASP2的那些事儿~
  • 实习日记(二):序列建模工具包——Fairseq

感谢篇:
  十分感谢外研在线技术中心算法团队各位老师在我实习期间给予的帮助,好嗨皮的时光,学到了很多东西。【悄悄告诉你们:他们非常耐心 <( ̄▽ ̄)/】

本文资料链接:

  • mRASP代码
  • mRASP2代码
  • MUSE代码

文章目录

  • 往期回顾
  • 前言
  • 一、RAS
    • 1.1 RAS实践
    • 1.2 RAS效果
      • 德语数据
      • 英语数据
      • 汉语数据
  • 二、AA
    • 1.1 AA实践(暂未得到效果,实验失败,我继续研究ing,T_T)
  • 总结

前言

  本文主要对RAS和AA的源码进行解读,并进行了效果的测试,希望可以帮助大家理解。


提示:以下是本篇文章正文内容。

一、RAS

  RAS是mRASP的核心算法,其原理是:使用一种语言去替换另一种语言中相同词义的单词,如:" I like singing and dancing. " 中的 " singing " 和 " dancing " 使用中文的“唱歌”和“跳舞”去替代,原句改变为:" I like 唱歌 and 跳舞. " ,然后将替换好的数据作为模型的训练数据。

注意:RAS(optional, only valid for train set)

1.1 RAS实践

  • Step1:preprocess_steps_list: clean:subword:merge:ras,注意只有添加上“:ras”,预处理才有RAS的操作;
  • Step2:运行~/preprocess/multilingual_preprocess_main.sh 脚本;

1、Data filtering and cleaning
2、Tokenization
3、Learn / Apply joint bpe sub-word vocabulary
4、Random Alignment Substitution (optional, only valid for train set)

# step2执行命令
bash ${PROJECT_ROOT}/preprocess/multilingual_preprocess_main.sh ${config_yaml_file}
# 我的{config_yaml_file}内容:
raw_data_path: /data1/home/nmt/mRASP/finetune/data/raw/train
merged_output_path: /data1/home/nmt/mRASP/finetune/merged_data/train_ras
output_main_path: /data1/home/nmt/mRASP/finetune/data/prep/train_ras
final_vocab_path: /data1/home/nmt/mRASP/finetune/vocab
configs_subdir: configs
cleaned_subdir: cleaned
logs_subdir: logs
vocab_subdir: vocab
output_subdir: output
preprocess_steps_list: clean:subword:merge:ras
file_prefix: train
learn: false
mono: false
subword_bpe_merge_ops: 32000
maximum_vocabulary_size: 1000
minimum_frequency: 5
pairs: en_de;en_zh
directions: en2de;de2en;en2zh;zh2en
languages: en;de;zh
default_pairs:deduplicate: truekeep_lines_percent: '1.0'shuffle: true
default_langs:do_normalize_punctuations: truetokenizer: MosesTokenizer
ras:dict_path: /data1/home/nmt/sungege/mRASP/finetune/dictionariesvocab_size: 1000
  • Step3:屏幕输出下列信息,证明RAS成功运行;
==== Working directory: ====
/data1/home/mRASP/preprocess
============================
======== 1. Clean & Tokenization BEGIN ========
******** Generate config for LANGUAGE  ********
******** Generate config for LANGUAGE PAIR en_de and Clean & Tokenize en_de Parallel Data ********
======== 1. Clean & Tokenization ALL DONE ========
======== 2. Subword & Vocab BEGIN ========
******** Only Apply BEGIN ********
******** Only Apply ALL DONE ********
======== 2. Subword & Vocab ALL DONE ========
======== 3. Merge BEGIN ========
======== 3. Merge ALL DONE ========
======== 4. Random Alignment Substitution BEGIN ========
======== 4. Random Alignment Substitution ALL DONE ========

1.2 RAS效果

  • 实践数据:德语10条,英语:20条(英-德:10条,英-中:10条),汉语:10条,数据如下所示:

德语数据

  1 Wiederaufnahme der Sitzungsperiode2 Ich erkläre die am Freitag, dem 17. Dezember unterbrochene Sitzungsperiode des Europäischen Parlaments für wiederaufgenommen,     wünsche Ihnen nochmals alles Gute zum Jahreswechsel und hoffe, daß Sie schöne Ferien hatten.3 Wie Sie feststellen konnten, ist der gefürchtete "Millenium-Bug " nicht eingetreten. Doch sind Bürger einiger unserer Mitglie    dstaaten Opfer von schrecklichen Naturkatastrophen geworden.4 Im Parlament besteht der Wunsch nach einer Aussprache im Verlauf dieser Sitzungsperiode in den nächsten Tagen.5 Heute möchte ich Sie bitten - das ist auch der Wunsch einiger Kolleginnen und Kollegen -, allen Opfern der Stürme, insbesonde    re in den verschiedenen Ländern der Europäischen Union, in einer Schweigeminute zu gedenken.6 Ich bitte Sie, sich zu einer Schweigeminute zu erheben.7 Das Parlament erhebt sich zu einer Schweigeminute.8 Frau Präsidentin, zur Geschäftsordnung.9 Wie Sie sicher aus der Presse und dem Fernsehen wissen, gab es in Sri Lanka mehrere Bombenexplosionen mit zahlreichen Toten.10 Zu den Attentatsopfern, die es in jüngster Zeit in Sri Lanka zu beklagen gab, zählt auch Herr Kumar Ponnambalam, der     dem Europäischen Parlament erst vor wenigen Monaten einen Besuch abgestattet hatte.

英语数据

  1 Resumption of the session2 I declare resumed the session of the European Parliament adjourned on Friday 17 December 1999, and I would like once again to     wish you a happy new year in the hope that you enjoyed a pleasant festive period.3 Although, as you will have seen, the dreaded 'millennium bug' failed to materialise, still the people in a number of countrie    s suffered a series of natural disasters that truly were dreadful.4 You have requested a debate on this subject in the course of the next few days, during this part-session.5 In the meantime, I should like to observe a minute' s silence, as a number of Members have requested, on behalf of all the vi    ctims concerned, particularly those of the terrible storms, in the various countries of the European Union.6 Please rise, then, for this minute' s silence.7 The House rose and observed a minute' s silence8 Madam President, on a point of order.9 You will be aware from the press and television that there have been a number of bomb explosions and killings in Sri Lanka.10 One of the people assassinated very recently in Sri Lanka was Mr Kumar Ponnambalam, who had visited the European Parliament j    ust a few months ago.11 1929 or 1989 ?12 Paris - As the economic crisis deepens and widens , the world has been searching for historical analogies to help us understa    nd what has been happening .13 at the start of the crisis , many people likened it to 1982 or 1973 , which was reassuring , because both dates refer to clas    sical cyclical downturns .14 today , the mood is much gri@@ mmer , with references to 1929 and 1931 beginning to abound , even if some governments continu    e to behave as if the crisis was more classical than exceptional .15 the tendency is either excessive restraint ( Europe ) or a diffusion of the effort ( the United States ) .16 Europe is being cautious in the name of avoiding debt and defending the euro , whereas the US has moved on many fronts in ord    er not to waste an ideal opportunity to implement badly needed structural reforms .17 for geo-@@ strategists , however , the year that naturally comes to mind , in both politics and economics , is 1989 .18 of course , the fall of the house of Lehman Brothers has nothing to do with the fall of the Berlin Wall .19 indeed , on the surface it seems to be its perfect anti@@ thesis : the collapse of a wall symboli@@ zing oppression and artif    icial divisions versus the collapse of a seemingly inde@@ struc@@ tible and reassuring institution of financial capitalism .20 yet 2008-2009 , like 1989 , may very well correspond to an epochal change , whose unfolding consequences will be felt for dec    ades .

汉语数据

  1 1929 年 还是 1989 年 ?2 巴黎 - 随着 经济危机 不断 加深 和 蔓延 , 整个 世界 一直 在 寻找 历史 上 的 类似 事件 希望 有助于 我们 了解 目前 正在 发生 的     情况 。3 一 开始 , 很多 人 把 这次 危机 比作 1982 年 或 1973 年 所 发生 的 情况 , 这样 得 类比 是 令人 宽@@ 心 的 , 因为 这 两@@ 段     时期 意味着 典型 的 周期性 衰退 。4 如今 人们 的 心情 却是 沉重 多 了 , 许多 人 开始 把 这次 危机 与 1929 年 和 1931 年 相比 , 即使 一些 国家 政府 的 表现 仍然     似乎 把@@ 视 目前 的 情况 为 是 典型 的 而 看见 的 衰退 。5 目前 的 趋势 是 , 要么 是 过度 的 克制 ( 欧洲 ) , 要么 是 努力 的 扩展 ( 美国 ) 。6 欧洲 在 避免 债务 和 捍卫 欧元 的 名义 下@@ 正 变得 谨慎 , 而 美国 已经 在 许多 方面 行动 起来 , 以 利用 这一 理想 的 时机     来 实行 急需 的 结构性 改革 。7 然而 , 作为 地域 战略 学家 , 无论是 从 政治 意义 还是 从 经济 意义 上 , 让 我 自然 想到 的 年份 是 1989 年 。8 当然 , 雷曼 兄弟 公司 的 倒闭 和 柏林墙 的 倒塌 没有 任何 关系 。9 事实上 , 从 表面 上 看 , 两者 似乎 是 完全 是 相反 的 : 一个 是 象征 着 压抑 和 人为 分裂 的 柏林墙 的 倒塌 , 而 另 一个     是 看似 坚不可摧 的 并 令人 安心 的 金融 资本主义 机构 的 倒塌 。10 然而 , 和 1989 年 一样 , 2008 - 2009 年 很 可能 也 能 被 视为 一个 划时代 的 改变 , 其 带来 的 发人深省 的 后果 将 在 几十    年 后 仍 能 让 我们 感受 得到 。
  • 按照上述的步骤,可得 train.src 和 train.trg 两个文件,train.src 中是三种语言混合,并且使用中文去替代了某些相同词义的词语,train.trg 中的内容仅做了三种语言的合并工作,并没有进行替换,两个文件部分内容如下所示:
# train.src
LANG_TOK_EN Al@@ tho@@ ugh , as 浣@@ � will have seen , the dre@@ ade@@ d ' mil@@ len@@ ni@@ um bu@@ g ' fa@@ il@@ ed to mate    ri@@ al@@ ise , st@@ ill the people in a number of countries suf@@ fer@@ ed a 绯@@ 诲@@ 垪 of nat@@ ural dis@@ ast@@ ers that tr@@ ul@@ y were dre@@ ad@@ ful .
LANG_TOK_EN You will be aw@@ are from the press and telev@@ ision 閭@@ e@@ €@@ � there have been a number of bom@@ b expl@@     osi@@ ons and k@@ ill@@ ings in S@@ ri Lan@@ ka .
LANG_TOK_EN P@@ le@@ ase ris@@ e , 閭@@ i@@ 杭 , for 閫@@ � minute ' s sil@@ ence .
LANG_TOK_ZH 巴@@ 黎 - 随@@ 着 经@@ 济@@ 危@@ 机 不@@ 断 加@@ 深 和 蔓@@ 延 , 整@@ 个 世界 一@@ 直 在 寻@@ 找 历@@ 史 上 的 >    类@@ 似 事件 希望 有@@ 助@@ 于 我们 了@@ 解 目前 正在 发@@ 生 的 情况 。
LANG_TOK_DE Das Parlament er@@ heb@@ t sich zu einer Sch@@ we@@ ig@@ emin@@ ute .# train.trg
LANG_TOK_EN One of the people ass@@ as@@ sin@@ ated very rec@@ ent@@ ly in S@@ ri Lan@@ ka was Mr Kum@@ ar Pon@@ nam@@ bal@@     am , who had vis@@ ited the European Parliament just a fe@@ w mon@@ th@@ s ago .
LANG_TOK_DE Wie Sie fest@@ stellen kon@@ n@@ ten , ist der gef@@ ür@@ cht@@ ete " Mill@@ eni@@ um @-@ Bu@@ g " nicht eing@@ e    t@@ re@@ ten . D@@ och sind Bür@@ ger ein@@ iger unserer Mitgliedstaaten Op@@ fer von sch@@ rec@@ kli@@ chen Natur@@ kat@@ as    t@@ rop@@ hen ge@@ worden .
LANG_TOK_ZH 巴@@ 黎 - 随@@ 着 经@@ 济@@ 危@@ 机 不@@ 断 加@@ 深 和 蔓@@ 延 , 整@@ 个 世界 一@@ 直 在 寻@@ 找 历@@ 史 上 的 >    类@@ 似 事件 希望 有@@ 助@@ 于 我们 了@@ 解 目前 正在 发@@ 生 的 情况 。

二、AA

  AA是mRASP2的核心算法,其原理是:使用多种语言去替换另一种语言中相同词义的单词,如:" I like singing and dancing. " 中的 " singing " 和 " dancing " 使用中文的“唱歌”和德语的“tanzen”去替代,原句改变为:" I like 唱歌 and tanzen. " ,然后将替换好的数据作为模型的训练数据。

1.1 AA实践(暂未得到效果,实验失败,我继续研究ing,T_T)

  


总结

  以上就是我对RAS和AA的原理和代码的理解,如果有理解错误的地方还望多多指正。

实习日记(三):mRASPmRASP2中的RAS及AA源码解读相关推荐

  1. Bert系列(三)——源码解读之Pre-train

    https://www.jianshu.com/p/22e462f01d8c pre-train是迁移学习的基础,虽然Google已经发布了各种预训练好的模型,而且因为资源消耗巨大,自己再预训练也不现 ...

  2. netty中的future和promise源码分析(二)

    前面一篇netty中的future和promise源码分析(一)中对future进行了重点分析,接下来讲一讲promise. promise是可写的future,从future的分析中可以发现在其中没 ...

  3. Learning to Rank中Pointwise关于PRank算法源码实现

    [学习排序] Learning to Rank中Pointwise关于PRank算法源码实现 标签: 学习排序PRankPointwiseLearning to Rank代码实现 2015-01-28 ...

  4. faster rcnn源码解读(三)train_faster_rcnn_alt_opt.py

    转载自:faster rcnn源码解读(三)train_faster_rcnn_alt_opt.py - 野孩子的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/u ...

  5. OpenCV学习笔记(三):图像对比度、亮度调整源码

    OpenCV学习笔记(三):图像对比度.亮度调整源码 主函数: #include <opencv2/opencv.hpp>using namespace cv;using namespac ...

  6. idea启动tomcat没有加载项目_震惊!我三步就搞定了 Tomcat 源码环境搭建!

    喜欢请点关注 引言 随着微服务的流行,轻量级的服务应用器也是跟着大火了.毕竟那些企业级的服务应用器部署搭建成本太高.并且springboot 自带的就是 tomcat 服务. 所以我们也有必要学习 t ...

  7. ORB SLAM2源码解读(三):Frame类

    文章目录 前言 构造函数 双目相机 RGBD相机 单目相机 ExtractORB:提取特征点 ComputeBoW:计算词袋数据 SetPose:设置相机外参 isInFrustum:判断一个MapP ...

  8. mysql src.rpm_从.src.rpm包中提取出完整的源码的方法

    1 什么是完整的源码 就是说,最初始的源码加上打了所有的patch后的源码,即最新的源码. 2 过程 2.1 从.src.rpm中提取完整的rpm工程文件 2.1.1 rpm to cpio rpm2 ...

  9. Fabric中PBFT源码解读 (3)

    文章目录 5. Preprepare消息的接收以及Prepare消息的发送 6. Prepare消息的接收以及Commit消息的发送 5. Preprepare消息的接收以及Prepare消息的发送 ...

最新文章

  1. c语言程序的实质,C语言_printf中的%p的实质
  2. Selenium 反反爬检测方案(利用js隐藏浏览器特征)
  3. 配置kickstart脚本--图形篇
  4. [转载]优化ASP.NET应用程序性能研究与探讨
  5. Mysql -- SQL常用命令实例
  6. continue详细讲解
  7. 2018-11-08
  8. 程序员如何学习一门新的编程语言
  9. 2020最新版本js车牌号检验规则
  10. 使用php语言制作水印
  11. 对话职业经理人阿朱:程序员转型期的职业选择
  12. java设计模式 之 模板方法模式
  13. 区块链学习一--初始比特币
  14. 倍福--两台TwinCAT3之间做Ethernet IP通信
  15. gin post 数据参数_gin请求参数处理
  16. 计量经济学及Stata应用案例(一)
  17. System.Web.Mail.SmtpMail
  18. The Thirty-three Of Word-Day
  19. 移相全桥PWM发波要求
  20. 实现跨越多个云的无缝云数据管理

热门文章

  1. 实现原理 扫描枪_条码扫描枪的构成和原理
  2. 滴滴出行2017校园春招内推面试(一)
  3. 全球及中国沥青基碳纤维市场需求格局与供给前景预测报告2022版
  4. Let’s Encrypt免费证书获取方法
  5. Windows2008系统安全日志分析
  6. 书山有路勤为径--书虫成长之路
  7. 手机实名制实施起来难度很大
  8. pytorch 自动微分基础原理
  9. 计算机专业课好学吗,计算机专业课程有哪些 学计算机难不难
  10. 跨境电商各平台的入驻条件都有哪些?