1. A computer implemented method for encoding data, the method comprising: in response to an input stream having a plurality of symbols in sequence, buffering an initial chunk of symbols; determining a number of escape tokens that would be emitted at each stage of encoding at least buffered initial chunk; for each stage, determining a base value and a step value for the escape token using a heuristic modeling function in view of the determined number of escape tokens such that a number of bits required to encode the input stream is minimized; and encoding the input stream using an adaptive context model having a context for each stage to generate an output stream, wherein each context is initialized with the corresponding base value and step value generated from the heuristic modeling function, and wherein the output stream includes the base value and step value for each stage.