code: def valid_show(valid_iter, model):
      table = wandb.Table(
          columns=["Sent", "Predicted Tree", "True Tree"]
      )
      Dist = TreeCRF
      for i, ex in enumerate(valid_iter):
          words, lengths = ex.word
          label = ex.label
          batch = label.shape[0]
          words = words.cuda()
          phi = model(words, lengths)
          dist = Dist(phi)
          argmax = dist.argmax
          argmax_tree = dist.struct.from_parts(argmax.detach())[0].cpu()
          for b in range(words.shape[0]):
              out = [WORD.vocab.itos[w.item()] for w in words[b]]
              sent = " ".join(out)
  
              def show(tree):
                  output = ""
                  start = {}
                  end = {}
                  for i, j, _ in tree.nonzero():
                      i = i.item()
                      j = j.item()
                      start.setdefault(i, -1)
                      end.setdefault(j, -1)
                      start[i] += 1
                      end[j] += 1
                  for i, w in enumerate(out):
                      for _ in range(start.get(i, 0)):
                          output += "( "
                      output += w + " "
                      for _ in range(end.get(i, 0)):
                          output += ") "
                  return output
  
              predict_text = show(ex.tree[b].cpu())
              true_text = show(argmax_tree[b].cpu())
              table.add_data(sent, predict_text, true_text)
          break
      return table
  
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 5 for calling a global function with example usage: valid_show(valid_iter, model) and returns: table, output