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: inputs: batch_size x seq_len x num_tags
  masks: batch_size x seq_len
  tag_indices: batch_size x seq_len
  
  @return:
      loss: CRF negative log likelihood on all instances.
      transitions: the transition matrix
docstr_tok: ["inputs",":","batch_size","x","seq_len","x","num_tags","masks",":","batch_size","x","seq_len","tag_indices",":","batch_size","x","seq_len","@","return",":","loss",":","CRF","negative","log","likelihood","on","all","instances",".","transitions",":","the","transition","matrix"]
code: def forward(self, inputs, masks, tag_indices):
      """
      inputs: batch_size x seq_len x num_tags
      masks: batch_size x seq_len
      tag_indices: batch_size x seq_len
  
      @return:
          loss: CRF negative log likelihood on all instances.
          transitions: the transition matrix
      """
      # TODO: handle <start> and <end> tags
      input_bs, input_sl, input_nc = inputs.size()
      unary_scores = self.crf_unary_score(
          inputs, masks, tag_indices, input_bs, input_sl, input_nc
      )
      binary_scores = self.crf_binary_score(
          inputs, masks, tag_indices, input_bs, input_sl, input_nc
      )
      log_norm = self.crf_log_norm(inputs, masks, tag_indices)
      log_likelihood = (
          unary_scores + binary_scores - log_norm
      )  # batch_size
      loss = torch.sum(-log_likelihood)
      if self._batch_average:
          loss = loss / input_bs
      else:
          total = masks.eq(0).sum()
          loss = loss / (total + 1e-8)
      return loss, self._transitions
  
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 2 for calling the CRFLoss obj's underlying member method code with example usage: obj.forward(inputs, masks, tag_indices) and returns: loss,  self