code: def get_dec_batch(dec_tree_batch, batch_size, device, form_manager):
      queue_tree = {}
      for i in range(1, batch_size + 1):
          queue_tree[i] = []
          queue_tree[i].append(
              {
                  "tree": dec_tree_batch[i - 1],
                  "parent": 0,
                  "child_index": 1,
              }
          )
  
      cur_index, max_index = 1, 1
      dec_batch = {}
      # max_index: the max number of sequence decoder in one batch
      while cur_index <= max_index:
          max_w_len = -1
          batch_w_list = []
          for i in range(1, batch_size + 1):
              w_list = []
              if cur_index <= len(queue_tree[i]):
                  t = queue_tree[i][cur_index - 1]["tree"]
  
                  for ic in range(t.num_children):
                      if isinstance(t.children[ic], Tree):
                          w_list.append(4)
                          queue_tree[i].append(
                              {
                                  "tree": t.children[ic],
                                  "parent": cur_index,
                                  "child_index": ic + 1,
                              }
                          )
                      else:
                          w_list.append(t.children[ic])
                  if len(queue_tree[i]) > max_index:
                      max_index = len(queue_tree[i])
              if len(w_list) > max_w_len:
                  max_w_len = len(w_list)
              batch_w_list.append(w_list)
          dec_batch[cur_index] = torch.zeros(
              (batch_size, max_w_len + 2), dtype=torch.long
          )
          for i in range(batch_size):
              w_list = batch_w_list[i]
              if len(w_list) > 0:
                  for j in range(len(w_list)):
                      dec_batch[cur_index][i][j + 1] = w_list[j]
                  # add <S>, <E>
                  if cur_index == 1:
                      dec_batch[cur_index][i][0] = 1
                  else:
                      dec_batch[cur_index][i][
                          0
                      ] = form_manager.get_symbol_idx("(")
                  dec_batch[cur_index][i][len(w_list) + 1] = 2
  
          dec_batch[cur_index] = to_cuda(dec_batch[cur_index], device)
          cur_index += 1
  
      return dec_batch, queue_tree, max_index
  
imports: import random
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from graph4nlp.pytorch.modules.utils.tree_utils import Tree, to_cuda
  from .attention import Attention
  from .base import RNNTreeDecoderBase
label_desc: Use image node_id 2 for calling a global function with example usage: get_dec_batch(dec_tree_batch, batch_size, device, form_manager) and returns: dec_batch,  queue_tree,  max_index