code: def valid_sup(valid_iter, model, tree_lstm, V):
      total = 0
      correct = 0
      Dist = TreeCRF
      for i, ex in enumerate(valid_iter):
          words, lengths = ex.word
          trees = ex.tree
          label = ex.label
          words = words.cuda()
  
          def tree_reward(spans):
              new_spans = expand_spans(spans, words, 1, V)
              g, labels, indices, topo = TreeLSTM.spans_to_dgl(
                  new_spans
              )
              _, am = tree_lstm(g, labels, indices, topo, lengths).max(
                  -1
              )
              return (label == am).sum(), label.shape[0]
  
          words = words.cuda()
          phi = model(words, lengths)
          dist = TreeCRF(phi, lengths)
          argmax = dist.argmax
          argmax_tree = dist.struct.from_parts(argmax.detach())[0]
          score, tota = tree_reward(argmax_tree)
          total += int(tota)
          correct += score
  
          if i == 25:
              break
      print(correct.item() / float(total), correct, total)
      return correct.item() / float(total)
  
file_path: pytorch-struct/examples/tree.py
imports: from torch_struct import TreeCRF, SelfCritical
  import torchtext.data
  from torch_struct.data import ListOpsDataset, TokenBucket
  from torch_struct.networks import TreeLSTM, SpanLSTM
  import torch
  import torch.nn
  import wandb
label_desc: Use image node_id 3 for calling a global function with example usage: valid_sup(valid_iter, model, tree_lstm, V) and returns: unknown, unknown,  label