def get_final_text(pred_text, orig_text, tokenizer):
<EOL>def _strip_spaces(text):<EOL><INDENT>ns_chars = []<EOL>ns_to_s_map = OrderedDict()<EOL>for (i, c) in enumerate(text):<EOL><INDENT>if c == '<STR_LIT:U+0020>':<EOL><INDENT>continue<EOL><DEDENT>ns_to_s_map[len(ns_chars)] = i<EOL>ns_chars.append(c)<EOL><DEDENT>ns_text = '<STR_LIT>'.join(ns_chars)<EOL>return (ns_text, ns_to_s_map)<EOL><DEDENT>tok_text = '<STR_LIT:U+0020>'.join(tokenizer(orig_text))<EOL>start_position = tok_text.find(pred_text)<EOL>if start_position == -<NUM_LIT:1>:<EOL><INDENT>return orig_text<EOL><DEDENT>end_position = start_position + len(pred_text) - <NUM_LIT:1><EOL>(orig_ns_text, orig_ns_to_s_map) = _strip_spaces(orig_text)<EOL>(tok_ns_text, tok_ns_to_s_map) = _strip_spaces(tok_text)<EOL>if len(orig_ns_text) != len(tok_ns_text):<EOL><INDENT>return orig_text<EOL><DEDENT>tok_s_to_ns_map = {}<EOL>for (i, tok_index) in six.iteritems(tok_ns_to_s_map):<EOL><INDENT>tok_s_to_ns_map[tok_index] = i<EOL><DEDENT>orig_start_position = None<EOL>if start_position in tok_s_to_ns_map:<EOL><INDENT>ns_start_position = tok_s_to_ns_map[start_position]<EOL>if ns_start_position in orig_ns_to_s_map:<EOL><INDENT>orig_start_position = orig_ns_to_s_map[ns_start_position]<EOL><DEDENT><DEDENT>if orig_start_position is None:<EOL><INDENT>return orig_text<EOL><DEDENT>orig_end_position = None<EOL>if end_position in tok_s_to_ns_map:<EOL><INDENT>ns_end_position = tok_s_to_ns_map[end_position]<EOL>if ns_end_position in orig_ns_to_s_map:<EOL><INDENT>orig_end_position = orig_ns_to_s_map[ns_end_position]<EOL><DEDENT><DEDENT>if orig_end_position is None:<EOL><INDENT>return orig_text<EOL><DEDENT>output_text = orig_text[orig_start_position:(orig_end_position + <NUM_LIT:1>)]<EOL>return output_text<EOL>
Project the tokenized prediction back to the original text.