code: def test_mst_respects_no_outgoing_root_edges_constraint(self):
      # This energy tensor expresses the following relation:
      # energy[i,j] = "Score that i is the head of j". In this
      # case, we have heads pointing to their children.
  
      # We want to construct a case that has 2 children for the ROOT node,
      # because in a typical dependency parse there should only be one
      # word which has the ROOT as it's head.
      energy = torch.Tensor([[0, 9, 5], [2, 0, 4], [3, 1, 0]])
  
      length = torch.LongTensor([3])
      heads, _ = decode_mst(
          energy.numpy(), length.item(), has_labels=False
      )
  
      # This is the correct MST, but not desirable for dependency parsing.
      assert list(heads) == [-1, 0, 0]
      # If we run the decoding with the model, it should enforce
      # the constraint.
      heads_model, _ = self.model._run_mst_decoding(
          energy.view(1, 1, 3, 3), length
      )  # pylint: disable=protected-access
      assert heads_model.tolist()[0] == [0, 0, 1]
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/models/biaffine_dependency_parser_test.py
imports: from __future__ import division
  from __future__ import absolute_import
  import torch
  from allennlp.common.testing.model_test_case import ModelTestCase
  from allennlp.nn.decoding.chu_liu_edmonds import decode_mst
label_desc: Use image node_id 6 for calling the BiaffineDependencyParserTest obj's underlying member method code with example usage: obj.test_mst_respects_no_outgoing_root_edges_constraint() without return types