class_docstr: edge : b x N x K x C x C semimarkov potentials
docstr: Convert a sequence representation to edges
  
  Parameters:
      sequence : b x N  long tensors in [-1, 0, C-1]
      extra : number of states
      lengths: b long tensor of N values
  
  Returns:
      edge : b x (N-1) x K x C x C semimarkov potentials
                  (t x z_t x z_{t-1})
docstr_tok: ["Convert","a","sequence","representation","to","edges","Parameters",":","sequence",":","b","x","N","long","tensors","in","[","-1",",","0",",","C-1","]","extra",":","number","of","states","lengths",":","b","long","tensor","of","N","values","Returns",":","edge",":","b","x","(","N-1",")","x","K","x","C","x","C","semimarkov","potentials","(","t","x","z_t","x","z_","{","t-1","}",")"]
code: def to_parts(sequence, extra, lengths=None):
      """
      Convert a sequence representation to edges
  
      Parameters:
          sequence : b x N  long tensors in [-1, 0, C-1]
          extra : number of states
          lengths: b long tensor of N values
  
      Returns:
          edge : b x (N-1) x K x C x C semimarkov potentials
                      (t x z_t x z_{t-1})
      """
      C, K = extra
      batch, N = sequence.shape
      labels = torch.zeros(batch, N - 1, K, C, C).long()
      if lengths is None:
          lengths = torch.LongTensor([N] * batch)
  
      for b in range(batch):
          last = None
          c = None
          for n in range(0, N):
              if sequence[b, n] == -1:
                  assert n != 0
                  continue
              else:
                  new_c = sequence[b, n]
                  if n != 0:
                      labels[b, last, n - last, new_c, c] = 1
                  last = n
                  c = new_c
      return labels
  
file_path: pytorch-struct/torch_struct/semimarkov.py
imports: import torch
  from .helpers import _Struct
label_desc: Use image node_id 4 for calling the SemiMarkov obj's underlying member method code with example usage: obj.to_parts(sequence, extra, lengths) and returns: labels