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","."]
docstr: Convert a sequence representation to arcs
  
  Parameters:
      sequence : b x N long tensor in [0, N] (indexing is +1)
      extra : None
      lengths : lengths of sequences
  
  Returns:
      arcs : b x N x N arc indicators
docstr_tok: ["Convert","a","sequence","representation","to","arcs","Parameters",":","sequence",":","b","x","N","long","tensor","in","[","0",",","N","]","(","indexing","is","+1",")","extra",":","None","lengths",":","lengths","of","sequences","Returns",":","arcs",":","b","x","N","x","N","arc","indicators"]
code: def to_parts(sequence, extra=None, lengths=None):
      """
      Convert a sequence representation to arcs
  
      Parameters:
          sequence : b x N long tensor in [0, N] (indexing is +1)
          extra : None
          lengths : lengths of sequences
  
      Returns:
          arcs : b x N x N arc indicators
      """
      batch, N = sequence.shape
      if lengths is None:
          lengths = torch.LongTensor([N] * batch)
      labels = torch.zeros(batch, N + 1, N + 1).long()
      for n in range(1, N + 1):
          labels[torch.arange(batch), sequence[:, n - 1], n] = 1
      for b in range(batch):
          labels[b, lengths[b] + 1 :, :] = 0
          labels[b, :, lengths[b] + 1 :] = 0
      return unconvert(labels)
  
file_path: pytorch-struct/torch_struct/deptree.py
imports: import torch
  from .helpers import _Struct, Chart
label_desc: Use image node_id 4 for calling the DepTree obj's underlying member method code with example usage: obj.to_parts(sequence, extra, lengths) and returns: unconvert