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: Returns a list containing all possible words .
  
  Overwrite _get_substitute_words of super class.
  To accelerate transformation for long text, input single sentence to
  language model rather than whole text.
  
  :param list words: all words
  :param list legal_indices: indices which has not been skipped
  :param list sentences_tokens: list of tokens of each sentence
  :param list|None pos: None or list of pos tags
  :param int n:max candidates for each word to be substituted
  :return list candidates_list: list of candidates list
  :return list candidates_indices: list of candidates_indices list
docstr_tok: ["Returns","a","list","containing","all","possible","words",".","Overwrite","_get_substitute_words","of","super","class",".","To","accelerate","transformation","for","long","text",",","input","single","sentence","to","language","model","rather","than","whole","text",".",":","param","list","words",":","all","words",":","param","list","legal_indices",":","indices","which","has","not","been","skipped",":","param","list","sentences_tokens",":","list","of","tokens","of","each","sentence",":","param","list|None","pos",":","None","or","list","of","pos","tags",":","param","int","n",":","max","candidates","for","each","word","to","be","substituted",":","return","list","candidates_list",":","list","of","candidates","list",":","return","list","candidates_indices",":","list","of","candidates_indices","list"]
code: def _get_substitute_words(
      self, words, legal_indices, sentences_tokens, pos=None, n=5
  ):
      r"""
      Returns a list containing all possible words .
  
      Overwrite _get_substitute_words of super class.
      To accelerate transformation for long text, input single sentence to
      language model rather than whole text.
  
      :param list words: all words
      :param list legal_indices: indices which has not been skipped
      :param list sentences_tokens: list of tokens of each sentence
      :param list|None pos: None or list of pos tags
      :param int n:max candidates for each word to be substituted
      :return list candidates_list: list of candidates list
      :return list candidates_indices: list of candidates_indices list
  
      """
      (
          sub_indices,
          sub_sentences,
          sub_sent_indices,
      ) = self._get_relate_sub_info(
          words, sentences_tokens, legal_indices
      )
  
      assert len(sub_sentences) == len(sub_indices)
  
      candidates_list = []
      candidates_indices = []
      mask_word_pos_list = []
      mask_indices = []
      batch_tokens_tensor = torch.tensor(
          [], dtype=torch.long, device=self.device
      )
      batch_size = 0
  
      for i, mask_word_index in enumerate(sub_indices):
          mask_original_word_pos = pos[mask_word_index][:2]
          if mask_original_word_pos not in self.pos_allowed_token_id:
              continue
  
          candidates_indices.append(mask_word_index)
          mask_indices.append(sub_sent_indices[i] + 1)
          mask_word_pos_list.append(mask_original_word_pos)
  
          # process each legal words to get maximum transformed samples
          sent_tokens = (
              ["[CLS]"]
              + copy(sentences_tokens[sub_sentences[i]])
              + ["[SEP]"]
          )
          sent_tokens[sub_sent_indices[i] + 1] = "[MASK]"
          # padding sentence to do batch predict
          sent_tokens = sent_tokens + ["[PAD]"] * (
              self.max_sent_size - len(sent_tokens)
          )
          indexed_tokens = self.tokenizer.convert_tokens_to_ids(
              sent_tokens[: self.max_sent_size]
          )
          tokens_tensor = torch.tensor(
              [indexed_tokens], dtype=torch.long, device=self.device
          )
          batch_tokens_tensor = torch.cat(
              (batch_tokens_tensor, tokens_tensor)
          )
          batch_size += 1
  
      if batch_size > 0:
          segments_tensors = torch.zeros(
              batch_size,
              self.max_sent_size,
              dtype=torch.int64,
              device=self.device,
          )
          candidates_list = self._get_candidates(
              batch_tokens_tensor,
              segments_tensors,
              mask_indices,
              mask_word_pos_list,
              n=n,
          )
  
      return candidates_list, candidates_indices
  
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 7 for calling the MLMSuggestion obj's underlying member method code with example usage: obj._get_substitute_words(words, legal_indices, sentences_tokens, pos, n) and returns: candidates_list,  candidates_indices