Adds ngram generation to cpu_reference_implementation