code: def setUp(self):
      super(TestExpectedRiskMinimization, self).setUp()
      self.initial_state = SimpleDecoderState(
          [0], [[0]], [torch.Tensor([0.0])]
      )
      self.decoder_step = SimpleDecoderStep()
      # Cost is the number of odd elements in the action history.
      self.supervision = lambda state: torch.Tensor(
          [sum([x % 2 != 0 for x in state.action_history[0]])]
      )
      # High beam size ensures exhaustive search.
      self.trainer = ExpectedRiskMinimization(
          beam_size=100,
          normalize_by_length=False,
          max_decoding_steps=10,
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/nn/decoding/decoder_trainers/expected_risk_minimization_test.py
imports: from __future__ import division
  from __future__ import absolute_import
  import torch
  import numpy
  from numpy.testing import assert_almost_equal
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.nn.decoding.decoder_trainers import ExpectedRiskMinimization
  from ..simple_transition_system import SimpleDecoderState, SimpleDecoderStep
label_desc: Use image node_id 1 for calling the TestExpectedRiskMinimization obj's underlying member method code with example usage: obj.setUp() without return types