code: def mas(attn_map, width=1):
      # assumes mel x text
      opt = np.zeros_like(attn_map)
      attn_map = np.log(attn_map)
      attn_map[0, 1:] = -np.inf
      log_p = np.zeros_like(attn_map)
      log_p[0, :] = attn_map[0, :]
      prev_ind = np.zeros_like(attn_map, dtype=np.int64)
      for i in range(1, attn_map.shape[0]):
          for j in range(attn_map.shape[1]):  # for each text dim
              prev_j = np.arange(max(0, j - width), j + 1)
              prev_log = np.array(
                  [log_p[i - 1, prev_idx] for prev_idx in prev_j]
              )
  
              ind = np.argmax(prev_log)
              log_p[i, j] = attn_map[i, j] + prev_log[ind]
              prev_ind[i, j] = prev_j[ind]
  
      # now backtrack
      curr_text_idx = attn_map.shape[1] - 1
      for i in range(attn_map.shape[0] - 1, -1, -1):
          opt[i, curr_text_idx] = 1
          curr_text_idx = prev_ind[i, curr_text_idx]
      opt[0, curr_text_idx] = 1
  
      assert opt.sum(0).all()
      assert opt.sum(1).all()
  
      return opt
  
imports: from enum import Enum
  from typing import Optional, Tuple
  import librosa
  import matplotlib.pylab
  import numpy
  import torch
  from einops import rearrange
  from numba import jit, prange
  from nemo.collections.tts.torch.tts_data_types import DATA_STR2DATA_CLASS, MAIN_DATA_TYPES, WithLens
  from nemo.utils import logging
  from nemo.utils.decorators import deprecated
label_desc: Use image node_id 8 for calling a global function with example usage: mas(attn_map, width) and returns: opt