Complete the implementation of NGramGenerateModel(). But there are some bugs to be handled.