
import functools
import operator

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


__lowerCAmelCase									=logging.get_logger(__name__)

__lowerCAmelCase									={
    "asapp/sew-d-tiny-100k": "https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json",
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}


class  __magic_name__						(     _SCREAMING_SNAKE_CASE):
	_UpperCAmelCase	:			List[Any]		   =     '''sew-d'''





	def __init__(		self	: List[str]    ,__SCREAMING_SNAKE_CASE	: Tuple=3_2    ,__SCREAMING_SNAKE_CASE	: List[Any]=7_6_8    ,__SCREAMING_SNAKE_CASE	: Tuple=1_2    ,__SCREAMING_SNAKE_CASE	: Optional[Any]=1_2    ,__SCREAMING_SNAKE_CASE	: int=3_0_7_2    ,__SCREAMING_SNAKE_CASE	: List[str]=2    ,__SCREAMING_SNAKE_CASE	: Optional[Any]=5_1_2    ,__SCREAMING_SNAKE_CASE	: List[str]=2_5_6    ,__SCREAMING_SNAKE_CASE	: Dict=True    ,__SCREAMING_SNAKE_CASE	: Tuple=True    ,__SCREAMING_SNAKE_CASE	: str=("p2c", "c2p")    ,__SCREAMING_SNAKE_CASE	: Optional[Any]="layer_norm"    ,__SCREAMING_SNAKE_CASE	: Dict="gelu_python"    ,__SCREAMING_SNAKE_CASE	: Dict=0.1    ,__SCREAMING_SNAKE_CASE	: Optional[Any]=0.1    ,__SCREAMING_SNAKE_CASE	: Optional[Any]=0.1    ,__SCREAMING_SNAKE_CASE	: Any=0.0    ,__SCREAMING_SNAKE_CASE	: Optional[int]=0.1    ,__SCREAMING_SNAKE_CASE	: Optional[int]=0.02    ,__SCREAMING_SNAKE_CASE	: Any=1e-7    ,__SCREAMING_SNAKE_CASE	: Optional[Any]=1e-5    ,__SCREAMING_SNAKE_CASE	: List[Any]="group"    ,__SCREAMING_SNAKE_CASE	: List[Any]="gelu"    ,__SCREAMING_SNAKE_CASE	: Optional[Any]=(6_4, 1_2_8, 1_2_8, 1_2_8, 1_2_8, 2_5_6, 2_5_6, 2_5_6, 2_5_6, 5_1_2, 5_1_2, 5_1_2, 5_1_2)    ,__SCREAMING_SNAKE_CASE	: Union[str, Any]=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)    ,__SCREAMING_SNAKE_CASE	: Any=(1_0, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)    ,__SCREAMING_SNAKE_CASE	: List[Any]=False    ,__SCREAMING_SNAKE_CASE	: int=1_2_8    ,__SCREAMING_SNAKE_CASE	: List[Any]=1_6    ,__SCREAMING_SNAKE_CASE	: Optional[Any]=True    ,__SCREAMING_SNAKE_CASE	: List[str]=0.05    ,__SCREAMING_SNAKE_CASE	: List[str]=1_0    ,__SCREAMING_SNAKE_CASE	: Optional[Any]=2    ,__SCREAMING_SNAKE_CASE	: Union[str, Any]=0.0    ,__SCREAMING_SNAKE_CASE	: str=1_0    ,__SCREAMING_SNAKE_CASE	: Tuple=0    ,__SCREAMING_SNAKE_CASE	: str="mean"    ,__SCREAMING_SNAKE_CASE	: List[Any]=False    ,__SCREAMING_SNAKE_CASE	: Dict=False    ,__SCREAMING_SNAKE_CASE	: Dict=2_5_6    ,__SCREAMING_SNAKE_CASE	: Optional[Any]=0    ,__SCREAMING_SNAKE_CASE	: int=1    ,__SCREAMING_SNAKE_CASE	: Union[str, Any]=2    ,**__SCREAMING_SNAKE_CASE	: List[Any]    ,):
						super().__init__(**_lowercase    ,pad_token_id=_lowercase    ,bos_token_id=_lowercase    ,eos_token_id=_lowercase       )
						UpperCAmelCase				   =  hidden_size
						UpperCAmelCase				   =  feat_extract_norm
						UpperCAmelCase				   =  feat_extract_activation
						UpperCAmelCase				   =  list(_lowercase       )
						UpperCAmelCase				   =  list(_lowercase       )
						UpperCAmelCase				   =  list(_lowercase       )
						UpperCAmelCase				   =  conv_bias
						UpperCAmelCase				   =  num_conv_pos_embeddings
						UpperCAmelCase				   =  num_conv_pos_embedding_groups
						UpperCAmelCase				   =  len(self.conv_dim       )
						UpperCAmelCase				   =  num_hidden_layers
						UpperCAmelCase				   =  intermediate_size
						UpperCAmelCase				   =  squeeze_factor
						UpperCAmelCase				   =  max_position_embeddings
						UpperCAmelCase				   =  position_buckets
						UpperCAmelCase				   =  share_att_key
						UpperCAmelCase				   =  relative_attention
						UpperCAmelCase				   =  norm_rel_ebd
						UpperCAmelCase				   =  list(_lowercase       )
						UpperCAmelCase				   =  hidden_act
						UpperCAmelCase				   =  num_attention_heads
						UpperCAmelCase				   =  hidden_dropout
						UpperCAmelCase				   =  attention_dropout
						UpperCAmelCase				   =  activation_dropout
						UpperCAmelCase				   =  feat_proj_dropout
						UpperCAmelCase				   =  final_dropout
						UpperCAmelCase				   =  layer_norm_eps
						UpperCAmelCase				   =  feature_layer_norm_eps
						UpperCAmelCase				   =  initializer_range
						UpperCAmelCase				   =  vocab_size

						if (
						    (len(self.conv_stride       ) != self.num_feat_extract_layers)
						    or (len(self.conv_kernel       ) != self.num_feat_extract_layers)
						    or (len(self.conv_dim       ) != self.num_feat_extract_layers)
						):
											raise ValueError(
											    "Configuration for convolutional layers is incorrect."
											    "It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,"
											    f'''but is `len(config.conv_dim) = {len(self.conv_dim       )}`, `len(config.conv_stride)'''
											    f'''= {len(self.conv_stride       )}`, `len(config.conv_kernel) = {len(self.conv_kernel       )}`.'''       )

						# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
						UpperCAmelCase				   =  apply_spec_augment
						UpperCAmelCase				   =  mask_time_prob
						UpperCAmelCase				   =  mask_time_length
						UpperCAmelCase				   =  mask_time_min_masks
						UpperCAmelCase				   =  mask_feature_prob
						UpperCAmelCase				   =  mask_feature_length
						UpperCAmelCase				   =  mask_feature_min_masks

						# ctc loss
						UpperCAmelCase				   =  ctc_loss_reduction
						UpperCAmelCase				   =  ctc_zero_infinity

						# sequence classification
						UpperCAmelCase				   =  use_weighted_layer_sum
						UpperCAmelCase				   =  classifier_proj_size





	@property
	def 	_UpperCAmelCase						(		self	: Optional[Any]       ):
						return functools.reduce(operator.mul    ,self.conv_stride    ,1       )




'''simple docstring'''



import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


_lowercase          =						False
try:
						_lowercase          =						_is_package_available("""google.colab""")
except ModuleNotFoundError:
						pass




@input.register
class     UpperCAmelCase_	:






						'''simple docstring'''






						def __init__(   self       ,  _lowercase = None       ,  _lowercase = [] ):

												"""simple docstring"""



												_lowerCAmelCase    		=					0
												_lowerCAmelCase    		=					choices
												_lowerCAmelCase    		=					prompt
												if sys.platform == "win32":
																		_lowerCAmelCase    		=					"""*"""
												else:
																		_lowerCAmelCase    		=					"""➔ """




						def    _lowercase      (   self       ,  _lowercase       ,  _lowercase = "" ):

												"""simple docstring"""



												if sys.platform != "win32":
																		writeColor(self.choices[index]       ,  32       ,  _lowercase )
												else:
																		forceWrite(self.choices[index]       ,  _lowercase )




						def    _lowercase      (   self       ,  _lowercase ):

												"""simple docstring"""



												if index == self.position:
																		forceWrite(F' {self.arrow_char} ' )
																		self.write_choice(_lowercase )
												else:
																		forceWrite(F'    {self.choices[index]}' )
												reset_cursor()




						def    _lowercase      (   self       ,  _lowercase       ,  _lowercase = 1 ):

												"""simple docstring"""



												_lowerCAmelCase    		=					self.position
												if direction == Direction.DOWN:
																		if self.position + 1 >= len(self.choices ):
																								return
																		self.position += num_spaces
												else:
																		if self.position - 1 < 0:
																								return
																		self.position -= num_spaces
												clear_line()
												self.print_choice(_lowercase )
												move_cursor(_lowercase       ,  direction.name )
												self.print_choice(self.position )




						@input.mark(KEYMAP["""up"""] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												self.move_direction(Direction.UP )




						@input.mark(KEYMAP["""down"""] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												self.move_direction(Direction.DOWN )




						@input.mark(KEYMAP["""newline"""] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												move_cursor(len(self.choices ) - self.position       ,  """DOWN""" )
												return self.position




						@input.mark(KEYMAP["""interrupt"""] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												move_cursor(len(self.choices ) - self.position       ,  """DOWN""" )
												raise KeyboardInterrupt




						@input.mark_multiple(*[KEYMAP[str(_lowercase )] for number in range(10 )] )
						def    _lowercase      (   self ):

												"""simple docstring"""



												_lowerCAmelCase    		=					int(chr(self.current_selection ) )
												_lowerCAmelCase    		=					index - self.position
												if index == self.position:
																		return
												if index < len(self.choices ):
																		if self.position > index:
																								self.move_direction(Direction.UP       ,  -movement )
																		elif self.position < index:
																								self.move_direction(Direction.DOWN       ,  _lowercase )
																		else:
																								return
												else:
																		return




						def    _lowercase      (   self       ,  _lowercase = 0 ):

												"""simple docstring"""



												if self.prompt:
																		linebreak()
																		forceWrite(self.prompt       ,  """\n""" )
																		if in_colab:
																								forceWrite("""Please input a choice index (starting from 0), and press enter"""       ,  """\n""" )
																		else:
																								forceWrite("""Please select a choice using the arrow or number keys, and selecting with enter"""       ,  """\n""" )
												_lowerCAmelCase    		=					default_choice
												for i in range(len(self.choices ) ):
																		self.print_choice(_lowercase )
																		forceWrite("""\n""" )
												move_cursor(len(self.choices ) - self.position       ,  """UP""" )
												with cursor.hide():
																		while True:
																								if in_colab:
																														try:
																																				_lowerCAmelCase    		=					int(builtins.input() )
																														except ValueError:
																																				_lowerCAmelCase    		=					default_choice
																								else:
																														_lowerCAmelCase    		=					self.handle_input()
																								if choice is not None:
																														reset_cursor()
																														for _ in range(len(self.choices ) + 1 ):
																																				move_cursor(1       ,  """UP""" )
																																				clear_line()
																														self.write_choice(_lowercase       ,  """\n""" )
																														return choice
