class_docstr: Parallelly Word replace transformation to implement normal word replace functions.
class_docstr_tok: ["Parallelly","Word","replace","transformation","to","implement","normal","word","replace","functions","."]
docstr: Transform text string according field.
  
  :param dict sample: input data, normally one data component.
  :param str fields: indicate which field to apply transformation
  :param int n: number of generated samples
  :return list: transformed sample list.
docstr_tok: ["Transform","text","string","according","field",".",":","param","dict","sample",":","input","data",",","normally","one","data","component",".",":","param","str","fields",":","indicate","which","field","to","apply","transformation",":","param","int","n",":","number","of","generated","samples",":","return","list",":","transformed","sample","list","."]
code: def _transform(
      self, sample, field=["source", "target"], n=1, **kwargs
  ):
      r"""
      Transform text string according field.
  
      :param dict sample: input data, normally one data component.
      :param str fields: indicate which field to apply transformation
      :param int n: number of generated samples
      :return list: transformed sample list.
  
      """
  
      field.sort()
      source_tokens = sample.get_words(field[0])
      target_tokens = sample.get_words(field[1])
      source_tokens_mask = sample.get_mask(field[0])
      target_tokens_mask = sample.get_mask(field[1])
  
      # return up to (len(sub_indices) * n) candidates
      source_pos_info = (
          sample.get_pos(field[0]) if self.get_pos else None
      )
      target_pos_info = (
          sample.get_pos(field[1]) if self.get_pos else None
      )
      source_legal_indices = self.skip_aug(
          source_tokens, source_tokens_mask, pos=source_pos_info
      )
      target_legal_indices = self.skip_aug(
          target_tokens, target_tokens_mask, pos=target_pos_info
      )
  
      if not (source_legal_indices and target_legal_indices):
          return []
  
      sub_words, sub_indices = self._get_substitute_words(
          (source_tokens, target_tokens),
          (source_legal_indices, target_legal_indices),
          pos=(source_pos_info, target_pos_info),
          n=n,
      )
  
      # select property candidates
      trans_num = self.get_trans_cnt(len(source_tokens))
      sub_words, sub_indices = trade_off_sub_words(
          sub_words, sub_indices, trans_num, n
      )
  
      if not sub_words:
          return []
  
      trans_samples = []
      for i in range(len(sub_words)):
          single_sub_words = sub_words[i]
          trans_samples.append(
              sample.replace_field_at_indices(
                  field[0],
                  [e[0] for e in sub_indices],
                  single_sub_words,
              ).replace_field_at_indices(
                  field[1],
                  [e[1] for e in sub_indices],
                  single_sub_words,
              )
          )
      return trans_samples
  
file_path: textflint/textflint/generation/transformation/NMT/parallel_word_substitute.py
imports: from abc import abstractmethod
  from ..word_substitute import WordSubstitute
  from ....common.utils.error import FlintError
  from ....common.utils import logger
  from ....common.utils.list_op import trade_off_sub_words
label_desc: Use image node_id 3 for calling the ParallelWordSubstitute obj's underlying member method code with example usage: obj._transform(sample, field, n) and returns: trans_samples, list, list