class_docstr: Transforms an input by replacing its tokens with words of mask language
  predicted.
  To accelerate transformation for long text, input single sentence to
  language model rather than whole text.
class_docstr_tok: ["Transforms","an","input","by","replacing","its","tokens","with","words","of","mask","language","predicted",".","To","accelerate","transformation","for","long","text",",","input","single","sentence","to","language","model","rather","than","whole","text","."]
docstr: Transform text string according field.
  
  :param Sample sample: input data, normally one data component.
  :param str field: indicate which field to apply transformation
  :param int n: number of generated samples
  :param kwargs:
  :return list trans_samples: transformed sample list.
docstr_tok: ["Transform","text","string","according","field",".",":","param","Sample","sample",":","input","data",",","normally","one","data","component",".",":","param","str","field",":","indicate","which","field","to","apply","transformation",":","param","int","n",":","number","of","generated","samples",":","param","kwargs",":",":","return","list","trans_samples",":","transformed","sample","list","."]
code: def _transform(self, sample, field="x", n=1, **kwargs):
      r"""
      Transform text string according field.
  
      :param Sample sample: input data, normally one data component.
      :param str field: indicate which field to apply transformation
      :param int n: number of generated samples
      :param kwargs:
      :return list trans_samples: transformed sample list.
  
      """
  
      if not self.pos_allowed_token_id:
          self.get_model()
          self.pos_allowed_token_id = (
              self.pre_calculate_allowed_tokens()
          )
  
      tokens = sample.get_words(field)
      tokens_mask = sample.get_mask(field)
      # accelerate computation for long text
      if len(tokens) > self.max_sent_size:
          sentences = sample.get_sentences(field)
          sentences_tokens = [
              self.processor.tokenize(sent) for sent in sentences
          ]
      else:
          sentences_tokens = [tokens]
  
      # return up to (len(sub_indices) * n) candidates
      pos_info = sample.get_pos(field)
      legal_indices = self.skip_aug(tokens, tokens_mask)
  
      if not legal_indices:
          return []
  
      sub_words, sub_indices = self._get_substitute_words(
          tokens, legal_indices, sentences_tokens, pos=pos_info, n=n
      )
  
      # select property candidates
      sub_words, sub_indices = trade_off_sub_words(
          sub_words, sub_indices, n=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, sub_indices, single_sub_words
              )
          )
  
      return trans_samples
  
file_path: textflint/textflint/generation/transformation/UT/mlm_suggestion.py
imports: import torch
  from copy import copy
  from collections import defaultdict
  from ....common import device
  from ...transformation.word_substitute import WordSubstitute
  from ....common.settings import BERT_MODEL_NAME
  from ....common.utils.list_op import trade_off_sub_words
label_desc: Use image node_id 6 for calling the MLMSuggestion obj's underlying member method code with example usage: obj._transform(sample, field, n) and returns: trans_samples, list, list