code: def sparse_multinomial_likelihood(
      total_count, nonzero_logits, nonzero_value
  ):
      """
      The following are equivalent::
  
          # Version 1. dense
          log_prob = Multinomial(logits=logits).log_prob(value).sum()
  
          # Version 2. sparse
          nnz = value.nonzero(as_tuple=True)
          log_prob = sparse_multinomial_likelihood(
              value.sum(-1),
              (logits - logits.logsumexp(-1))[nnz],
              value[nnz],
          )
      """
      return (
          _log_factorial_sum(total_count)
          - _log_factorial_sum(nonzero_value)
          + torch.dot(nonzero_logits, nonzero_value)
      )
  
file_path: pyro/pyro/ops/special.py
imports: import functools
  import math
  import operator
  import weakref
  from typing import Dict
  import numpy
  import torch
  from numpy.polynomial.hermite import hermgauss
label_desc: Use image node_id 6 for calling a global function with example usage: sparse_multinomial_likelihood(total_count, nonzero_logits, nonzero_value) and returns: unknown