We create a simple algorithm that calculates the probability of the tail word in a phrase. The following is a simple example of the basic backoff algorithm:
- The user types in a three word phrase, such as “he is a”.
- We search through all quad-grams (4-word phrases) from our corpus of text provided by Swiftkey. We calculate all frequencies where the first three words are “he is a” within the quad-gram file. For example “he is a big” may occur 20 times and “he is a very” may occur 10 times.
- The most common 4-word phrase is used as the text prediction. In other words, if the phrase, “he is a big” is the most common 4-word phrase that starts with “he is a”, we predict the tail word to be “big”.
- If no perfect match exists, we “backoff” to the next lower order n-gram. Here we would search for all two-word phrases in the tri-grams that start with “is a”. Then predict the most fequent tail word.
- If no two-word phrase exists within our tri-gram file, we would search the one word phrase “a” in the bi-gram file.
If no appropriate phrase is found within the bi-gram, the most common uni-gram word is selected.