An n-gram is a sequence of n adjacent items, such as phonemes, syllables, letters, or words, arranged in a specific order. We classify n-grams based on the value of n. If n is 1, it's called a unigram. If n is 2, it's called a bigram. This pattern continues with different prefixes that indicate the number of items in the sequence.
Take the sentence: "The quick brown fox jumps over the lazy dog."
Bigrams give more context than unigrams, and trigrams give even more.
If you want to learn more about n-grams you can go to here and here.
N-gram language models use word sequences (N-grams) to predict the next word in a sentence. They work by looking at the last few words and choosing the most likely word based on patterns from training data.
This makes them useful for capturing word relationships. However, if we want more variety instead of predictable results, we may need to add randomness to the word choice.
You can find more information about this here.
My N-gram model is simple and doesn’t use smoothing techniques or separate functions for each N-gram. Instead, it relies on nested dictionaries: the previous word is stored as a key, and its possible next words are stored as sub-keys with their probabilities. Example (bigram):
Here, the numbers show the probability of one word following another. The model then uses these probabilities to predict the next words in a sequence. You can go to the github repository to see how its done.