implemented the code for context prediction