It is often the case that during the course of learning, some match states in the model are used by few sequences, while some insertion states are used by many sequences. Model surgery is a means of dynamically adjusting the model during training.
The basic operation of surgery is to delete modules with unused match states and to insert modules in place of over-used insert states. In the default case, any match state used by fewer than half the sequences is removed, forcing those sequences to use an insert state or to significantly change their alignment to the model. Similarly, any insert state used by more than half the sequences is replaced with a number of match states approximating the average number of characters inserted by that insert state. After surgery the model is retrained to adjust to the new situation. This process can be continued until the model is stable.
For finer tuning of the surgery process, the user can adjust the fraction of sequences that must use a match state, the fraction of sequences that are allowed to use an insert state, and the scaling used when replacing an insert state with one or more match states. While the default 50% usage heuristic stabalizes after a few surgery iterations, careless setting of these fine-tuning parameters can result in a model that oscillates, switching back and forth between match and insert states.