
from typing import Any




def 	A_ (							snake_case							:   list ,      snake_case							:   list ,      snake_case							:   dict ,      snake_case							:   dict ,      snake_case							:   dict ,      )      ->    Union[str, Any]:
						_validation(
						    SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      )
						# Creates data structures and fill initial step
						__UpperCamelCase       =			{}
						__UpperCamelCase       =			{}
						for state in states_space:
												__UpperCamelCase       =			observations_space[0]
												__UpperCamelCase       =			(
												    initial_probabilities[state] * emission_probabilities[state][observation]
												)
												__UpperCamelCase       =			None

						# Fills the data structure with the probabilities of
						# different transitions and pointers to previous states
						for o in range(1 ,      len(SCREAMING_SNAKE_CASE__ ) ):
												__UpperCamelCase       =			observations_space[o]
												__UpperCamelCase       =			observations_space[o - 1]
												for state in states_space:
																		# Calculates the argmax for probability function
																		__UpperCamelCase       =			""""""
																		__UpperCamelCase       =			-1
																		for k_state in states_space:
																								__UpperCamelCase       =			(
																								    probabilities[(k_state, prior_observation)]
																								    * transition_probabilities[k_state][state]
																								    * emission_probabilities[state][observation]
																								)
																								if probability > max_probability:
																														__UpperCamelCase       =			probability
																														__UpperCamelCase       =			k_state

            # Update probabilities and pointers dicts
																		__UpperCamelCase       =			(
																		    probabilities[(arg_max, prior_observation)]
																		    * transition_probabilities[arg_max][state]
																		    * emission_probabilities[state][observation]
																		)

																		__UpperCamelCase       =			arg_max

    # The final observation
						__UpperCamelCase       =			observations_space[len(SCREAMING_SNAKE_CASE__ ) - 1]

						# argmax for given final observation
						__UpperCamelCase       =			""""""
						__UpperCamelCase       =			-1
						for k_state in states_space:
												__UpperCamelCase       =			probabilities[(k_state, final_observation)]
												if probability > max_probability:
																		__UpperCamelCase       =			probability
																		__UpperCamelCase       =			k_state
						__UpperCamelCase       =			arg_max

						# Process pointers backwards
						__UpperCamelCase       =			last_state
						__UpperCamelCase       =			[]
						for o in range(len(SCREAMING_SNAKE_CASE__ ) - 1 ,      -1 ,      -1 ):
												result.append(SCREAMING_SNAKE_CASE__ )
												__UpperCamelCase       =			pointers[previous, observations_space[o]]
						result.reverse()

						return result




def 	A_ (							snake_case							:   Any ,      snake_case							:   Any ,      snake_case							:   Any ,      snake_case							:   Any ,      snake_case							:   Any ,      )      ->    Optional[int]:
						_validate_not_empty(
						    SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      )
						_validate_lists(SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ )
						_validate_dicts(
						    SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ )




def 	A_ (							snake_case							:   Any ,      snake_case							:   Any ,      snake_case							:   Any ,      snake_case							:   Any ,      snake_case							:   Any ,      )      ->    Union[str, Any]:





						if not all(
						    [
						        observations_space,
						        states_space,
						        initial_probabilities,
						        transition_probabilities,
						        emission_probabilities,
						    ] ):
												raise ValueError('''There\'s an empty parameter''' )




def 	A_ (							snake_case							:   Any ,      snake_case							:   Any )      ->    Optional[int]:
						_validate_list(SCREAMING_SNAKE_CASE__ ,      '''observations_space''' )
						_validate_list(SCREAMING_SNAKE_CASE__ ,      '''states_space''' )




def 	A_ (							snake_case							:   Any ,      snake_case							:   str )      ->    Tuple:





						if not isinstance(_object ,      SCREAMING_SNAKE_CASE__ ):
												__UpperCamelCase       =			f"{var_name} must be a list"
												raise ValueError(SCREAMING_SNAKE_CASE__ )
						else:
												for x in _object:
																		if not isinstance(SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ):
																								__UpperCamelCase       =			f"{var_name} must be a list of strings"
																								raise ValueError(SCREAMING_SNAKE_CASE__ )




def 	A_ (							snake_case							:   Any ,      snake_case							:   Any ,      snake_case							:   Any ,      )      ->    List[str]:
						_validate_dict(SCREAMING_SNAKE_CASE__ ,      '''initial_probabilities''' ,      SCREAMING_SNAKE_CASE__ )
						_validate_nested_dict(SCREAMING_SNAKE_CASE__ ,      '''transition_probabilities''' )
						_validate_nested_dict(SCREAMING_SNAKE_CASE__ ,      '''emission_probabilities''' )




def 	A_ (							snake_case							:   Any ,      snake_case							:   str )      ->    List[Any]:
						_validate_dict(_object ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ )
						for x in _object.values():
												_validate_dict(SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ )




def 	A_ (							snake_case							:   Any ,      snake_case							:   str ,      snake_case							:   type ,      snake_case							:   bool = False )      ->    Optional[int]:





						if not isinstance(_object ,      SCREAMING_SNAKE_CASE__ ):
												__UpperCamelCase       =			f"{var_name} must be a dict"
												raise ValueError(SCREAMING_SNAKE_CASE__ )
						if not all(isinstance(SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ) for x in _object ):
												__UpperCamelCase       =			f"{var_name} all keys must be strings"
												raise ValueError(SCREAMING_SNAKE_CASE__ )
						if not all(isinstance(SCREAMING_SNAKE_CASE__ ,      SCREAMING_SNAKE_CASE__ ) for x in _object.values() ):
												__UpperCamelCase       =			"""nested dictionary """ if nested else """"""
												__UpperCamelCase       =			f"{var_name} {nested_text}all values must be {value_type.__name__}"
												raise ValueError(SCREAMING_SNAKE_CASE__ )


if __name__ == "__main__":
				from doctest import testmod

				testmod()






from ....configuration_utils import PretrainedConfig
from ....utils import logging


lowercase__							:							Tuple									=			logging.get_logger(__name__)

lowercase__							:							Union[str, Any]									=			{
    "speechbrain/m-ctc-t-large": "https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json",
    # See all M-CTC-T models at https://huggingface.co/models?filter=mctct
}






class        SCREAMING_SNAKE_CASE__    (							SCREAMING_SNAKE_CASE_    ):

							"""simple docstring"""






							_snake_case     		=  'mctct'



							def __init__(  self     ,	SCREAMING_SNAKE_CASE_=8065     ,	SCREAMING_SNAKE_CASE_=1536     ,	SCREAMING_SNAKE_CASE_=36     ,	SCREAMING_SNAKE_CASE_=6144     ,	SCREAMING_SNAKE_CASE_=4     ,	SCREAMING_SNAKE_CASE_=384     ,	SCREAMING_SNAKE_CASE_=920     ,	SCREAMING_SNAKE_CASE_=1E-5     ,	SCREAMING_SNAKE_CASE_=0.3     ,	SCREAMING_SNAKE_CASE_="relu"     ,	SCREAMING_SNAKE_CASE_=0.0_2     ,	SCREAMING_SNAKE_CASE_=0.3     ,	SCREAMING_SNAKE_CASE_=0.3     ,	SCREAMING_SNAKE_CASE_=1     ,	SCREAMING_SNAKE_CASE_=0     ,	SCREAMING_SNAKE_CASE_=2     ,	SCREAMING_SNAKE_CASE_=1     ,	SCREAMING_SNAKE_CASE_=0.3     ,	SCREAMING_SNAKE_CASE_=1     ,	SCREAMING_SNAKE_CASE_=(7,)     ,	SCREAMING_SNAKE_CASE_=(3,)     ,	SCREAMING_SNAKE_CASE_=80     ,	SCREAMING_SNAKE_CASE_=1     ,	SCREAMING_SNAKE_CASE_=None     ,	SCREAMING_SNAKE_CASE_="sum"     ,	SCREAMING_SNAKE_CASE_=False     ,	**SCREAMING_SNAKE_CASE_     ,	)->   Tuple:





													'''simple docstring'''






													super().__init__(**SCREAMING_SNAKE_CASE_     ,	pad_token_id=SCREAMING_SNAKE_CASE_     ,	bos_token_id=SCREAMING_SNAKE_CASE_     ,	eos_token_id=SCREAMING_SNAKE_CASE_			)
													__UpperCamelCase       =			vocab_size
													__UpperCamelCase       =			hidden_size
													__UpperCamelCase       =			num_hidden_layers
													__UpperCamelCase       =			intermediate_size
													__UpperCamelCase       =			num_attention_heads
													__UpperCamelCase       =			attention_head_dim
													__UpperCamelCase       =			max_position_embeddings
													__UpperCamelCase       =			layer_norm_eps
													__UpperCamelCase       =			layerdrop
													__UpperCamelCase       =			hidden_act
													__UpperCamelCase       =			initializer_range
													__UpperCamelCase       =			hidden_dropout_prob
													__UpperCamelCase       =			attention_probs_dropout_prob
													__UpperCamelCase       =			pad_token_id
													__UpperCamelCase       =			bos_token_id
													__UpperCamelCase       =			eos_token_id
													__UpperCamelCase       =			conv_glu_dim
													__UpperCamelCase       =			conv_dropout
													__UpperCamelCase       =			num_conv_layers
													__UpperCamelCase       =			input_feat_per_channel
													__UpperCamelCase       =			input_channels
													__UpperCamelCase       =			conv_channels
													__UpperCamelCase       =			ctc_loss_reduction
													__UpperCamelCase       =			ctc_zero_infinity

													# prevents config testing fail with exporting to json
													__UpperCamelCase       =			list(SCREAMING_SNAKE_CASE_			)
													__UpperCamelCase       =			list(SCREAMING_SNAKE_CASE_			)

													if len(self.conv_kernel			) != self.num_conv_layers:
																			raise ValueError(
																			    '''Configuration for convolutional module is incorrect. '''
																			    '''It is required that `len(config.conv_kernel)` == `config.num_conv_layers` '''
																			    F"but is `len(config.conv_kernel) = {len(self.conv_kernel			)}`, "
																			    F"`config.num_conv_layers = {self.num_conv_layers}`."			)




