code: def test_entropy(model_test, data):
      "Test entropy by manual enumeration"
      gen = Gen(model_test, data, EntropySemiring)
      alpha = gen.struct.sum(gen.vals)
      log_z = gen.model(LogSemiring).sum(gen.vals)
  
      log_probs = gen.enum(LogSemiring)[1]
      log_probs = torch.stack(log_probs, dim=1) - log_z
      entropy = -log_probs.mul(log_probs.exp()).sum(1).squeeze(0)
      assert entropy.shape == alpha.shape
      assert torch.isclose(entropy, alpha).all()
  
imports: from torch_struct import CKY, CKY_CRF, DepTree, LinearChain, SemiMarkov, Alignment, deptree_nonproj, deptree_part
  from torch_struct import LogSemiring, CheckpointSemiring, CheckpointShardSemiring, KMaxSemiring, SparseMaxSemiring, MaxSemiring, StdSemiring, EntropySemiring
  from .extensions import LinearChainTest, SemiMarkovTest, DepTreeTest, CKYTest, CKY_CRFTest, test_lookup
  import torch
  from hypothesis import given
  from hypothesis.strategies import integers, data, sampled_from
  import pytest
  from hypothesis import settings
label_desc: Use image node_id 3 for calling a global function with example usage: test_entropy(model_test, data) without return types