class_docstr: Calculate log-space crf loss, given unary potentials, a transition matrix
  and gold tag sequences.
class_docstr_tok: ["Calculate","log-space","crf","loss",",","given","unary","potentials",",","a","transition","matrix","and","gold","tag","sequences","."]
docstr: @return:
      binary_scores: batch_size
docstr_tok: ["@","return",":","binary_scores",":","batch_size"]
code: def crf_binary_score(
      self, inputs, masks, tag_indices, input_bs, input_sl, input_nc
  ):
      """
      @return:
          binary_scores: batch_size
      """
      # get number of transitions
      nt = tag_indices.size(-1) - 1
      start_indices = tag_indices[:, :nt]
      end_indices = tag_indices[:, 1:]
      # flat matrices
      flat_transition_indices = start_indices * input_nc + end_indices
      flat_transition_indices = flat_transition_indices.view(-1)
      flat_transition_matrix = self._transitions.view(-1)
      binary_scores = torch.gather(
          flat_transition_matrix, 0, flat_transition_indices
      ).view(input_bs, -1)
      score_masks = masks[:, 1:]
      binary_scores.masked_fill_(score_masks, 0)
      return binary_scores.sum(dim=1)
  
file_path: stanza/stanza/models/common/crf.py
imports: import math
  from numbers import Number
  import numpy
  import torch
  from torch import nn
  import torch.nn.init
label_desc: Use image node_id 4 for calling the CRFLoss obj's underlying member method code with example usage: obj.crf_binary_score(inputs, masks, tag_indices, input_bs, input_sl, input_nc) and returns: binary_scores