class_docstr: Implements an entropy expectation semiring.
  
  Computes both the log-values and the running distributional entropy.
  
  Based on descriptions in:
  
  * Parameter estimation for probabilistic finite-state transducers :cite:`eisner2002parameter`
  * First-and second-order expectation semirings with applications to minimum-risk training on translation forests :cite:`li2009first`
  * Sample Selection for Statistical Grammar Induction :cite:`hwa2000samplesf`
code: def sum(xs, dim=-1):
      assert dim != 0
      d = dim - 1 if dim > 0 else dim
      part = torch.logsumexp(xs[0], dim=d)
      log_sm = xs[0] - part.unsqueeze(d)
      sm = log_sm.exp()
      return torch.stack(
          (part, torch.sum(xs[1].mul(sm) - log_sm.mul(sm), dim=d))
      )
  
imports: import torch
label_desc: Use image node_id 4 for calling the EntropySemiring obj's underlying member method code with example usage: obj.sum(xs, dim) and returns: torch