基于RNN的LM在性能上优于传统的N-gram LM,在实际使用时RNN_LM还可以与N-gram LM联合使用,进一步提高性能。
1. 从点击打开链接下载c++代码。
2. 修改makefile 中对应内容为: CC = g++
3. 替换rnnlmlib.cpp中的 函数exp10为pow(x,y)。
4.在cygwin 下运行代码自带的example.sh,进行训练得到模型文件model。
#rnn model is trained here
time ./rnnlm -train train -valid valid -rnnlm model -hidden 15 -rand-seed 1 -debug 2 -class 100 -bptt 4 -bptt-block 10 -direct-order 3 -direct 2 -binary
5. 测试,在cygwin中输入./rnnlm -rnnlm model -test test -nbest -debug 0 > scores.txt
得到的scores.txt的行数和测试输入文本文件的行数相同,每个句子一行。scores.txt显示了每个句子的概率log值。
6. 具体算法参考Tomas Mikolov,Statistical Language Models Based on Neural Networks。