


"""simple docstring"""

import functools
import operator

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


UpperCAmelCase__  							=logging.get_logger(__name__)

UpperCAmelCase__  							={
    "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    ):
						a :     Tuple											=		"""sew-d"""
						def __init__(		self	:	Optional[int]      ,       A_	:	int=3_2      ,       A_	:	Any=7_6_8      ,       A_	:	Any=1_2      ,       A_	:	int=1_2      ,       A_	:	List[Any]=3_0_7_2      ,       A_	:	int=2      ,       A_	:	Optional[Any]=5_1_2      ,       A_	:	Union[str, Any]=2_5_6      ,       A_	:	Union[str, Any]=True      ,       A_	:	Union[str, Any]=True      ,       A_	:	List[Any]=("p2c", "c2p")      ,       A_	:	Dict="layer_norm"      ,       A_	:	List[Any]="gelu_python"      ,       A_	:	Union[str, Any]=0.1      ,       A_	:	Any=0.1      ,       A_	:	Optional[Any]=0.1      ,       A_	:	Optional[Any]=0.0      ,       A_	:	Union[str, Any]=0.1      ,       A_	:	List[str]=0.02      ,       A_	:	List[str]=1e-7      ,       A_	:	List[str]=1e-5      ,       A_	:	Union[str, Any]="group"      ,       A_	:	int="gelu"      ,       A_	:	Union[str, 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)      ,       A_	:	Dict=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)      ,       A_	:	int=(1_0, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)      ,       A_	:	str=False      ,       A_	:	Tuple=1_2_8      ,       A_	:	List[Any]=1_6      ,       A_	:	Dict=True      ,       A_	:	str=0.05      ,       A_	:	Tuple=1_0      ,       A_	:	List[str]=2      ,       A_	:	List[Any]=0.0      ,       A_	:	Optional[Any]=1_0      ,       A_	:	str=0      ,       A_	:	Tuple="mean"      ,       A_	:	List[str]=False      ,       A_	:	Tuple=False      ,       A_	:	List[Any]=2_5_6      ,       A_	:	Optional[Any]=0      ,       A_	:	Optional[int]=1      ,       A_	:	Optional[int]=2      ,       **A_	:	int      ,       ):






							'''simple docstring'''


							super().__init__(**A_      ,       pad_token_id=A_      ,       bos_token_id=A_      ,       eos_token_id=A_							)
							__lowercase									=	hidden_size
							__lowercase									=	feat_extract_norm
							__lowercase									=	feat_extract_activation
							__lowercase									=	list(A_							)
							__lowercase									=	list(A_							)
							__lowercase									=	list(A_							)
							__lowercase									=	conv_bias
							__lowercase									=	num_conv_pos_embeddings
							__lowercase									=	num_conv_pos_embedding_groups
							__lowercase									=	len(self.conv_dim							)
							__lowercase									=	num_hidden_layers
							__lowercase									=	intermediate_size
							__lowercase									=	squeeze_factor
							__lowercase									=	max_position_embeddings
							__lowercase									=	position_buckets
							__lowercase									=	share_att_key
							__lowercase									=	relative_attention
							__lowercase									=	norm_rel_ebd
							__lowercase									=	list(A_							)
							__lowercase									=	hidden_act
							__lowercase									=	num_attention_heads
							__lowercase									=	hidden_dropout
							__lowercase									=	attention_dropout
							__lowercase									=	activation_dropout
							__lowercase									=	feat_proj_dropout
							__lowercase									=	final_dropout
							__lowercase									=	layer_norm_eps
							__lowercase									=	feature_layer_norm_eps
							__lowercase									=	initializer_range
							__lowercase									=	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
							__lowercase									=	apply_spec_augment
							__lowercase									=	mask_time_prob
							__lowercase									=	mask_time_length
							__lowercase									=	mask_time_min_masks
							__lowercase									=	mask_feature_prob
							__lowercase									=	mask_feature_length
							__lowercase									=	mask_feature_min_masks

							# ctc loss
							__lowercase									=	ctc_loss_reduction
							__lowercase									=	ctc_zero_infinity

							# sequence classification
							__lowercase									=	use_weighted_layer_sum
							__lowercase									=	classifier_proj_size






						@property
						def SCREAMING_SNAKE_CASE_	(		self	:	Optional[Any]							):






							'''simple docstring'''


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




"""simple docstring"""

import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.text import TextDatasetReader

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases


def lowerCAmelCase_      (				UpperCamelCase__	: List[str]				,   UpperCamelCase__	: Any ):






 """simple docstring"""







 assert isinstance(UpperCamelCase__				,   UpperCamelCase__ )
 assert dataset.num_rows == 4
 assert dataset.num_columns == 1
 assert dataset.column_names == ["text"]
 for feature, expected_dtype in expected_features.items():
  assert dataset.features[feature].dtype == expected_dtype


@pytest.mark.parametrize("""keep_in_memory"""				,   [False, True] )
def lowerCAmelCase_      (				UpperCamelCase__	: Dict				,   UpperCamelCase__	: Optional[int]				,   UpperCamelCase__	: List[str] ):






 """simple docstring"""







 __lowercase									=	tmp_path / """cache"""
 __lowercase									=	{"""text""": """string"""}
 with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
  __lowercase									=	TextDatasetReader(UpperCamelCase__				,   cache_dir=UpperCamelCase__				,   keep_in_memory=UpperCamelCase__ ).read()
 _check_text_dataset(UpperCamelCase__				,   UpperCamelCase__ )


@pytest.mark.parametrize(
    """features"""				,   [
        None,
        {"""text""": """string"""},
        {"""text""": """int32"""},
        {"""text""": """float32"""},
    ]				,   )
def lowerCAmelCase_      (				UpperCamelCase__	: List[Any]				,   UpperCamelCase__	: List[str]				,   UpperCamelCase__	: Union[str, Any] ):






 """simple docstring"""







 __lowercase									=	tmp_path / """cache"""
 __lowercase									=	{"""text""": """string"""}
 __lowercase									=	features.copy() if features else default_expected_features
 __lowercase									=	(
     Features({feature: Value(UpperCamelCase__ ) for feature, dtype in features.items()} ) if features is not None else None
 )
 __lowercase									=	TextDatasetReader(UpperCamelCase__				,   features=UpperCamelCase__				,   cache_dir=UpperCamelCase__ ).read()
 _check_text_dataset(UpperCamelCase__				,   UpperCamelCase__ )


@pytest.mark.parametrize("""split"""				,   [None, NamedSplit("""train""" ), """train""", """test"""] )
def lowerCAmelCase_      (				UpperCamelCase__	: Union[str, Any]				,   UpperCamelCase__	: str				,   UpperCamelCase__	: Tuple ):






 """simple docstring"""







 __lowercase									=	tmp_path / """cache"""
 __lowercase									=	{"""text""": """string"""}
 __lowercase									=	TextDatasetReader(UpperCamelCase__				,   cache_dir=UpperCamelCase__				,   split=UpperCamelCase__ ).read()
 _check_text_dataset(UpperCamelCase__				,   UpperCamelCase__ )
 assert dataset.split == split if split else "train"


@pytest.mark.parametrize("""path_type"""				,   [str, list] )
def lowerCAmelCase_      (				UpperCamelCase__	: Union[str, Any]				,   UpperCamelCase__	: List[str]				,   UpperCamelCase__	: Any ):






 """simple docstring"""







 if issubclass(UpperCamelCase__				,   UpperCamelCase__ ):
  __lowercase									=	text_path
 elif issubclass(UpperCamelCase__				,   UpperCamelCase__ ):
  __lowercase									=	[text_path]
 __lowercase									=	tmp_path / """cache"""
 __lowercase									=	{"""text""": """string"""}
 __lowercase									=	TextDatasetReader(UpperCamelCase__				,   cache_dir=UpperCamelCase__ ).read()
 _check_text_dataset(UpperCamelCase__				,   UpperCamelCase__ )


def lowerCAmelCase_      (				UpperCamelCase__	: str				,   UpperCamelCase__	: str				,   UpperCamelCase__	: Any=("train",) ):






 """simple docstring"""







 assert isinstance(UpperCamelCase__				,   UpperCamelCase__ )
 for split in splits:
  __lowercase									=	dataset_dict[split]
  assert dataset.num_rows == 4
  assert dataset.num_columns == 1
  assert dataset.column_names == ["text"]
  for feature, expected_dtype in expected_features.items():
   assert dataset.features[feature].dtype == expected_dtype


@pytest.mark.parametrize("""keep_in_memory"""				,   [False, True] )
def lowerCAmelCase_      (				UpperCamelCase__	: int				,   UpperCamelCase__	: List[str]				,   UpperCamelCase__	: List[Any] ):






 """simple docstring"""







 __lowercase									=	tmp_path / """cache"""
 __lowercase									=	{"""text""": """string"""}
 with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
  __lowercase									=	TextDatasetReader({"""train""": text_path}				,   cache_dir=UpperCamelCase__				,   keep_in_memory=UpperCamelCase__ ).read()
 _check_text_datasetdict(UpperCamelCase__				,   UpperCamelCase__ )


@pytest.mark.parametrize(
    """features"""				,   [
        None,
        {"""text""": """string"""},
        {"""text""": """int32"""},
        {"""text""": """float32"""},
    ]				,   )
def lowerCAmelCase_      (				UpperCamelCase__	: Optional[Any]				,   UpperCamelCase__	: Dict				,   UpperCamelCase__	: Union[str, Any] ):






 """simple docstring"""







 __lowercase									=	tmp_path / """cache"""
 # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
 __lowercase									=	{"""text""": """string"""}
 __lowercase									=	features.copy() if features else default_expected_features
 __lowercase									=	(
     Features({feature: Value(UpperCamelCase__ ) for feature, dtype in features.items()} ) if features is not None else None
 )
 __lowercase									=	TextDatasetReader({"""train""": text_path}				,   features=UpperCamelCase__				,   cache_dir=UpperCamelCase__ ).read()
 _check_text_datasetdict(UpperCamelCase__				,   UpperCamelCase__ )


@pytest.mark.parametrize("""split"""				,   [None, NamedSplit("""train""" ), """train""", """test"""] )
def lowerCAmelCase_      (				UpperCamelCase__	: Dict				,   UpperCamelCase__	: int				,   UpperCamelCase__	: int ):






 """simple docstring"""







 if split:
  __lowercase									=	{split: text_path}
 else:
  __lowercase									=	"""train"""
  __lowercase									=	{"""train""": text_path, """test""": text_path}
 __lowercase									=	tmp_path / """cache"""
 __lowercase									=	{"""text""": """string"""}
 __lowercase									=	TextDatasetReader(UpperCamelCase__				,   cache_dir=UpperCamelCase__ ).read()
 _check_text_datasetdict(UpperCamelCase__				,   UpperCamelCase__				,   splits=list(path.keys() ) )
 assert all(dataset[split].split == split for split in path.keys() )
