code: def fastemit_regularization(
      log_probs, labels, alphas, betas, blank, fastemit_lambda
  ):
      """
      Describes the computation of FastEmit regularization from the paper -
      [FastEmit: Low-latency Streaming ASR with Sequence-level Emission Regularization](https://arxiv.org/abs/2010.11148)
  
      Args:
          log_probs: Tensor of shape [T, U, V+1]
          labels: Unused. Labels of shape [B, U]
          alphas: Tensor of shape [T, U] which represents the forward variable.
          betas: Unused. Tensor of shape [T, U] which represents the backward variable.
          blank: Index of the blank token.
          fastemit_lambda: Float scaling factor for FastEmit regularization.
  
      Returns:
          The regularized negative log likelihood - lambda * P˜(At, u|x)
      """
      # General calculation of the fastemit regularization alignments
      T, U, _ = log_probs.shape
      # alignment = np.zeros((T, U), dtype='float32')
      #
      # for t in range(0, T):
      #     alignment[t, U - 1] = alphas[t, U - 1] + betas[t, U - 1]
      #
      # for t in range(0, T):
      #     for u in range(0, U - 1):
      #         emit = alphas[t, u] + log_probs[t, u, labels[u]] + betas[t, u + 1]
      #         alignment[t, u] = emit
      # reg = fastemit_lambda * (alignment[T - 1, U - 1])
  
      # The above is equivalent to below, without need of computing above
      # reg = fastemit_lambda * (alphas[T - 1, U - 1] + betas[T - 1, U - 1])
  
      # The above is also equivalent to below, without need of computing the betas alignment matrix
      reg = fastemit_lambda * (
          alphas[T - 1, U - 1] + log_probs[T - 1, U - 1, blank]
      )
      return -reg
  
imports: import numpy
  import torch
  from torch.autograd import Function, Variable
  from torch.nn import Module
label_desc: Use image node_id 9 for calling a global function with example usage: fastemit_regularization(log_probs, labels, alphas, betas, blank, fastemit_lambda) and returns: unknown