code: def test_doesnt_predict_eos_if_shorter_than_min_len(self):
      # batch 0 will always predict EOS. The other batches will predict
      # non-eos scores.
      for batch_sz in [1, 3]:
          n_words = 100
          _non_eos_idxs = [47]
          valid_score_dist = torch.log_softmax(
              torch.tensor([6.0, 5.0]), dim=0
          )
          min_length = 5
          eos_idx = 2
          lengths = torch.randint(0, 30, (batch_sz,))
          samp = GreedySearch(
              0,
              1,
              2,
              3,
              1,
              1,
              batch_sz,
              GlobalScorerStub(),
              min_length,
              False,
              set(),
              False,
              30,
              1.0,
              1,
              0,
              1,
              False,
          )
          samp.initialize(torch.zeros((1, 1)), lengths)
          all_attns = []
          for i in range(min_length + 4):
              word_probs = torch.full(
                  (batch_sz, n_words), -float("inf")
              )
              # "best" prediction is eos - that should be blocked
              word_probs[0, eos_idx] = valid_score_dist[0]
              # include at least one prediction OTHER than EOS
              # that is greater than -1e20
              word_probs[0, _non_eos_idxs[0]] = valid_score_dist[1]
              word_probs[1:, _non_eos_idxs[0] + i] = 0
  
              attns = torch.randn(1, batch_sz, 53)
              all_attns.append(attns)
              samp.advance(word_probs, attns)
              if i < min_length:
                  self.assertTrue(
                      samp.topk_scores[0].allclose(valid_score_dist[1])
                  )
                  self.assertTrue(samp.topk_scores[1:].eq(0).all())
              elif i == min_length:
                  # now batch 0 has ended and no others have
                  self.assertTrue(all(samp.is_finished_list[0][:]))
                  self.assertTrue(
                      all(
                          all([not x for x in sublist])
                          for sublist in samp.is_finished_list[1:][1:]
                      )
                  )
              else:  # i > min_length
                  break
  
file_path: OpenNMT-py/onmt/tests/test_greedy_search.py
imports: import unittest
  from onmt.translate.greedy_search import GreedySearch
  import torch
label_desc: Use image node_id 1 for calling the TestGreedySearch obj's underlying member method code with example usage: obj.test_doesnt_predict_eos_if_shorter_than_min_len() without return types