code: def test_l3_kbest():
      params, lengths = params_l3()
      dist = SentCFG(params, lengths=lengths)
  
      _, _, _, spans = dist.argmax
      spans, trees = extract_parses(spans, lengths)
      best_trees = "((0 1) 2)"
      best_spans = [(0, 1, 2), (0, 2, 2)]
      assert spans[0] == best_spans
      assert trees[0] == best_trees
  
      _, _, _, spans = dist.topk(4)
      size = (1, 0) + tuple(range(2, spans.dim()))
      spans = spans.permute(size)
      spans, trees = extract_topk(spans, lengths)
      best_trees = "((0 1) 2)"
      best_spans = [
          [(0, 1, 2), (0, 2, 2)],
          [(0, 1, 2), (0, 2, 2)],
          [(0, 1, 1), (0, 2, 2)],
          [(0, 1, 1), (0, 2, 2)],
      ]
      for i, (span, tree) in enumerate(zip(spans, trees)):
          assert span == best_spans[i]
          assert tree == best_trees
  
imports: import torch
  from torch_struct import SentCFG
label_desc: Use image node_id 5 for calling a global function with example usage: test_l3_kbest() without return types