
"""simple docstring"""




import functools
import operator

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


UpperCAmelCase__   :					Dict												=				logging.get_logger(__name__)

UpperCAmelCase__   :					int												=				{
    '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 			lowerCAmelCase_		(a__						):


				"""simple docstring"""



				__UpperCamelCase   :		str       =     '''sew-d'''



				def __init__(self     , SCREAMING_SNAKE_CASE__=32     , SCREAMING_SNAKE_CASE__=7_68     , SCREAMING_SNAKE_CASE__=12     , SCREAMING_SNAKE_CASE__=12     , SCREAMING_SNAKE_CASE__=30_72     , SCREAMING_SNAKE_CASE__=2     , SCREAMING_SNAKE_CASE__=5_12     , SCREAMING_SNAKE_CASE__=2_56     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=("p2c", "c2p")     , SCREAMING_SNAKE_CASE__="layer_norm"     , SCREAMING_SNAKE_CASE__="gelu_python"     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.02     , SCREAMING_SNAKE_CASE__=1E-7     , SCREAMING_SNAKE_CASE__=1E-5     , SCREAMING_SNAKE_CASE__="group"     , SCREAMING_SNAKE_CASE__="gelu"     , SCREAMING_SNAKE_CASE__=(64, 1_28, 1_28, 1_28, 1_28, 2_56, 2_56, 2_56, 2_56, 5_12, 5_12, 5_12, 5_12)     , SCREAMING_SNAKE_CASE__=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)     , SCREAMING_SNAKE_CASE__=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__=1_28     , SCREAMING_SNAKE_CASE__=16     , SCREAMING_SNAKE_CASE__=True     , SCREAMING_SNAKE_CASE__=0.05     , SCREAMING_SNAKE_CASE__=10     , SCREAMING_SNAKE_CASE__=2     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=10     , SCREAMING_SNAKE_CASE__=0     , SCREAMING_SNAKE_CASE__="mean"     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__=2_56     , SCREAMING_SNAKE_CASE__=0     , SCREAMING_SNAKE_CASE__=1     , SCREAMING_SNAKE_CASE__=2     , **SCREAMING_SNAKE_CASE__     , )      ->	Any:



											"""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__					)
											SCREAMING_SNAKE_CASE__		: Dict     =     hidden_size
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     feat_extract_norm
											SCREAMING_SNAKE_CASE__		: Any     =     feat_extract_activation
											SCREAMING_SNAKE_CASE__		: Dict     =     list(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Tuple     =     list(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Tuple     =     list(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Tuple     =     conv_bias
											SCREAMING_SNAKE_CASE__		: str     =     num_conv_pos_embeddings
											SCREAMING_SNAKE_CASE__		: List[str]     =     num_conv_pos_embedding_groups
											SCREAMING_SNAKE_CASE__		: str     =     len(self.conv_dim					)
											SCREAMING_SNAKE_CASE__		: Dict     =     num_hidden_layers
											SCREAMING_SNAKE_CASE__		: Tuple     =     intermediate_size
											SCREAMING_SNAKE_CASE__		: Tuple     =     squeeze_factor
											SCREAMING_SNAKE_CASE__		: Dict     =     max_position_embeddings
											SCREAMING_SNAKE_CASE__		: List[str]     =     position_buckets
											SCREAMING_SNAKE_CASE__		: Any     =     share_att_key
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     relative_attention
											SCREAMING_SNAKE_CASE__		: str     =     norm_rel_ebd
											SCREAMING_SNAKE_CASE__		: List[str]     =     list(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: str     =     hidden_act
											SCREAMING_SNAKE_CASE__		: int     =     num_attention_heads
											SCREAMING_SNAKE_CASE__		: List[str]     =     hidden_dropout
											SCREAMING_SNAKE_CASE__		: Tuple     =     attention_dropout
											SCREAMING_SNAKE_CASE__		: Dict     =     activation_dropout
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     feat_proj_dropout
											SCREAMING_SNAKE_CASE__		: Dict     =     final_dropout
											SCREAMING_SNAKE_CASE__		: Dict     =     layer_norm_eps
											SCREAMING_SNAKE_CASE__		: Tuple     =     feature_layer_norm_eps
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     initializer_range
											SCREAMING_SNAKE_CASE__		: Tuple     =     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
											SCREAMING_SNAKE_CASE__		: Tuple     =     apply_spec_augment
											SCREAMING_SNAKE_CASE__		: List[Any]     =     mask_time_prob
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     mask_time_length
											SCREAMING_SNAKE_CASE__		: Dict     =     mask_time_min_masks
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     mask_feature_prob
											SCREAMING_SNAKE_CASE__		: Any     =     mask_feature_length
											SCREAMING_SNAKE_CASE__		: List[Any]     =     mask_feature_min_masks

											# ctc loss
											SCREAMING_SNAKE_CASE__		: str     =     ctc_loss_reduction
											SCREAMING_SNAKE_CASE__		: List[str]     =     ctc_zero_infinity

											# sequence classification
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     use_weighted_layer_sum
											SCREAMING_SNAKE_CASE__		: Any     =     classifier_proj_size



				@property
				def 			__magic_name__					(self					)      ->	Dict:



											"""simple docstring"""




											return functools.reduce(operator.mul     , self.conv_stride     , 1					)






"""simple docstring"""




import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast



@dataclass
class 			lowerCAmelCase_		(datasets.BuilderConfig						):


				"""simple docstring"""



				__UpperCamelCase   :		Optional[datasets.Features]       =     None






class 			lowerCAmelCase_		(datasets.ArrowBasedBuilder						):


				"""simple docstring"""



				__UpperCamelCase   :		Union[str, Any]       =     PandasConfig



				def 			__magic_name__					(self					)      ->	List[str]:



											"""simple docstring"""




											return datasets.DatasetInfo(features=self.config.features					)



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__					)      ->	Optional[int]:



											"""simple docstring"""




											if not self.config.data_files:
																		raise ValueError(F'''At least one data file must be specified, but got data_files={self.config.data_files}'''					)
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     dl_manager.download_and_extract(self.config.data_files					)
											if isinstance(SCREAMING_SNAKE_CASE__     , (str, list, tuple)					):
																		SCREAMING_SNAKE_CASE__		: Tuple     =     data_files
																		if isinstance(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					):
																									SCREAMING_SNAKE_CASE__		: Optional[Any]     =     [files]
																		# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
																		SCREAMING_SNAKE_CASE__		: str     =     [dl_manager.iter_files(SCREAMING_SNAKE_CASE__					) for file in files]
																		return [datasets.SplitGenerator(name=datasets.Split.TRAIN     , gen_kwargs={"""files""": files}					)]
											SCREAMING_SNAKE_CASE__		: int     =     []
											for split_name, files in data_files.items():
																		if isinstance(SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					):
																									SCREAMING_SNAKE_CASE__		: List[str]     =     [files]
																		# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
																		SCREAMING_SNAKE_CASE__		: Dict     =     [dl_manager.iter_files(SCREAMING_SNAKE_CASE__					) for file in files]
																		splits.append(datasets.SplitGenerator(name=SCREAMING_SNAKE_CASE__     , gen_kwargs={"""files""": files}					)					)
											return splits



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__					)      ->	pa.Table:



											"""simple docstring"""




											if self.config.features is not None:
																		# more expensive cast to support nested features with keys in a different order
																		# allows str <-> int/float or str to Audio for example
																		SCREAMING_SNAKE_CASE__		: Tuple     =     table_cast(SCREAMING_SNAKE_CASE__     , self.config.features.arrow_schema					)
											return pa_table



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__					)      ->	Optional[Any]:



											"""simple docstring"""




											for i, file in enumerate(itertools.chain.from_iterable(SCREAMING_SNAKE_CASE__					)					):
																		with open(SCREAMING_SNAKE_CASE__     , """rb"""					) as f:
																									SCREAMING_SNAKE_CASE__		: List[str]     =     pa.Table.from_pandas(pd.read_pickle(SCREAMING_SNAKE_CASE__					)					)
																									yield i, self._cast_table(SCREAMING_SNAKE_CASE__					)




