5

Moses是一个建立机器翻译模型的软件。并且KenLM是 moses 使用的事实上的语言模型软件。

我有一个包含 16GB 文本的文本文件,我用它来构建这样的语言模型:

bin/lmplz -o 5 <text > text.arpa

生成的文件 ( text.arpa) 为 38GB。然后我将语言模型二值化为:

bin/build_binary text.arpa text.binary

二值化语言模型 ( text.binary) 增长到 71GB。

中,在训练翻译模型后,您应该使用算法moses调整模型的权重。MERT这可以通过https://github.com/moses-smt/mosesdecoder/blob/master/scripts/training/mert-moses.pl轻松完成。

MERT 适用于小语言模型,但对于大语言模型,需要相当长的时间才能完成。

我进行了谷歌搜索,发现了 KenLM 的过滤器,它承诺将语言模型过滤到更小的尺寸:https ://kheafield.com/code/kenlm/filter/

但我对如何使它工作一无所知。命令帮助给出:

$ ~/moses/bin/filter
Usage: /home/alvas/moses/bin/filter mode [context] [phrase] [raw|arpa] [threads:m] [batch_size:m] (vocab|model):input_file output_file

copy mode just copies, but makes the format nicer for e.g. irstlm's broken
    parser.
single mode treats the entire input as a single sentence.
multiple mode filters to multiple sentences in parallel.  Each sentence is on
    a separate line.  A separate file is created for each sentence by appending
    the 0-indexed line number to the output file name.
union mode produces one filtered model that is the union of models created by
    multiple mode.

context means only the context (all but last word) has to pass the filter, but
    the entire n-gram is output.

phrase means that the vocabulary is actually tab-delimited phrases and that the
    phrases can generate the n-gram when assembled in arbitrary order and
    clipped.  Currently works with multiple or union mode.

The file format is set by [raw|arpa] with default arpa:
raw means space-separated tokens, optionally followed by a tab and arbitrary
    text.  This is useful for ngram count files.
arpa means the ARPA file format for n-gram language models.

threads:m sets m threads (default: conccurrency detected by boost)
batch_size:m sets the batch size for threading.  Expect memory usage from this
    of 2*threads*batch_size n-grams.

There are two inputs: vocabulary and model.  Either may be given as a file
    while the other is on stdin.  Specify the type given as a file using
    vocab: or model: before the file name.  

For ARPA format, the output must be seekable.  For raw format, it can be a
    stream i.e. /dev/stdout

但是当我尝试以下操作时,它会卡住并且什么也不做:

$ ~/moses/bin/filter union lm.en.binary lm.filter.binary
Assuming that lm.en.binary is a model file
Reading lm.en.binary
----5---10---15---20---25---30---35---40---45---50---55---60---65---70---75---80---85---90---95--100

二值化后的语言模型应该怎么做?是否有任何其他步骤来操作大型语言模型以减少调整时的计算负载?

调整大型 LM 文件的常用方法是什么?

如何使用 KenLM 的过滤器?

(有关https://www.mail-archive.com/moses-support@mit.edu/msg12089.html的更多详细信息)

4

1 回答 1

1

回答如何使用KenLMfilter的命令

cat small_vocabulary_one_word_per_line.txt \
  | filter single \
         "model:LM_large_vocab.arpa" \
          output_LM_small_vocab.

注意:single可以用unionor代替copy。如果您在filter没有参数的情况下运行二进制文件,请阅读正在打印的帮助中的更多信息。

于 2017-09-20T16:03:07.943 回答