code: def test_batchfy_hyp():
      vocab_size = 5
      eos = -1
      # simplest beam search
      beam = BatchBeamSearch(
          beam_size=3,
          vocab_size=vocab_size,
          weights={"a": 0.5, "b": 0.5},
          scorers={
              "a": LengthBonus(vocab_size),
              "b": LengthBonus(vocab_size),
          },
          pre_beam_score_key="a",
          sos=eos,
          eos=eos,
      )
      hs = [
          Hypothesis(
              yseq=torch.tensor([0, 1, 2]),
              score=torch.tensor(0.15),
              scores={"a": torch.tensor(0.1), "b": torch.tensor(0.2)},
              states={"a": 1, "b": 2},
          ),
          Hypothesis(
              yseq=torch.tensor([0, 1]),
              score=torch.tensor(0.1),
              scores={"a": torch.tensor(0.0), "b": torch.tensor(0.2)},
              states={"a": 3, "b": 4},
          ),
      ]
      bs = beam.batchfy(hs)
      assert torch.all(
          bs.yseq == torch.tensor([[0, 1, 2], [0, 1, eos]])
      )
      assert torch.all(bs.score == torch.tensor([0.15, 0.1]))
      assert torch.all(bs.scores["a"] == torch.tensor([0.1, 0.0]))
      assert torch.all(bs.scores["b"] == torch.tensor([0.2, 0.2]))
      assert bs.states["a"] == [1, 3]
      assert bs.states["b"] == [2, 4]
  
      us = beam.unbatchfy(bs)
      for i in range(len(hs)):
          assert us[i].yseq.tolist() == hs[i].yseq.tolist()
          assert us[i].score == hs[i].score
          assert us[i].scores == hs[i].scores
          assert us[i].states == hs[i].states
  
file_path: espnet/test/test_batch_beam_search.py
imports: import os
  from argparse import Namespace
  from test.test_beam_search import prepare, transformer_args
  import numpy
  import pytest
  import torch
  from espnet.nets.batch_beam_search import BatchBeamSearch, BeamSearch
  from espnet.nets.beam_search import Hypothesis
  from espnet.nets.lm_interface import dynamic_import_lm
  from espnet.nets.scorers.length_bonus import LengthBonus
  from espnet.nets.scorers.ngram import NgramFullScorer
label_desc: Use image node_id 1 for calling a global function with example usage: test_batchfy_hyp() without return types