The way our model work is that it takes input of 1,2, or 3 words, A B C for instance. Then it checks if A B C appears as a trigram in our training set. If it does, then among the whole 4-grams, it checks all of the ones with starting A B C and then provides the words which are the most probable to follow A B C. If A B C does not belong to trigrams, then backs off and checks if B C belongs to bigrams. Then the algorithmn works similarly.