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; searching the word lattice for N best paths, where N is a positive integer; and determining one or more candidate sentences comprising candidate words based on the N best paths, where the method is performed by one or more hardware processors of the device.