class_docstr: Speech-to-text alignment model (https://arxiv.org/pdf/2108.10447.pdf) that is used to learn alignments between mel spectrogram and text.
class_docstr_tok: ["Speech-to-text","alignment","model","(","https",":","\/\/arxiv.org\/pdf\/2108.10447.pdf",")","that","is","used","to","learn","alignments","between","mel","spectrogram","and","text","."]
code: def _metrics(self, attn_soft, attn_logprob, spec_len, text_len):
      loss, bin_loss, attn_hard = 0.0, None, None
  
      forward_sum_loss = self.forward_sum_loss(
          attn_logprob=attn_logprob, in_lens=text_len, out_lens=spec_len
      )
      loss += forward_sum_loss
  
      if self.add_bin_loss:
          attn_hard = binarize_attention(attn_soft, text_len, spec_len)
          bin_loss = self.bin_loss(
              hard_attention=attn_hard, soft_attention=attn_soft
          )
          loss += bin_loss
  
      return loss, forward_sum_loss, bin_loss, attn_hard
  
imports: from typing import List
  import numpy
  import omegaconf
  import torch
  from hydra.utils import instantiate
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from pytorch_lightning.loggers import WandbLogger
  from torch import nn
  from nemo.collections.tts.losses.aligner_loss import BinLoss, ForwardSumLoss
  from nemo.collections.tts.parts.utils.helpers import binarize_attention, g2p_backward_compatible_support, get_mask_from_lengths, plot_alignment_to_numpy
  from nemo.core.classes import ModelPT
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 5 for calling the AlignerModel obj's underlying member method code with example usage: obj._metrics(attn_soft, attn_logprob, spec_len, text_len) and returns: loss,  forward_sum_loss,  bin_loss,  attn_hard