class_docstr: Autoregressive left to right HMM model primarily used in "Neural HMMs are all you need (for high-quality attention-free TTS)"
  
  Paper::
      https://arxiv.org/abs/2108.13320
  
  Paper abstract::
      Neural sequence-to-sequence TTS has achieved significantly better output quality than statistical speech synthesis using
      HMMs. However, neural TTS is generally not probabilistic and uses non-monotonic attention. Attention failures increase
      training time and can make synthesis babble incoherently. This paper describes how the old and new paradigms can be
      combined to obtain the advantages of both worlds, by replacing attention in neural TTS with an autoregressive left-right
      no-skip hidden Markov model defined by a neural network. Based on this proposal, we modify Tacotron 2 to obtain an
      HMM-based neural TTS model with monotonic alignment, trained to maximise the full sequence likelihood without
      approximation. We also describe how to combine ideas from classical and contemporary TTS for best results. The resulting
      example system is smaller and simpler than Tacotron 2, and learns to speak with fewer iterations and less data, whilst
      achieving comparable naturalness prior to the post-net. Our approach also allows easy control over speaking rate.
  
  Args:
      frame_channels (int): Output dimension to generate.
      ar_order (int): Autoregressive order of the model. In ablations of Neural HMM it was found that more autoregression while giving more variation hurts naturalness of the synthesised audio.
      deterministic_transition (bool): deterministic duration generation based on duration quantiles as defiend in "S. Ronanki, O. Watts, S. King, and G. E. Henter, “Medianbased generation of synthetic speech durations using a nonparametric approach,” in Proc. SLT, 2016.". Defaults to True.
      encoder_dim (int): Channels of encoder input and character embedding tensors. Defaults to 512.
      prenet_type (str): `original` or `bn`. `original` sets the default Prenet and `bn` uses Batch Normalization version of the Prenet.
      prenet_dim (int): Dimension of the Prenet.
      prenet_n_layers (int): Number of layers in the Prenet.
      prenet_dropout (float): Dropout probability of the Prenet.
      prenet_dropout_at_inference (bool): If True, dropout is applied at inference time.
      memory_rnn_dim (int): Size of the memory RNN to process output of prenet.
      outputnet_size (List[int]): Size of the output network inside the neural HMM.
      flat_start_params (dict): Parameters for the flat start initialization of the neural HMM.
      std_floor (float): Floor value for the standard deviation of the neural HMM. Prevents model cheating by putting point mass and getting infinite likelihood at any datapoint.
      use_grad_checkpointing (bool, optional): Use gradient checkpointing to save memory. Defaults to True.
class_docstr_tok: ["Autoregressive","left","to","right","HMM","model","primarily","used","in","``","Neural","HMMs","are","all","you","need","(","for","high-quality","attention-free","TTS",")","''","Paper",":",":","https",":","\/\/arxiv.org\/abs\/2108.13320","Paper","abstract",":",":","Neural","sequence-to-sequence","TTS","has","achieved","significantly","better","output","quality","than","statistical","speech","synthesis","using","HMMs",".","However",",","neural","TTS","is","generally","not","probabilistic","and","uses","non-monotonic","attention",".","Attention","failures","increase","training","time","and","can","make","synthesis","babble","incoherently",".","This","paper","describes","how","the","old","and","new","paradigms","can","be","combined","to","obtain","the","advantages","of","both","worlds",",","by","replacing","attention","in","neural","TTS","with","an","autoregressive","left-right","no-skip","hidden","Markov","model","defined","by","a","neural","network",".","Based","on","this","proposal",",","we","modify","Tacotron","2","to","obtain","an","HMM-based","neural","TTS","model","with","monotonic","alignment",",","trained","to","maximise","the","full","sequence","likelihood","without","approximation",".","We","also","describe","how","to","combine","ideas","from","classical","and","contemporary","TTS","for","best","results",".","The","resulting","example","system","is","smaller","and","simpler","than","Tacotron","2",",","and","learns","to","speak","with","fewer","iterations","and","less","data",",","whilst","achieving","comparable","naturalness","prior","to","the","post-net",".","Our","approach","also","allows","easy","control","over","speaking","rate",".","Args",":","frame_channels","(","int",")",":","Output","dimension","to","generate",".","ar_order","(","int",")",":","Autoregressive","order","of","the","model",".","In","ablations","of","Neural","HMM","it","was","found","that","more","autoregression","while","giving","more","variation","hurts","naturalness","of","the","synthesised","audio",".","deterministic_transition","(","bool",")",":","deterministic","duration","generation","based","on","duration","quantiles","as","defiend","in","``","S.","Ronanki",",","O.","Watts",",","S.","King",",","and","G.","E.","Henter",",","\u201c","Medianbased","generation","of","synthetic","speech","durations","using","a","nonparametric","approach",",","\u201d","in","Proc",".","SLT",",","2016.","''",".","Defaults","to","True",".","encoder_dim","(","int",")",":","Channels","of","encoder","input","and","character","embedding","tensors",".","Defaults","to","512.","prenet_type","(","str",")",":","`","original","`","or","`","bn","`",".","`","original","`","sets","the","default","Prenet","and","`","bn","`","uses","Batch","Normalization","version","of","the","Prenet",".","prenet_dim","(","int",")",":","Dimension","of","the","Prenet",".","prenet_n_layers","(","int",")",":","Number","of","layers","in","the","Prenet",".","prenet_dropout","(","float",")",":","Dropout","probability","of","the","Prenet",".","prenet_dropout_at_inference","(","bool",")",":","If","True",",","dropout","is","applied","at","inference","time",".","memory_rnn_dim","(","int",")",":","Size","of","the","memory","RNN","to","process","output","of","prenet",".","outputnet_size","(","List","[","int","]",")",":","Size","of","the","output","network","inside","the","neural","HMM",".","flat_start_params","(","dict",")",":","Parameters","for","the","flat","start","initialization","of","the","neural","HMM",".","std_floor","(","float",")",":","Floor","value","for","the","standard","deviation","of","the","neural","HMM",".","Prevents","model","cheating","by","putting","point","mass","and","getting","infinite","likelihood","at","any","datapoint",".","use_grad_checkpointing","(","bool",",","optional",")",":","Use","gradient","checkpointing","to","save","memory",".","Defaults","to","True","."]
docstr: Process autoregression in timestep
  1. At a specific t timestep
  2. Perform data dropout if applied (we did not use it)
  3. Run the autoregressive frame through the prenet (has dropout)
  4. Run the prenet output through the post prenet rnn
  
  Args:
      t (int): mel-spec timestep
      ar_inputs (torch.FloatTensor): go-token appended mel-spectrograms
          - shape: (b, D_out, T_out)
      h_post_prenet (torch.FloatTensor): previous timestep rnn hidden state
          - shape: (b, memory_rnn_dim)
      c_post_prenet (torch.FloatTensor): previous timestep rnn cell state
          - shape: (b, memory_rnn_dim)
  
  Returns:
      h_post_prenet (torch.FloatTensor): rnn hidden state of the current timestep
      c_post_prenet (torch.FloatTensor): rnn cell state of the current timestep
docstr_tok: ["Process","autoregression","in","timestep","1",".","At","a","specific","t","timestep","2",".","Perform","data","dropout","if","applied","(","we","did","not","use","it",")","3",".","Run","the","autoregressive","frame","through","the","prenet","(","has","dropout",")","4",".","Run","the","prenet","output","through","the","post","prenet","rnn","Args",":","t","(","int",")",":","mel-spec","timestep","ar_inputs","(","torch.FloatTensor",")",":","go-token","appended","mel-spectrograms","-","shape",":","(","b",",","D_out",",","T_out",")","h_post_prenet","(","torch.FloatTensor",")",":","previous","timestep","rnn","hidden","state","-","shape",":","(","b",",","memory_rnn_dim",")","c_post_prenet","(","torch.FloatTensor",")",":","previous","timestep","rnn","cell","state","-","shape",":","(","b",",","memory_rnn_dim",")","Returns",":","h_post_prenet","(","torch.FloatTensor",")",":","rnn","hidden","state","of","the","current","timestep","c_post_prenet","(","torch.FloatTensor",")",":","rnn","cell","state","of","the","current","timestep"]
code: def _process_ar_timestep(
      self,
      t,
      ar_inputs,
      h_memory,
      c_memory,
  ):
      """
      Process autoregression in timestep
      1. At a specific t timestep
      2. Perform data dropout if applied (we did not use it)
      3. Run the autoregressive frame through the prenet (has dropout)
      4. Run the prenet output through the post prenet rnn
  
      Args:
          t (int): mel-spec timestep
          ar_inputs (torch.FloatTensor): go-token appended mel-spectrograms
              - shape: (b, D_out, T_out)
          h_post_prenet (torch.FloatTensor): previous timestep rnn hidden state
              - shape: (b, memory_rnn_dim)
          c_post_prenet (torch.FloatTensor): previous timestep rnn cell state
              - shape: (b, memory_rnn_dim)
  
      Returns:
          h_post_prenet (torch.FloatTensor): rnn hidden state of the current timestep
          c_post_prenet (torch.FloatTensor): rnn cell state of the current timestep
      """
      prenet_input = ar_inputs[:, t : t + self.ar_order].flatten(1)
      memory_inputs = self.prenet(prenet_input)
      h_memory, c_memory = self.memory_rnn(
          memory_inputs, (h_memory, c_memory)
      )
      return h_memory, c_memory
  
imports: from typing import List
  import torch
  import torch.distributions
  import torch.nn.functional
  from torch import nn
  from torch.utils.checkpoint import checkpoint
  from TTS.tts.layers.overflow.common_layers import Outputnet, OverflowUtils
  from TTS.tts.layers.tacotron.common_layers import Prenet
  from TTS.tts.utils.helpers import sequence_mask
label_desc: Use image node_id 4 for calling the NeuralHMM obj's underlying member method code with example usage: obj._process_ar_timestep(t, ar_inputs, h_memory, c_memory) and returns: h_memory,  c_memory