1. A method comprising: receiving a sequence of keyboard events representing keystrokes input to a virtual keyboard of a device; traversing a hierarchical data structure according to the sequence of keyboard events to determine candidate words; constructing a word lattice based on a language model, including deriving path weights from candidate word statistics and keyboard error model data, wherein deriving the path weights is based on a function having one or more first parameters including the candidate word statistics and one or more second parameters including the keyboard error model data; searching the word lattice for N best paths, where N is a positive integer; determining one or more candidate sentences comprising candidate words based on the N best paths; and presenting the candidate sentences on a user interface component of the device, where the method is performed by one or more hardware processors of the device.