code: def trade_off_sub_words(sub_words, sub_indices, trans_num=None, n=1):
      r"""
      Select proper candidate words to maximum number of transform result.
      Select words of top n substitutes words number.
  
      :param list sub_words: list of substitutes word of each legal word
      :param list sub_indices: list of indices of each legal word
      :param int trans_num: max number of words to apply substitution
      :param int n:
      :return: sub_words after alignment + indices of sub_words
      """
  
      assert len(sub_words) == len(
          sub_indices
      ), "The length of sub_words and sub_indices should be the same"
      # max number of words to apply transform
      trans_num = (
          min(trans_num, len(sub_words))
          if trans_num
          else len(sub_words)
      )
  
      re_sub_words = []
      re_sub_indices = []
      for i, j in zip(sub_words, sub_indices):
          if isinstance(i, list) and i:
              re_sub_words.append(i)
              re_sub_indices.append(j)
  
      if trans_num < len(re_sub_words):
          trans_info = [
              [i, j] for i, j in zip(re_sub_words, re_sub_indices)
          ]
          trans_info = random.sample(trans_info, trans_num)
          re_sub_words = [i for i, j in trans_info]
          re_sub_indices = [j for i, j in trans_info]
  
      if not re_sub_words:
          return [], []
  
      return descartes(re_sub_words, n), re_sub_indices
  
imports: import copy
  import random
  from .logger import logger
label_desc: Use image node_id 1 for calling a global function with example usage: trade_off_sub_words(sub_words, sub_indices, trans_num, n) and returns: descartes,  re_sub_indices, list,  list