class_docstr: A projective dependency CRF.
  
  Parameters:
      arc_scores_in: Arc scores of shape (B, N, N) or (B, N, N, L) with root scores on
      diagonal.
  
  Note: For single-root case, do not set cache=True for now.
class_docstr_tok: ["A","projective","dependency","CRF",".","Parameters",":","arc_scores_in",":","Arc","scores","of","shape","(","B",",","N",",","N",")","or","(","B",",","N",",","N",",","L",")","with","root","scores","on","diagonal",".","Note",":","For","single-root","case",",","do","not","set","cache=True","for","now","."]
code: def logpartition(self, arc_scores_in, lengths=None, force_grad=False):
      multiroot = getattr(self, "multiroot", True)
      if arc_scores_in.dim() not in (3, 4):
          raise ValueError(
              "potentials must have dim of 3 (unlabeled) or 4 (labeled)"
          )
  
      labeled = arc_scores_in.dim() == 4
      semiring = self.semiring
      arc_scores_in = convert(arc_scores_in)
      arc_scores_in, batch, N, lengths = self._check_potentials(
          arc_scores_in, lengths
      )
      arc_scores_in.requires_grad_(True)
      arc_scores = (
          semiring.sum(arc_scores_in) if labeled else arc_scores_in
      )
      alpha = [
          [
              [
                  Chart((batch, N, N), arc_scores, semiring)
                  for _ in range(2)
              ]
              for _ in range(2)
          ]
          for _ in range(2)
      ]
      mask = torch.zeros(alpha[A][C][L].data.shape).bool()
      mask[:, :, :, 0].fill_(True)
      alpha[A][C][L].data[:] = semiring.fill(
          alpha[A][C][L].data[:], mask, semiring.one
      )
      alpha[A][C][R].data[:] = semiring.fill(
          alpha[A][C][R].data[:], mask, semiring.one
      )
      mask = torch.zeros(alpha[B][C][L].data[:].shape).bool()
      mask[:, :, :, -1].fill_(True)
      alpha[B][C][L].data[:] = semiring.fill(
          alpha[B][C][L].data[:], mask, semiring.one
      )
      alpha[B][C][R].data[:] = semiring.fill(
          alpha[B][C][R].data[:], mask, semiring.one
      )
  
      if multiroot:
          start_idx = 0
      else:
          start_idx = 1
  
      for k in range(1, N - start_idx):
          f = torch.arange(start_idx, N - k), torch.arange(
              k + start_idx, N
          )
          ACL = alpha[A][C][L][start_idx : N - k, :k]
          ACR = alpha[A][C][R][start_idx : N - k, :k]
          BCL = alpha[B][C][L][k + start_idx :, N - k :]
          BCR = alpha[B][C][R][k + start_idx :, N - k :]
          x = semiring.dot(ACR, BCL)
          arcs_l = semiring.times(x, arc_scores[:, :, f[1], f[0]])
          alpha[A][I][L][start_idx : N - k, k] = arcs_l
          alpha[B][I][L][k + start_idx : N, N - k - 1] = arcs_l
          arcs_r = semiring.times(x, arc_scores[:, :, f[0], f[1]])
          alpha[A][I][R][start_idx : N - k, k] = arcs_r
          alpha[B][I][R][k + start_idx : N, N - k - 1] = arcs_r
          AIR = alpha[A][I][R][start_idx : N - k, 1 : k + 1]
          BIL = alpha[B][I][L][k + start_idx :, N - k - 1 : N - 1]
          new = semiring.dot(ACL, BIL)
          alpha[A][C][L][start_idx : N - k, k] = new
          alpha[B][C][L][k + start_idx : N, N - k - 1] = new
          new = semiring.dot(AIR, BCR)
          alpha[A][C][R][start_idx : N - k, k] = new
          alpha[B][C][R][k + start_idx : N, N - k - 1] = new
  
      if not multiroot:
          root_incomplete_span = semiring.times(
              alpha[A][C][L][1, : N - 1], arc_scores[:, :, 0, 1:]
          )
          for k in range(1, N):
              AIR = root_incomplete_span[:, :, :k]
              BCR = alpha[B][C][R][k, N - k :]
              alpha[A][C][R][0, k] = semiring.dot(AIR, BCR)
  
      final = alpha[A][C][R][(0,)]
      v = torch.stack(
          [final[:, i, l] for i, l in enumerate(lengths)], dim=1
      )
      return v, [arc_scores_in]
  
file_path: pytorch-struct/torch_struct/deptree.py
imports: import torch
  from .helpers import _Struct, Chart
label_desc: Use image node_id 1 for calling the DepTree obj's underlying member method code with example usage: obj.logpartition(arc_scores_in, lengths, force_grad) and returns: v,  list