class_docstr: Transformer model for simultaneous translation.
code: def translate(self, text, use_gpu=False):
      paddle.set_device("gpu") if use_gpu else paddle.set_device("cpu")
  
      # Word segmentation
      text = " ".join(jieba.cut(text))
      # For decoding max length
      decoder_max_length = 1
      # For decoding cache
      cache = None
      # For decoding start token id
      bos_id = None
      # Current source word index
      i = 0
      # For decoding: is_last=True, max_len=256
      is_last = False
      # Tokenized id
      user_input_tokenized = []
      # Store the translation
      result = []
  
      bpe_str, tokenized_src = self.tokenizer.tokenize(text)
      while i < len(tokenized_src):
          user_input_tokenized.append(tokenized_src[i])
          if bpe_str[i] in ["。", "？", "！"]:
              is_last = True
          result, cache, bos_id = predict(
              user_input_tokenized,
              decoder_max_length,
              is_last,
              cache,
              bos_id,
              result,
              self.tokenizer,
              self.transformer,
              max_out_len=self.max_out_len,
          )
          i += 1
      return " ".join(result)
  
file_path: PaddleHub/modules/text/simultaneous_translation/stacl/transformer_nist_wait_5/module.py
imports: import os
  import jieba
  import paddle
  from paddlenlp.transformers import position_encoding_init
  from paddlenlp.transformers import WordEmbedding, PositionalEmbedding
  from paddlehub.env import MODULE_HOME
  from paddlehub.module.module import moduleinfo, serving
  from transformer_nist_wait_5.model import SimultaneousTransformer
  from transformer_nist_wait_5.processor import STACLTokenizer, predict
label_desc: Use image node_id 2 for calling the STTransformer obj's underlying member method code with example usage: obj.translate(text, use_gpu) and returns: str