code: def test_convert_to_hypotheses_with_alignments(
      self, device: torch.device
  ):
      batch_size = 2
      logits_dim = 7
      blank_index = 6
      hyps = BatchedHyps(
          batch_size=batch_size, init_length=1, device=device
      )
      alignments = BatchedAlignments(
          batch_size=batch_size,
          init_length=1,
          logits_dim=logits_dim,
          device=device,
      )
      sample_logits = torch.rand(
          (batch_size, 4, logits_dim), device=device
      )
      # sequence 0: [[5, blank], [2, blank]] -> [5, 2]
      # sequence 1: [[blank   ], [4, blank]] -> [4]
  
      # frame 0
      hyps.add_results_(
          active_indices=torch.tensor([0], device=device),
          labels=torch.tensor([5], device=device),
          time_indices=torch.tensor([0], device=device),
          scores=torch.tensor([0.5], device=device),
      )
      alignments.add_results_(
          active_indices=torch.arange(batch_size, device=device),
          logits=sample_logits[:, 0],
          labels=torch.tensor([5, blank_index], device=device),
          time_indices=torch.tensor([0, 0], device=device),
      )
      alignments.add_results_(
          active_indices=torch.tensor([0], device=device),
          logits=sample_logits[:1, 1],
          labels=torch.tensor([blank_index], device=device),
          time_indices=torch.tensor([0], device=device),
      )
  
      # frame 1
      hyps.add_results_(
          active_indices=torch.arange(batch_size, device=device),
          labels=torch.tensor([2, 4], device=device),
          time_indices=torch.tensor([1, 1], device=device),
          scores=torch.tensor([1.0, 1.0], device=device),
      )
      alignments.add_results_(
          active_indices=torch.arange(batch_size, device=device),
          logits=sample_logits[:, 2],
          labels=torch.tensor([2, 4], device=device),
          time_indices=torch.tensor([1, 1], device=device),
      )
      alignments.add_results_(
          active_indices=torch.arange(batch_size, device=device),
          logits=sample_logits[:, 3],
          labels=torch.tensor(
              [blank_index, blank_index], device=device
          ),
          time_indices=torch.tensor([1, 1], device=device),
      )
  
      hypotheses = batched_hyps_to_hypotheses(hyps, alignments)
      assert (
          hypotheses[0].y_sequence
          == torch.tensor([5, 2], device=device)
      ).all()
      assert (
          hypotheses[1].y_sequence == torch.tensor([4], device=device)
      ).all()
      assert hypotheses[0].score == pytest.approx(1.5)
      assert hypotheses[1].score == pytest.approx(1.0)
      assert (
          hypotheses[0].timestep == torch.tensor([0, 1], device=device)
      ).all()
      assert (
          hypotheses[1].timestep == torch.tensor([1], device=device)
      ).all()
  
      etalon = [
          [
              [
                  (torch.tensor(5), sample_logits[0, 0].cpu()),
                  (
                      torch.tensor(blank_index),
                      sample_logits[0, 1].cpu(),
                  ),
              ],
              [
                  (torch.tensor(2), sample_logits[0, 2].cpu()),
                  (
                      torch.tensor(blank_index),
                      sample_logits[0, 3].cpu(),
                  ),
              ],
          ],
          [
              [(torch.tensor(blank_index), sample_logits[1, 0].cpu())],
              [
                  (torch.tensor(4), sample_logits[1, 2].cpu()),
                  (
                      torch.tensor(blank_index),
                      sample_logits[1, 3].cpu(),
                  ),
              ],
          ],
      ]
      for batch_i in range(batch_size):
          for t, group_for_timestep in enumerate(etalon[batch_i]):
              for step, (label, current_logits) in enumerate(
                  group_for_timestep
              ):
                  assert torch.allclose(
                      hypotheses[batch_i].alignments[t][step][0],
                      current_logits,
                  )
                  assert (
                      hypotheses[batch_i].alignments[t][step][1]
                      == label
                  )
  
imports: from typing import List
  import pytest
  import torch
  from nemo.collections.asr.parts.utils.rnnt_utils import BatchedAlignments, BatchedHyps, batched_hyps_to_hypotheses
label_desc: Use image node_id 2 for calling the TestConvertToHypotheses obj's underlying member method code with example usage: obj.test_convert_to_hypotheses_with_alignments(device) without return types