code: def linearize_tree(vocab, root, xp=numpy):
      # Left node indexes for all parent nodes
      lefts = []
      # Right node indexes for all parent nodes
      rights = []
      # Parent node indexes
      dests = []
      # All labels to predict for all parent nodes
      labels = []
  
      # All words of leaf nodes
      words = []
      # Leaf labels
      leaf_labels = []
  
      # Current leaf node index
      leaf_index = [0]
  
      def traverse_leaf(exp):
          if len(exp) == 2:
              label, leaf = exp
              if leaf not in vocab:
                  vocab[leaf] = len(vocab)
              words.append(vocab[leaf])
              leaf_labels.append(int(label))
              leaf_index[0] += 1
          elif len(exp) == 3:
              _, left, right = exp
              traverse_leaf(left)
              traverse_leaf(right)
  
      traverse_leaf(root)
  
      # Current internal node index
      node_index = leaf_index
      leaf_index = [0]
  
      def traverse_node(exp):
          if len(exp) == 2:
              leaf_index[0] += 1
              return leaf_index[0] - 1
          elif len(exp) == 3:
              label, left, right = exp
              l = traverse_node(left)
              r = traverse_node(right)
  
              lefts.append(l)
              rights.append(r)
              dests.append(node_index[0])
              labels.append(int(label))
  
              node_index[0] += 1
              return node_index[0] - 1
  
      traverse_node(root)
      assert len(lefts) == len(words) - 1
  
      return {
          "lefts": xp.array(lefts, xp.int32),
          "rights": xp.array(rights, xp.int32),
          "dests": xp.array(dests, xp.int32),
          "words": xp.array(words, xp.int32),
          "labels": xp.array(labels, xp.int32),
          "leaf_labels": xp.array(leaf_labels, xp.int32),
      }
  
imports: import argparse
  import warnings
  import numpy
  import chainer
  import chainer.functions
  import chainer.links
  from chainer import reporter
  from chainer import training
  from chainer.training import extensions
  import data
  import thin_stack
label_desc: Use image node_id 1 for calling a global function with example usage: linearize_tree(vocab, root, xp) and returns: dict, unknown, unknown