class_docstr: Represents structured linear-chain CRFs, generalizing HMMs smoothing, tagging models,
  and anything with chain-like dynamics.
docstr: Convert HMM log-probs to a linear chain.
  
  Parameters:
      transition: C X C
      emission: V x C
      init: C
      observations: b x N between [0, V-1]
  
  Returns:
      edges: b x (N-1) x C x C
docstr_tok: ["Convert","HMM","log-probs","to","a","linear","chain",".","Parameters",":","transition",":","C","X","C","emission",":","V","x","C","init",":","C","observations",":","b","x","N","between","[","0",",","V-1","]","Returns",":","edges",":","b","x","(","N-1",")","x","C","x","C"]
code: def hmm(transition, emission, init, observations):
      """
      Convert HMM log-probs to a linear chain.
  
      Parameters:
          transition: C X C
          emission: V x C
          init: C
          observations: b x N between [0, V-1]
  
      Returns:
          edges: b x (N-1) x C x C
      """
      V, C = emission.shape
      batch, N = observations.shape
      scores = torch.zeros(batch, N - 1, C, C).type_as(emission)
      scores[:, :, :, :] += transition.view(1, 1, C, C)
      scores[:, 0, :, :] += init.view(1, 1, C)
      obs = emission[observations.view(batch * N), :]
      scores[:, :, :, :] += obs.view(batch, N, C, 1)[:, 1:]
      scores[:, 0, :, :] += obs.view(batch, N, 1, C)[:, 0]
      return scores
  
file_path: pytorch-struct/torch_struct/linearchain.py
imports: import torch
  from .helpers import _Struct
label_desc: Use image node_id 5 for calling the LinearChain obj's underlying member method code with example usage: obj.hmm(transition, emission, init, observations) and returns: scores