Valerio Gherardi takes us through the concept of k-grams:
The post is structured as follows: we start by giving a succinct theoretical introduction to kk-gram models. Subsequently, we illustrate how to train a kk-gram model in R using
kgrams
, and explain how to use the standard perplexity metric for model evaluation or tuning. Finally, we use our trained model to generate some random text at different temperatures.
This goes into some depth on the topic and is worth giving a careful read.