This is basically achieved by using dynamic programming and especially the Viterbi algorithm associated with beam searching.
decoding algorithms were designed for translation, not for paraphrase generation.