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.
docstr: Returns a list containing all possible words .
  
  :param list words: all words
  :param list legal_indices: indices which has not been skipped
  :param None|list pos: None or list of pos tags
  :param int n: max candidates for each word to be substituted
  :return list: list of list
docstr_tok: ["Returns","a","list","containing","all","possible","words",".",":","param","list","words",":","all","words",":","param","list","legal_indices",":","indices","which","has","not","been","skipped",":","param","None|list","pos",":","None","or","list","of","pos","tags",":","param","int","n",":","max","candidates","for","each","word","to","be","substituted",":","return","list",":","list","of","list"]
code: def _get_substitute_words(
      self, tokens, words, legal_indices, pos=None, n=5, text=None
  ):
      r"""
      Returns a list containing all possible words .
  
      :param list words: all words
      :param list legal_indices: indices which has not been skipped
      :param None|list pos: None or list of pos tags
      :param int n: max candidates for each word to be substituted
      :return list: list of list
  
      """
      # process each legal words to get maximum transformed samples
      legal_words = [
          "".join(tokens[start:end]) for (start, end) in legal_indices
      ]
      pos = (
          {(i[1], i[2] + 1): i[0] for i in pos}
          if self.get_pos
          else None
      )
      legal_words_pos = (
          [pos[index] for index in legal_indices]
          if self.get_pos
          else None
      )
  
      candidates_list = []
      candidates_indices = []
  
      for index, word in enumerate(legal_words):
          _pos = legal_words_pos[index] if self.get_pos else None
          candidates = self._get_candidates(
              word,
              pos=_pos,
              n=n,
              word_position=legal_indices[index],
              text=text,
          )
          # filter no word without candidates
          if candidates:
              candidates_indices.append(legal_indices[index])
              candidates_list.append(candidates)
          if index > n * 3:
              break
      return candidates_list, candidates_indices
  
file_path: textflint/textflint/generation/transformation/UTCN/cn_mlm_suggestion.py
imports: import torch
  from ....common import device
  from ...transformation import CnWordSubstitute
  from ....common.settings import CN_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._get_substitute_words(tokens, words, legal_indices, pos, n, text) and returns: candidates_list,  candidates_indices