//  [python]
def __init__(self, model: str, **kwargs):
        """Build an automatic post editing pipeline with a model dir.

        @param model: Model path for saved pb file
        """
        super().__init__(model=model, **kwargs)
        export_dir = model
        self.cfg = Config.from_file(
            os.path.join(export_dir, ModelFile.CONFIGURATION))
        joint_vocab_file = os.path.join(
            export_dir, self.cfg[ConfigFields.preprocessor]['vocab'])
        self.vocab = dict([(w.strip(), i) for i, w in enumerate(
            open(joint_vocab_file, 'r', encoding='utf8'))])
        self.vocab_reverse = dict([(i, w.strip()) for i, w in enumerate(
            open(joint_vocab_file, 'r', encoding='utf8'))])
        self.unk_id = self.cfg[ConfigFields.preprocessor].get('unk_id', -1)
        strip_unk = self.cfg.get(ConfigFields.postprocessor,
                                 {}).get('strip_unk', True)
        self.unk_token = '' if strip_unk else self.cfg.get(
            ConfigFields.postprocessor, {}).get('unk_token', '<unk>')
        if self.unk_id == -1:
            self.unk_id = len(self.vocab) - 1
        tf.reset_default_graph()
        tf_config = tf.ConfigProto(allow_soft_placement=True)
        tf_config.gpu_options.allow_growth = True
        self._session = tf.Session(config=tf_config)
        tf.saved_model.loader.load(
            self._session, [tf.python.saved_model.tag_constants.SERVING],
            export_dir)
        default_graph = tf.get_default_graph()
        self.input_src_id_placeholder = default_graph.get_tensor_by_name(
            'Placeholder:0')
        self.input_src_len_placeholder = default_graph.get_tensor_by_name(
            'Placeholder_1:0')
        self.input_mt_id_placeholder = default_graph.get_tensor_by_name(
            'Placeholder_2:0')
        self.input_mt_len_placeholder = default_graph.get_tensor_by_name(
            'Placeholder_3:0')
        output_id_beam = default_graph.get_tensor_by_name(
            'enc2enc/decoder/transpose:0')
        output_len_beam = default_graph.get_tensor_by_name(
            'enc2enc/decoder/Minimum:0')
        output_id = tf.cast(
            tf.map_fn(lambda x: x[0], output_id_beam), dtype=tf.int64)
        output_len = tf.map_fn(lambda x: x[0], output_len_beam)
        self.output = {'output_ids': output_id, 'output_lens': output_len}
        init = tf.global_variables_initializer()
        local_init = tf.local_variables_initializer()
        self._session.run([init, local_init])
        tf.saved_model.loader.load(
            self._session, [tf.python.saved_model.tag_constants.SERVING],
            export_dir)

        # preprocess
        self._src_lang = self.cfg[ConfigFields.preprocessor]['src_lang']
        self._tgt_lang = self.cfg[ConfigFields.preprocessor]['tgt_lang']
        tok_escape = self.cfg[ConfigFields.preprocessor].get(
            'tokenize_escape', False)
        src_tokenizer = MosesTokenizer(lang=self._src_lang)
        mt_tokenizer = MosesTokenizer(lang=self._tgt_lang)
        truecase_model = os.path.join(
            export_dir, self.cfg[ConfigFields.preprocessor]['truecaser'])
        truecaser = MosesTruecaser(load_from=truecase_model)
        sp_model = os.path.join(
            export_dir, self.cfg[ConfigFields.preprocessor]['sentencepiece'])
        sp = SentencePieceProcessor()
        sp.load(sp_model)

        self.src_preprocess = lambda x: ' '.join(
            sp.encode_as_pieces(
                truecaser.truecase(
                    src_tokenizer.tokenize(
                        x, return_str=True, escape=tok_escape),
                    return_str=True)))
        self.mt_preprocess = lambda x: ' '.join(
            sp.encode_as_pieces(
                truecaser.truecase(
                    mt_tokenizer.tokenize(
                        x, return_str=True, escape=tok_escape),
                    return_str=True)))

        # post process, de-bpe, de-truecase, detok
        detruecaser = MosesDetruecaser()
        detokenizer = MosesDetokenizer(lang=self._tgt_lang)
        self.postprocess_fun = lambda x: detokenizer.detokenize(
            detruecaser.detruecase(
                x.replace(' ▁', '@@').replace(' ', '').replace('@@', ' ').
                strip()[1:],
                return_str=True).split())