Next Word Predictor
Next-word prediction system which internally uses a prebuilt Markov-model to predict the next-word given the current word. Markov models could modelled as directed-graphs where nodes are the words from the training corpus (huge text dataset) and edges represent dependencies. If a directed-edge goes from word A to word B, then its weight is the frequency of word B, given that word A precedes it in the corpus. Once the graph is built, the top-3 words that precede any word 'w' are stored in a hashmap, where the key is the word 'w' and the value is List<String>
that contains the top-3 words succeeding 'w'. These words are displayed to the user as suggestions. For more implementation details, see the rust
branch.
The implementation of the graph is built in Rust, and is interfaced with this class through JNI. The .so libraries for various targets could be found in text-predictor/src/main/jniLibs
. The JNI methods would be found on the rust
branch in src/lib.rs
script.
Example:
val nextWordPredictor = NextWordPredictor( context )
nextWordPredictor.load()
val input = "why"
nextWordPredictor.predict(
input ,
onResult = { results ->
} ,
onError = { error ->
println( error.message
}
)