code: def validate(val_iter):
      incorrect_edges = 0
      total_edges = 0
      model.eval()
      for i, ex in enumerate(val_iter):
          words, mapper, _ = ex.word
          label, lengths = ex.head
          batch, _ = label.shape
  
          final = model(words.cuda(), mapper)
          for b in range(batch):
              final[b, lengths[b] - 1 :, :] = 0
              final[b, :, lengths[b] - 1 :] = 0
          dist = DependencyCRF(final, lengths=lengths)
          gold = dist.struct.to_parts(label, lengths=lengths).type_as(
              dist.argmax
          )
          incorrect_edges += (
              dist.argmax[:, :].cpu() - gold[:, :].cpu()
          ).abs().sum() / 2.0
          total_edges += gold.sum()
  
      print(total_edges, incorrect_edges)
      model.train()
  
file_path: pytorch-struct/examples/bert-dep.py
imports: import torchtext
  import torch
  from torch import nn
  from torch_struct import DependencyCRF
  from torch_struct.data import SubTokenizedField, ConllXDataset, TokenBucket
  from torchtext.data import RawField, BucketIterator
  from pytorch_transformers import BertModel, BertTokenizer, AdamW, WarmupLinearSchedule
label_desc: Use image node_id 3 for calling a global function with example usage: validate(val_iter) without return types