class_docstr: This class calculates Viterbi alignments in the forward method.
  
  It also records alignments and creates batches of them for use
  in Viterbi training.
  
  Arguments
  ---------
  states_per_phoneme : int
      Number of hidden states to use per phoneme.
  output_folder : str
      It is the folder that the alignments will be stored in when
      saved to disk. Not yet implemented.
  neg_inf : float
      The float used to represent a negative infinite log probability.
      Using `-float("Inf")` tends to give numerical instability.
      A number more negative than -1e5 also sometimes gave errors when
      the `genbmm` library was used (currently not in use). (default: -1e5)
  batch_reduction : string
      One of "none", "sum" or "mean".
      What kind of batch-level reduction to apply to the loss calculated
      in the forward method.
  input_len_norm : bool
      Whether to normalize the loss in the forward method by the length of
      the inputs.
  target_len_norm : bool
      Whether to normalize the loss in the forward method by the length of
      the targets.
  lexicon_path : string
      The location of the lexicon.
  
  Example
  -------
  >>> log_posteriors = torch.tensor([[[ -1., -10., -10.],
  ...                                 [-10.,  -1., -10.],
  ...                                 [-10., -10.,  -1.]],
  ...
  ...                                [[ -1., -10., -10.],
  ...                                 [-10.,  -1., -10.],
  ...                                 [-10., -10., -10.]]])
  >>> lens = torch.tensor([1., 0.66])
  >>> phns = torch.tensor([[0, 1, 2],
  ...                      [0, 1, 0]])
  >>> phn_lens = torch.tensor([1., 0.66])
  >>> aligner = HMMAligner()
  >>> forward_scores = aligner(
  ...        log_posteriors, lens, phns, phn_lens, 'forward'
  ... )
  >>> forward_scores.shape
  torch.Size([2])
  >>> viterbi_scores, alignments = aligner(
  ...        log_posteriors, lens, phns, phn_lens, 'viterbi'
  ... )
  >>> alignments
  [[0, 1, 2], [0, 1]]
  >>> viterbi_scores.shape
  torch.Size([2])
docstr: Prepares flat start alignments (with zero padding) for every utterance
  in the batch.
  Every phoneme will have an equal duration, except for the final phoneme
  potentially. E.g. if 104 frames and 10 phonemes, 9 phonemes will have
  duration of 10 frames, and one phoneme will have a duration of 14 frames.
  
  Arguments
  ---------
  lens_abs : torch.Tensor (batch)
      The absolute length of each input to the acoustic model,
      i.e., the number of frames.
  
  phn_lens_abs : torch.Tensor (batch)
      The absolute length of each phoneme sequence in the batch.
  
  phns : torch.Tensor (batch, phoneme in phn sequence)
      The phonemes that are known/thought to be in each utterance.
  
  Returns
  -------
  flat_start_batch : torch.Tensor (batch, time)
      Flat start alignments for utterances in the batch, with zero padding.
docstr_tok: ["Prepares","flat","start","alignments","(","with","zero","padding",")","for","every","utterance","in","the","batch",".","Every","phoneme","will","have","an","equal","duration",",","except","for","the","final","phoneme","potentially",".","E.g",".","if","104","frames","and","10","phonemes",",","9","phonemes","will","have","duration","of","10","frames",",","and","one","phoneme","will","have","a","duration","of","14","frames",".","Arguments","--","--","--","--","-","lens_abs",":","torch.Tensor","(","batch",")","The","absolute","length","of","each","input","to","the","acoustic","model",",","i.e.",",","the","number","of","frames",".","phn_lens_abs",":","torch.Tensor","(","batch",")","The","absolute","length","of","each","phoneme","sequence","in","the","batch",".","phns",":","torch.Tensor","(","batch",",","phoneme","in","phn","sequence",")","The","phonemes","that","are","known\/thought","to","be","in","each","utterance",".","Returns","--","--","--","-","flat_start_batch",":","torch.Tensor","(","batch",",","time",")","Flat","start","alignments","for","utterances","in","the","batch",",","with","zero","padding","."]
code: def _get_flat_start_batch(self, lens_abs, phn_lens_abs, phns):
      """Prepares flat start alignments (with zero padding) for every utterance
      in the batch.
      Every phoneme will have an equal duration, except for the final phoneme
      potentially. E.g. if 104 frames and 10 phonemes, 9 phonemes will have
      duration of 10 frames, and one phoneme will have a duration of 14 frames.
  
      Arguments
      ---------
      lens_abs : torch.Tensor (batch)
          The absolute length of each input to the acoustic model,
          i.e., the number of frames.
  
      phn_lens_abs : torch.Tensor (batch)
          The absolute length of each phoneme sequence in the batch.
  
      phns : torch.Tensor (batch, phoneme in phn sequence)
          The phonemes that are known/thought to be in each utterance.
  
      Returns
      -------
      flat_start_batch : torch.Tensor (batch, time)
          Flat start alignments for utterances in the batch, with zero padding.
      """
      phns = phns.long()
  
      batch_size = len(lens_abs)
      fb_max_length = torch.max(lens_abs)
  
      flat_start_batch = torch.zeros(
          batch_size, fb_max_length, device=phns.device
      ).long()
      for i in range(batch_size):
          utter_phns = phns[i]
          utter_phns = utter_phns[
              : phn_lens_abs[i]
          ]  # crop out zero padding
          repeat_amt = int(lens_abs[i].item() / len(utter_phns))
  
          # make sure repeat_amt is at least 1. (the code above
          # may make repeat_amt==0 if self.states_per_phoneme is too large).
          if repeat_amt == 0:
              repeat_amt = 1
  
          # repeat each phoneme in utter_phns by repeat_amt
          utter_phns = utter_phns.repeat_interleave(repeat_amt)
  
          # len(utter_phns) may be <, == or > lens_abs[i], so
          # make sure len(utter_phns) == lens_abs[i]
          utter_phns = utter_phns[: lens_abs[i]]
          utter_phns = torch.nn.functional.pad(
              utter_phns,
              (0, int(lens_abs[i]) - len(utter_phns)),
              value=utter_phns[-1],  # pad out with final phoneme
          )
  
          flat_start_batch[i, : len(utter_phns)] = utter_phns
  
      return flat_start_batch
  
imports: import torch
  import random
  from speechbrain.utils.checkpoints import register_checkpoint_hooks
  from speechbrain.utils.checkpoints import mark_as_saver
  from speechbrain.utils.checkpoints import mark_as_loader
  from speechbrain.utils.data_utils import undo_padding
label_desc: Use image node_id 13 for calling the HMMAligner obj's underlying member method code with example usage: obj._get_flat_start_batch(lens_abs, phn_lens_abs, phns) and returns: flat_start_batch