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: Get candidates from MLM model.
  
  :param torch.tensor batch_tokens_tensor: tokens tensor input
  :param torch.tensor segments_tensors: segment input
  :param list mask_indices: indices to predict candidates
  :param list mask_word_pos_list: pos tags of original target words
  :param int n: candidates number
  :return: list candidates
docstr_tok: ["Get","candidates","from","MLM","model",".",":","param","torch.tensor","batch_tokens_tensor",":","tokens","tensor","input",":","param","torch.tensor","segments_tensors",":","segment","input",":","param","list","mask_indices",":","indices","to","predict","candidates",":","param","list","mask_word_pos_list",":","pos","tags","of","original","target","words",":","param","int","n",":","candidates","number",":","return",":","list","candidates"]
code: def _get_candidates(
      self,
      batch_tokens_tensor,
      segments_tensors,
      mask_indices,
      mask_word_pos_list,
      n=5,
  ):
      r"""
      Get candidates from MLM model.
  
      :param torch.tensor batch_tokens_tensor: tokens tensor input
      :param torch.tensor segments_tensors: segment input
      :param list mask_indices: indices to predict candidates
      :param list mask_word_pos_list: pos tags of original target words
      :param int n: candidates number
      :return: list candidates
      """
      with torch.no_grad():
          output = self.model(batch_tokens_tensor, segments_tensors)
  
      candidates_list = []
  
      for i, tup in enumerate(zip(mask_indices, mask_word_pos_list)):
          mask_index, mask_original_word_pos = tup
          predict_tensor = output[0][i, mask_index]
          allowed_token_id = self.pos_allowed_token_id[
              mask_original_word_pos
          ]
          pos_allowed_predict = predict_tensor.gather(
              0, allowed_token_id
          )
          prob_values, topk_index = pos_allowed_predict.topk(
              min(pos_allowed_predict.shape[0], n)
          )
          original_vocab_index = allowed_token_id.gather(0, topk_index)
          replace_words = self.tokenizer.convert_ids_to_tokens(
              original_vocab_index
          )
          candidates_list.append(replace_words)
  
      return candidates_list
  
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 9 for calling the MLMSuggestion obj's underlying member method code with example usage: obj._get_candidates(batch_tokens_tensor, segments_tensors, mask_indices, mask_word_pos_list, n) and returns: candidates_list