无监督统计机器翻译起源篇《Unsupervised Statistical Machine Translation》

论文
python代码

这是一篇开启无监督机器翻译热的重要论文,18年之后的无监督机器翻译学习方法的改进大都在改论文之上,或启发之下进行进的。

上图中 Section 3.1

该部分的目的是一个语言模型将词训练为词向量,如工具word2vec or fasttext or glove
该部分针对每一中单语言原始语料文本,分别训练出一份词向量Embedding。

上图中 Section 3.2

该部分的目的是让两种语言进行映射联合,工具vecmapvecmap工具具体解析
该部分将两种语言的Embedding矩阵进行相互映射,通过映射处理,重新改变原始的Embedding,分别会产生一份新的MAP_Embedding。

上图中 Section 4.1

短语表生成
该部分的目的是生成一个源语言+目标语言同义词组的短语表。简言之,抽取短语翻译对。

上图中 Section 4.2

无监督微调

上图中 Section 5

迭代强化

运行模型:

获取模型所需的第三方工具

./get-third-party.sh

小demo数据准备
英文白雪公主,文件名en.MONO.TXT

In the harsh winter season, the goose-like snow flakes are flying around in the sky. There is a queen sitting in a window in the palace, doing needlework for her daughter, the wind blowing snow flakes into the window, the ebony window sill There are a lot of snowflakes falling on it. She looked up and looked out the window. She did not pay attention, and a needle stuck into her finger. The red blood flowed out of the needle, and three drops of blood fell on the snow on the window. She thoughtfully stared at the red blood drops on the white snow, and looked at the ebony window sill. She said, "I hope my little daughter's skin will be white and red, and it looks like this white snow and The red blood is the same, so gorgeous, so arrogant, the hair looks like the ebony of this window is generally black and bright!"
Her little daughter has grown up, and the little girl is so beautiful that she is beautiful, beautiful and moving. Her skin is really white like snow, ruddy with blood, and black hair like ebony. So the queen gave her a name, called Snow White. But Snow White has not grown up, and her queen mother died.
Soon, the father of the king married another wife. This queen is very beautiful, but she is very proud and conceited. She is very strong and can't stand it if she hears someone is more beautiful than her. She has a mirror, she often goes to the mirror to appreciate herself and asks: "Tell me, mirror, tell me the truth! All the women here are the most beautiful? Tell me who she is?"
The mirror replied: "It's you, queen! You are the most beautiful woman here."
When she heard this, she would smile with satisfaction. But Snow White grew up slowly and became more and more beautiful. By the time she was seven years old, she was more dazzling than the bright spring, more beautiful than the queen. Until one day, when the queen went to ask the mirror as usual, the mirror made the answer: "The queen, you are beautiful and beautiful, but Bai Xuegong is more beautiful than you!"
She heard this, her heart filled with anger and jealousy, and her face became pale. She called a servant and said to him, "Give me Snow White to the big forest. I don't want to see her anymore." The servant took Snow White away. When he was about to kill her in the forest, she cried and begged him not to kill her. Facing the pleading of the pitiful little princess, the servant’s sympathy came to life. He said, “You are a child who loves you, I will not kill you.” In this way, he left her alone. In the forest. When the servant decided not to kill Snow White and left her there, even though he knew that in the uninhabited big forest, she would be torn into pieces by the beast, but thought that he did not have to kill her by hand. He felt that a heavy stone that was pressing on his heart fell.
After the servant left, Snow White was very scared. She was everywhere in the forest, looking for a way out. The beast screamed beside her, but did not hurt her. In the evening, she came to a small house. When she determined that there was no one in the house, she pushed the door and went to rest, because she was really unable to move. As soon as she entered the door, she found that everything in the house was well organized and clean. A table was covered with white cloth with seven small plates, each with a piece of bread and some other food. There were seven glasses filled with wine next to the plate, seven knives. And the fork, etc., and the wall is also discharged with seven small beds. At this time she felt hungry and thirsty, and she did not care who it was. She went up to cut a small piece of bread from each piece of bread and drank a little bit of wine in each glass. After eating and drinking, she felt very tired and wanted to lie down and rest. So she came to the bed and almost tried every single of the seven beds. It was not too long, it was too short. It was not until the seventh bed was tried. She lay down on it and soon fell asleep.

德文白雪公主,文件名de.MONO.TXT

In der harten Wintersaison fliegen die gänseähnlichen Schneeflocken am Himmel herum. Da sitzt eine Königin in einem Fenster im Palast und macht Handarbeiten für ihre Tochter, der Wind bläst Schneeflocken ins Fenster, das ebenholzfarbene Fensterbrett Es fallen viele Schneeflocken darauf. Sie schaute auf und schaute aus dem Fenster. Sie achtete nicht darauf, und eine Nadel steckte in ihrem Finger. Das rote Blut floss aus der Nadel und drei Tropfen Blut fielen auf den Schnee am Fenster. Sie starrte nachdenklich auf die roten Blutstropfen auf dem weißen Schnee und schaute auf das ebenholzfarbene Fensterbrett. Sie sagte: "Ich hoffe, die Haut meiner kleinen Tochter ist weiß und rot, und sie sieht aus wie dieser weiße Schnee, und das rote Blut ist das gleiche, so hinreißend, so arrogant, das Haar sieht aus, als wäre das Ebenholz dieses Fensters im Allgemeinen schwarz und hell!"
Ihre kleine Tochter ist erwachsen geworden und das kleine Mädchen ist so schön, dass sie schön, schön und bewegend ist. Ihre Haut ist wirklich weiß wie Schnee, blutrot und schwarzes Haar wie Ebenholz. Also gab die Königin ihr einen Namen, der Schneewittchen hieß. Aber Schneewittchen ist nicht erwachsen geworden, und ihre Königinmutter ist gestorben.
Bald heiratete der Vater des Königs eine andere Frau. Diese Königin ist sehr schön, aber sie ist sehr stolz und eingebildet. Sie ist sehr stark und kann es nicht ertragen, wenn sie hört, dass jemand schöner ist als sie. Sie hat einen Spiegel, sie geht oft zum Spiegel, um sich selbst zu schätzen und fragt: "Sag mir, Spiegel, sag mir die Wahrheit! Alle Frauen hier sind die schönsten? Sag mir, wer sie ist?"
Der Spiegel antwortete: "Du bist es, Königin! Du bist die schönste Frau hier."
Wenn sie das hörte, lächelte sie zufrieden. Aber Schneewittchen wuchs langsam auf und wurde immer schöner. Als sie sieben Jahre alt war, war sie schillernder als der helle Frühling, schöner als die Königin. Bis eines Tages, als die Königin wie üblich den Spiegel fragte, gab der Spiegel die Antwort: "Die Königin, du bist schön und schön, aber Bai Xuegong ist schöner als du!"
Sie hörte das, ihr Herz füllte sich mit Wut und Eifersucht, und ihr Gesicht wurde blass. Sie rief einen Diener und sagte zu ihm: "Gib mir Schneewittchen in den großen Wald. Ich will sie nicht mehr sehen." Der Diener nahm Schneewittchen mit. Als er sie im Wald töten wollte, weinte sie und bat ihn, sie nicht zu töten. Angesichts der Bitte der erbärmlichen kleinen Prinzessin wurde das Mitgefühl des Dieners lebendig. Er sagte: „Du bist ein Kind, das dich liebt, ich werde dich nicht töten.“ Auf diese Weise ließ er sie in Ruhe. Im Wald. Als der Diener beschloss, Schneewittchen nicht zu töten und sie dort zurückließ, obwohl er wusste, dass sie im unbewohnten großen Wald vom Biest in Stücke gerissen würde, dachte er jedoch, dass er sie nicht mit der Hand töten musste. Er fühlte, dass ein schwerer Stein, der auf sein Herz drückte, fiel.
Nachdem der Diener gegangen war, hatte Schneewittchen große Angst. Sie war überall im Wald und suchte nach einem Ausweg. Das Tier schrie neben ihr, tat ihr aber nichts. Am Abend kam sie zu einem kleinen Haus. Als sie feststellte, dass niemand im Haus war, stieß sie die Tür auf und ruhte sich aus, weil sie sich wirklich nicht bewegen konnte. Sobald sie die Tür betrat, stellte sie fest, dass alles im Haus gut organisiert und sauber war. Ein Tisch war mit einem weißen Tuch bedeckt, auf dem sieben kleine Teller mit je einem Stück Brot und etwas anderem Essen standen. Neben dem Teller standen sieben mit Wein gefüllte Gläser und sieben Messer. Und die Gabel usw. und die Wand wird auch mit sieben kleinen Betten entladen. Zu dieser Zeit fühlte sie sich hungrig und durstig und es war ihr egal, wer es war. Sie ging hinauf, um ein kleines Stück Brot von jedem Stück zu schneiden, und trank in jedem Glas ein bisschen Wein. Nach dem Essen und Trinken fühlte sie sich sehr müde und wollte sich hinlegen und ausruhen. Also kam sie zum Bett und probierte fast jedes der sieben Betten aus. Es war nicht zu lang, es war zu kurz. Es war nicht bis das siebte Bett ausprobiert wurde. Sie legte sich darauf und schlief bald ein.

运行模型代码

标准
python train.py --src SRC.MONO.TXT --src-lang SRC --trg TRG.MONO.TXT --trg-lang TRG  --working MODEL-DIR
实际
python train.py --src en.MONO.TXT --src-lang en --trg de.MONO.TXT --trg-lang de  --working MODEL-DIR

运行结果,遇到第三方软件有找不到文件目录的原因,暂且放一下,后期解决。

Tokenizer Version 1.1
Language: en
Number of threads: 20
Tokenizer Version 1.1
Language: de
Number of threads: 20
bash: /home/ubuntu/liu/demo/monoses-master/third-party/moses/bin/lmplz: No such file or directory
bash: /home/ubuntu/liu/demo/monoses-master/third-party/moses/bin/build_binary: No such file or directory
bash: /home/ubuntu/liu/demo/monoses-master/third-party/moses/bin/lmplz: No such file or directory
bash: /home/ubuntu/liu/demo/monoses-master/third-party/moses/bin/build_binary: No such file or directory
bash: /home/ubuntu/liu/demo/monoses-master/third-party/phrase2vec/word2vec: No such file or directory
head: cannot open 'MODEL-DIR/tmpzq65kr2x/vocab-full.txt' for reading: No such file or directory
bash: /home/ubuntu/liu/demo/monoses-master/third-party/phrase2vec/word2vec: No such file or directory
bash: /home/ubuntu/liu/demo/monoses-master/third-party/phrase2vec/word2vec: No such file or directory
head: cannot open 'MODEL-DIR/tmpzq65kr2x/vocab-full.txt' for reading: No such file or directory
bash: /home/ubuntu/liu/demo/monoses-master/third-party/phrase2vec/word2vec: No such file or directory
Traceback (most recent call last):
  File "/home/ubuntu/liu/demo/monoses-master/third-party/vecmap/map_embeddings.py", line 422, in <module>
    main()
  File "/home/ubuntu/liu/demo/monoses-master/third-party/vecmap/map_embeddings.py", line 145, in main
    srcfile = open(args.src_input, encoding=args.encoding, errors='surrogateescape')
FileNotFoundError: [Errno 2] No such file or directory: 'MODEL-DIR/step3/emb.src'
Traceback (most recent call last):
  File "/home/ubuntu/liu/demo/monoses-master/training/induce-phrase-table.py", line 153, in <module>
    main()
  File "/home/ubuntu/liu/demo/monoses-master/training/induce-phrase-table.py", line 110, in main
    srcfile = open(args.src, encoding=args.encoding, errors='surrogateescape')
FileNotFoundError: [Errno 2] No such file or directory: 'MODEL-DIR/step4/emb.src'
sort: cannot read: MODEL-DIR/tmpzq65kr2x/src2trg.phrase-table: No such file or directory
Traceback (most recent call last):
  File "train.py", line 484, in <module>
    main()
  File "train.py", line 474, in main
    induce_phrase_table(args)
  File "train.py", line 317, in induce_phrase_table
    os.remove(args.tmp + '/' + part + '.phrase-table')
FileNotFoundError: [Errno 2] No such file or directory: 'MODEL-DIR/tmpzq65kr2x/src2trg.phrase-table'
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,646评论 4 366
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,979评论 1 301
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 110,391评论 0 250
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,356评论 0 215
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,740评论 3 293
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,836评论 1 224
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,022评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,764评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,487评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,728评论 2 252
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,200评论 1 263
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,548评论 3 260
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,217评论 3 241
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,134评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,921评论 0 201
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,919评论 2 283
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,766评论 2 274

推荐阅读更多精彩内容