软件需求:

首先你必须要有Moses(废话哈哈)、然后要有GIZA++用作词对齐(traning-model.perl的时候会用到)、IRSTLM产生语言模型

大致步骤:

大体的步骤如下:

  1. 准备Parallerl data(需要句子对齐):对语料进行tokenisation、truecasing和cleaning步骤之后才能使用于我们的机器翻译系统(哈哈,都快忍不住直接写详细步骤了)
  2. 训练你的语言模型(使用IRSTLM):当然也有几步,详细叙述再说
  3. 然后就是训练你的翻译系统啦(可能要花一两个小时):(2) run GIZA
    (3) align words
    (4) learn lexical translation
    (5) extract phrases
    (6) score phrases
    (7) learn reordering model
    (8) learn generation model
    (9) create decoder config file
  4. 最后是蛋疼的Tuning(当然你也可以自己手动的Tuning),大概要花几个小时
  5. 最后你就可以跑了,如果你嫌启动慢,可以把模型转化为Binarised-model来进行,会更快,当然这会需要你改动一些东西,不过很简单

详细步骤以及说明:

一、准备语料:

  首先我们需要你找到你要创建的翻译系统匹配的平行语料,例如英法新闻平行语料,然后对语料进行三步处理后才可以使用:tokenisation、truecasing和cleaning

  首先是tokenisation,就是词例化或者说分词,要使用 :mosesdecoder/scripts/tokenizer/tokenizer.perl进行词例化。 作用是将平行语料(其实是两个文本文件),中的每个句子进行词例化

例子如下:

 ~/mosesdecoder/scripts/tokenizer/tokenizer.perl -l en \
< ~/corpus/training/news-commentary-v8.fr-en.en \
> ~/corpus/news-commentary-v8.fr-en.tok.en
~/mosesdecoder/scripts/tokenizer/tokenizer.perl -l fr \
< ~/corpus/training/news-commentary-v8.fr-en.fr \
> ~/corpus/news-commentary-v8.fr-en.tok.fr

说明:-l 后指定文本的语言,看了一下文件,似乎只支持 en de fr 和 it,如要给中文分词的话,可能需要更多的配置,然后要指定输入的文本和输出的地点,切记 “<”  ">"是必须的!

完整参数说明如下:

Usage ./tokenizer.perl (-l [en|de|...]) (-threads 4) < textfile > tokenizedfile
Options:
-q ... quiet.
-a ... aggressive hyphen splitting.
-b ... disable Perl buffering.
-time ... enable processing time calculation.
-penn ... use Penn treebank-like tokenization.
-protected FILE ... specify file with patters to be protected in tokenisation.
-no-escape ... don't perform HTML escaping on apostrophy, quotes, etc.

然后我们还要进行truecasing,也就是对词汇的大小写进行调整

truecasing: The initial words in each sentence are converted to their most probable casing. This helps reduce data sparsity.,使用的脚本是:

/mosesdecoder/scripts/recaser/train-truecaser.perl和 /scripts/recaser/truecase.perl例子如下
~/mosesdecoder/scripts/recaser/train-truecaser.perl \
--model ~/corpus/truecase-model.en --corpus \
~/corpus/news-commentary-v8.fr-en.tok.en
~/mosesdecoder/scripts/recaser/train-truecaser.perl \
--model ~/corpus/truecase-model.fr --corpus \
~/corpus/news-commentary-v8.fr-en.tok.fr
 ~/mosesdecoder/scripts/recaser/truecase.perl \
--model ~/corpus/truecase-model.en \
< ~/corpus/news-commentary-v8.fr-en.tok.en \
> ~/corpus/news-commentary-v8.fr-en.true.en
~/mosesdecoder/scripts/recaser/truecase.perl \
--model ~/corpus/truecase-model.fr \
< ~/corpus/news-commentary-v8.fr-en.tok.fr \
> ~/corpus/news-commentary-v8.fr-en.true.fr

其中的train-truecaser脚本用来训练truecaser的model,输入文件仍然是你的corpus的已tok文件,作用是修改每一句子的首字母,输出是每个不同单词的形式和频率

manual中的USER GUIDE写到:

Instead of lowercasing all training and test data, we may also want to keep words in their nat-
ural case, and only change the words at the beginning of their sentence to their most frequent
form. This is what we mean by truecasing. Again, this requires first the training of a truecasing
model, which is a list of words and the frequency of their different forms.

然后最后一部就是用刚才的模型进行truecase啦:

truecase.perl --model MODEL [-b] < in > out

 -b代表 unbuffered,不清楚用途目前

 在中文处理中应该不需要truecasing这一步

 

最后的词处理clean,去除一些过长的单词

Finally we clean, limiting sentence length to 80:

 ~/mosesdecoder/scripts/training/clean-corpus-n.perl \
~/corpus/news-commentary-v8.fr-en.true fr en \
~/corpus/news-commentary-v8.fr-en.clean 1 80

二、训练语言模型(使用IRSTLM)

终于搞定了我们的语料了,下面我们要进入更深入的话题:训练语言模型

语言模型最朴实的作用在于让你的output更加流畅,更加像母语,为了达到这一效果,我们需要另外的句子对齐的平行语料来训练我们的语言模型(如果你用training model的同一个语料来训练,未免感觉会无效?)

参看manual中base系统的描述,我们需要用到以下几个工具来训练我们的语言模型。

首先:add-start-end.sh

 ~/irstlm/bin/add-start-end.sh                 \
< ~/corpus/news-commentary-v8.fr-en.true.en \
> news-commentary-v8.fr-en.sb.en

  用于把你的语料添加上开始结束标记(实际上就是<s></s>标签对)

然后使用:build-lm.sh build一个语言模型源文件,输出lm源文件

export IRSTLM=$HOME/irstlm; ~/irstlm/bin/build-lm.sh \
-i news-commentary-v8.fr-en.sb.en \
-t ./tmp -p -s improved-kneser-ney -o news-commentary-v8.fr-en.lm.en

最后compile:

~/irstlm/bin/compile-lm  \

软件需求:

首先你必须要有Moses(废话哈哈)、然后要有GIZA++用作词对齐(traning-model.perl的时候会用到)、IRSTLM产生语言模型

大致步骤:

大体的步骤如下:

  1. 准备Parallerl data(需要句子对齐):对语料进行tokenisation、truecasing和cleaning步骤之后才能使用于我们的机器翻译系统(哈哈,都快忍不住直接写详细步骤了)
  2. 训练你的语言模型(使用IRSTLM):当然也有几步,详细叙述再说
  3. 然后就是训练你的翻译系统啦(可能要花一两个小时):(2) run GIZA
    (3) align words
    (4) learn lexical translation
    (5) extract phrases
    (6) score phrases
    (7) learn reordering model
    (8) learn generation model
    (9) create decoder config file
  4. 最后是蛋疼的Tuning(当然你也可以自己手动的Tuning),大概要花几个小时
  5. 最后你就可以跑了,如果你嫌启动慢,可以把模型转化为Binarised-model来进行,会更快,当然这会需要你改动一些东西,不过很简单

详细步骤以及说明:

一、准备语料:

  首先我们需要你找到你要创建的翻译系统匹配的平行语料,例如英法新闻平行语料,然后对语料进行三步处理后才可以使用:tokenisation、truecasing和cleaning

  首先是tokenisation,就是词例化或者说分词,要使用 :mosesdecoder/scripts/tokenizer/tokenizer.perl进行词例化。 作用是将平行语料(其实是两个文本文件),中的每个句子进行词例化

例子如下:

 ~/mosesdecoder/scripts/tokenizer/tokenizer.perl -l en \
< ~/corpus/training/news-commentary-v8.fr-en.en \
> ~/corpus/news-commentary-v8.fr-en.tok.en
~/mosesdecoder/scripts/tokenizer/tokenizer.perl -l fr \
< ~/corpus/training/news-commentary-v8.fr-en.fr \
> ~/corpus/news-commentary-v8.fr-en.tok.fr

说明:-l 后指定文本的语言,看了一下文件,似乎只支持 en de fr 和 it,如要给中文分词的话,可能需要更多的配置,然后要指定输入的文本和输出的地点,切记 “<”  ">"是必须的!

完整参数说明如下:

Usage ./tokenizer.perl (-l [en|de|...]) (-threads 4) < textfile > tokenizedfile
Options:
-q ... quiet.
-a ... aggressive hyphen splitting.
-b ... disable Perl buffering.
-time ... enable processing time calculation.
-penn ... use Penn treebank-like tokenization.
-protected FILE ... specify file with patters to be protected in tokenisation.
-no-escape ... don't perform HTML escaping on apostrophy, quotes, etc.

然后我们还要进行truecasing,也就是对词汇的大小写进行调整

truecasing: The initial words in each sentence are converted to their most probable casing. This helps reduce data sparsity.,使用的脚本是:

/mosesdecoder/scripts/recaser/train-truecaser.perl和 /scripts/recaser/truecase.perl例子如下

~/mosesdecoder/scripts/recaser/train-truecaser.perl \
--model ~/corpus/truecase-model.en --corpus \
~/corpus/news-commentary-v8.fr-en.tok.en
~/mosesdecoder/scripts/recaser/train-truecaser.perl \
--model ~/corpus/truecase-model.fr --corpus \
~/corpus/news-commentary-v8.fr-en.tok.fr
 ~/mosesdecoder/scripts/recaser/truecase.perl \
--model ~/corpus/truecase-model.en \
< ~/corpus/news-commentary-v8.fr-en.tok.en \
> ~/corpus/news-commentary-v8.fr-en.true.en
~/mosesdecoder/scripts/recaser/truecase.perl \
--model ~/corpus/truecase-model.fr \
< ~/corpus/news-commentary-v8.fr-en.tok.fr \
> ~/corpus/news-commentary-v8.fr-en.true.fr

其中的train-truecaser脚本用来训练truecaser的model,输入文件仍然是你的corpus的已tok文件,作用是修改每一句子的首字母,输出是每个不同单词的形式和频率

manual中的USER GUIDE写到:

Instead of lowercasing all training and test data, we may also want to keep words in their nat-
ural case, and only change the words at the beginning of their sentence to their most frequent
form. This is what we mean by truecasing. Again, this requires first the training of a truecasing
model, which is a list of words and the frequency of their different forms.

然后最后一部就是用刚才的模型进行truecase啦:

truecase.perl --model MODEL [-b] < in > out

 -b代表 unbuffered,不清楚用途目前

 在中文处理中应该不需要truecasing这一步

 

最后的词处理clean,去除一些过长的单词

Finally we clean, limiting sentence length to 80:

 ~/mosesdecoder/scripts/training/clean-corpus-n.perl \
~/corpus/news-commentary-v8.fr-en.true fr en \
~/corpus/news-commentary-v8.fr-en.clean 1 80

二、训练语言模型(使用IRSTLM)

终于搞定了我们的语料了,下面我们要进入更深入的话题:训练语言模型

语言模型最朴实的作用在于让你的output更加流畅,更加像母语,为了达到这一效果,我们需要另外的句子对齐的平行语料来训练我们的语言模型(如果你用training model的同一个语料来训练,未免感觉会无效?)

参看manual中base系统的描述,我们需要用到以下几个工具来训练我们的语言模型。

首先:add-start-end.sh

 ~/irstlm/bin/add-start-end.sh                 \
< ~/corpus/news-commentary-v8.fr-en.true.en \
> news-commentary-v8.fr-en.sb.en

  用于把你的语料添加上开始结束标记(实际上就是<s></s>标签对)

然后使用:build-lm.sh build一个语言模型源文件,输出lm源文件

export IRSTLM=$HOME/irstlm; ~/irstlm/bin/build-lm.sh \
-i news-commentary-v8.fr-en.sb.en \
-t ./tmp -p -s improved-kneser-ney -o news-commentary-v8.fr-en.lm.en

最后compile:

~/irstlm/bin/compile-lm  \
--text \
news-commentary-v8.fr-en.lm.en.gz \
news-commentary-v8.fr-en.arpa.en

注意这里的 --text 后不要加 yes manual中写错了,这样就生成了一个arpa文件(可以用于query和生成二进制的IRSTLM模型以及KenLM模型,这里一直用生成KenLM解决,因为不知道为何IRSTLM不好用)

You can directly create an IRSTLM binary LM (for faster loading in Moses) by replacing the last command with the following:

 ~/irstlm/bin/compile-lm news-commentary-v8.fr-en.lm.en.gz \
news-commentary-v8.fr-en.blm.en

You can transform an arpa LM (*.arpa.en file) into an IRSTLM binary LM as follows:

 ~/irstlm/bin/compile-lm \
news-commentary-v8.fr-en.arpa.en \
news-commentary-v8.fr-en.blm.en

or viceversa, you can transform an IRSTLM binary LM into an arpa LM as follows:

 ~/irstlm/bin/compile-lm \
--text yes \
news-commentary-v8.fr-en.blm.en \
news-commentary-v8.fr-en.arpa.en

This instead binarises (for faster loading) the *.arpa.en file using KenLM:

 ~/mosesdecoder/bin/build_binary \
news-commentary-v8.fr-en.arpa.en \
news-commentary-v8.fr-en.blm.en You can check the language model by querying it, e.g. $ echo "is this an English sentence ?" \
| ~/mosesdecoder/bin/query news-commentary-v8.fr-en.blm.en
   --text  \
news-commentary-v8.fr-en.lm.en.gz \
news-commentary-v8.fr-en.arpa.en

注意这里的 --text 后不要加 yes manual中写错了,这样就生成了一个arpa文件(可以用于query和生成二进制的IRSTLM模型以及KenLM模型,这里一直用生成KenLM解决,因为不知道为何IRSTLM不好用)

You can directly create an IRSTLM binary LM (for faster loading in Moses) by replacing the last command with the following:

 ~/irstlm/bin/compile-lm news-commentary-v8.fr-en.lm.en.gz \
news-commentary-v8.fr-en.blm.en

You can transform an arpa LM (*.arpa.en file) into an IRSTLM binary LM as follows:

 ~/irstlm/bin/compile-lm \
news-commentary-v8.fr-en.arpa.en \
news-commentary-v8.fr-en.blm.en

or viceversa, you can transform an IRSTLM binary LM into an arpa LM as follows:

 ~/irstlm/bin/compile-lm \
--text yes \
news-commentary-v8.fr-en.blm.en \
news-commentary-v8.fr-en.arpa.en

This instead binarises (for faster loading) the *.arpa.en file using KenLM:

 ~/mosesdecoder/bin/build_binary \
news-commentary-v8.fr-en.arpa.en \
news-commentary-v8.fr-en.blm.en

You can check the language model by querying it, e.g.

 $ echo "is this an English sentence ?"                       \
| ~/mosesdecoder/bin/query news-commentary-v8.fr-en.blm.en

三、训练翻译模型

首先看看参数:


Reference: All Training Parameters

  • --root-dir -- root directory, where output files are stored
  • --corpus -- corpus file name (full pathname), excluding extension
  • --e -- extension of the English corpus file
  • --f -- extension of the foreign corpus file
  • --lm -- language model: <factor>:<order>:<filename> (option can be repeated)
  • --first-step -- first step in the training process (default 1)
  • --last-step -- last step in the training process (default 7)
  • --parts -- break up corpus in smaller parts before GIZA++ training
  • --corpus-dir -- corpus directory (default $ROOT/corpus)
  • --lexical-dir -- lexical translation probability directory (default $ROOT/model)
  • --model-dir -- model directory (default $ROOT/model)
  • --extract-file -- extraction file (default $ROOT/model/extract)
  • --giza-f2e -- GIZA++ directory (default $ROOT/giza.$F-$E)
  • --giza-e2f -- inverse GIZA++ directory (default $ROOT/giza.$E-$F)
  • --alignment -- heuristic used for word alignment: intersect, union, grow, grow-final, grow-diag, grow-diag-final (default), grow-diag-final-and, srctotgt, tgttosrc
  • --max-phrase-length -- maximum length of phrases entered into phrase table (default 7)
  • --giza-option -- additional options for GIZA++ training
  • --verbose -- prints additional word alignment information
  • --no-lexical-weighting -- only use conditional probabilities for the phrase table, not lexical weighting
  • --parts -- prepare data for GIZA++ by running snt2cooc in parts
  • --direction -- run training step 2 only in direction 1 or 2 (for parallelization)
  • --reordering -- specifies which reordering models to train using a comma-separated list of config-strings, see FactoredTraining.BuildReorderingModel. (default distance)
  • --reordering-smooth -- specifies the smoothing constant to be used for training lexicalized reordering models. If the letter "u" follows the constant, smoothing is based on actual counts. (default 0.5)
  • --alignment-factors --
  • --translation-factors --
  • --reordering-factors --
  • --generation-factors --
  • --decoding-steps --

Moses创建一个翻译系统的基本过程记录,以后会按照每个过程详细说明,并给出每个步骤的参数说明的更多相关文章

  1. springmvc在处理请求过程中出现异常信息交由异常处理器进行处理,自定义异常处理器可以实现一个系统的异常处理逻辑。为了区别不同的异常通常根据异常类型自定义异常类,这里我们创建一个自定义系统异常,如果controller、service、dao抛出此类异常说明是系统预期处理的异常信息。

    springmvc在处理请求过程中出现异常信息交由异常处理器进行处理,自定义异常处理器可以实现一个系统的异常处理逻辑. 1.1 异常处理思路 系统中异常包括两类:预期异常和运行时异常RuntimeEx ...

  2. 【C语言】创建一个函数,判断某一正整数是否为素数,并调用这个函数找出1000以内所有素数

    #include <stdio.h> int fun(int x) { int n; ;n<=x-;n++) ) break; if(n>=x) ; else ; } main ...

  3. ES 记录之如何创建一个索引映射,以及一些设置

    ElasticSearch 系列文章 1 ES 入门之一 安装ElasticSearcha 2 ES 记录之如何创建一个索引映射 3 ElasticSearch 学习记录之Text keyword 两 ...

  4. 【Spring】创建一个Spring的入门程序

    3.创建一个Spring的入门程序 简单记录 - Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)- Spring的基本应用 Spring与Spring MVC的 ...

  5. linux内核分析作业6:分析Linux内核创建一个新进程的过程

    task_struct结构: struct task_struct {   volatile long state;进程状态  void *stack; 堆栈  pid_t pid; 进程标识符  u ...

  6. 第六周——分析Linux内核创建一个新进程的过程

    "万子恵 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 &q ...

  7. 分析Linux内核创建一个新进程的过程

    一.原理分析 1.进程的描述 进程控制块PCB——task_struct,为了管理进程,内核必须对每个进程进行清晰的描述,进程描述符提供了内核所需了解的进程信息. struct task_struct ...

  8. 分析Linux内核创建一个新进程的过程【转】

    转自:http://www.cnblogs.com/MarkWoo/p/4420588.html 前言说明 本篇为网易云课堂Linux内核分析课程的第六周作业,本次作业我们将具体来分析fork系统调用 ...

  9. 实验六:分析Linux内核创建一个新进程的过程

    原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 题目自拟,内容围绕对Linu ...

随机推荐

  1. vc读写注册表

    注册表是Windows重要组成部分,注册表记录了大量有关电脑软硬件的信息.注册表中的值通过其名称标识.值名称由与键名相同的字符组成.值本身可以是字符串.二进制数据或者是32位无符号值.在这里我们主要运 ...

  2. 简单的python http接口自动化脚本

    今天给大家分享一个简单的Python脚本,使用python进行http的接口测试,脚本很简单,逻辑是:读取excel写好的测试用例,然后根据excel中的用例内容进行调用,判断预期结果中的返回值是否和 ...

  3. TesCase-GUI(图形用户界面)测试

    GUI测试是功能测试的一种表现形式.不仅要考虑GUI本身的测试,也要考虑GUI所表现的系统功能的测试.   GUI应具有的要素 1.符合标准和规范 2.直观性 (1)用户界面是否洁净.不唐突.不拥挤? ...

  4. POJ1002_487-3279_C++

    题目:http://poj.org/problem?id=1002 我知道你们最需要的是这个 [ 手动滑稽 ] STD 给出的方法是丢进一个数组,然后排序,相邻的是重复的 这个方法,时间复杂度很不错, ...

  5. Flex4 自定义通用的ImageButton

    Flex4与之前版本的一个极大区别就是外观皮肤的分离,虽然进一步解耦,但存在一个不爽的地方就是增加了编码的工作量,你能想象为你的每个自定义组件都写一个对应的皮肤吗?可能仅仅和你之前写过的组件差了那么一 ...

  6. 解决在 MVC  局部视图中加载 ueditor 编辑器时, 编辑器加载不出的 bug

    在 MVC 局部视图中,有时我们需要 加载 ueditor 编辑器,或进行局部刷新, 但是在加载局部视图后,ueditor 编辑器加载不出,这是由于 ueditor 使用的缓存,只要清空缓存,重新实例 ...

  7. USACO Section 3.2 香甜的黄油 Sweet Butter

    本题是多源最短路问题 但使用弗洛伊德算法会超时 而因为边数目比较少 所以用队列优化后的迪杰斯特拉算法可以通过 #include<iostream> #include<cstring& ...

  8. 应用OpenCV进行OCR字符识别

    opencv自带一个字符识别的例子,它的重点不是OCR字符识别,而主要是演示机器学习的应用.它应用的是UCI提供的字符数据(特征数据). DAMILES在网上发布了一个应用OpenCV进行OCR的例子 ...

  9. python的文件操作方法

    python中的文件对象:文件对象不仅可以用来访问普通的磁盘文件, 而且也可以访问任何其它类型抽象层面上的"文件". 一旦设置了合适的"钩子", 你就可以访问具 ...

  10. 一个不简单的Procedure body例子

    create or replace package body CountBankData_20150617 is type cursorCommon is ref cursor; --游标类型 str ...