
"""simple docstring"""




import os
import tempfile
from functools import partial
from unittest import TestCase
from unittest.mock import patch

import datasets
import datasets.config

from .utils import require_beam



class 			lowerCAmelCase_		(datasets.BeamBasedBuilder						):


				"""simple docstring"""



				def 			__magic_name__					(self					)      ->	Any:



											"""simple docstring"""




											return datasets.DatasetInfo(
											    features=datasets.Features({"""content""": datasets.Value("""string"""					)}					)     , supervised_keys=SCREAMING_SNAKE_CASE__     , )



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



											"""simple docstring"""




											return [datasets.SplitGenerator(name=datasets.Split.TRAIN     , gen_kwargs={"""examples""": get_test_dummy_examples()}					)]



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



											"""simple docstring"""




											import apache_beam as beam

											return pipeline | "Load Examples" >> beam.Create(SCREAMING_SNAKE_CASE__					)






class 			lowerCAmelCase_		(datasets.BeamBasedBuilder						):


				"""simple docstring"""



				def 			__magic_name__					(self					)      ->	Any:



											"""simple docstring"""




											return datasets.DatasetInfo(
											    features=datasets.Features({"""a""": datasets.Sequence({"""b""": datasets.Value("""string"""					)}					)}					)     , supervised_keys=SCREAMING_SNAKE_CASE__     , )



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					)      ->	str:



											"""simple docstring"""




											return [
											    datasets.SplitGenerator(name=datasets.Split.TRAIN     , gen_kwargs={"""examples""": get_test_nested_examples()}					)
											]



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					)      ->	Any:



											"""simple docstring"""




											import apache_beam as beam

											return pipeline | "Load Examples" >> beam.Create(SCREAMING_SNAKE_CASE__					)






def lowercase_						(     ):
							return [(i, {"content": content}) for i, content in enumerate(["""foo""", """bar""", """foobar"""]		)]

def lowercase_						(     ):
							return [(i, {"a": {"b": [content]}}) for i, content in enumerate(["""foo""", """bar""", """foobar"""]		)]



class 			lowerCAmelCase_		(a__						):


				"""simple docstring"""



				@require_beam
				def 			__magic_name__					(self					)      ->	Dict:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: List[Any]     =     len(get_test_dummy_examples()					)
											with tempfile.TemporaryDirectory() as tmp_cache_dir:
																		SCREAMING_SNAKE_CASE__		: List[str]     =     DummyBeamDataset(cache_dir=SCREAMING_SNAKE_CASE__     , beam_runner="""DirectRunner"""					)
																		builder.download_and_prepare()
																		self.assertTrue(
																		    os.path.exists(
																		        os.path.join(SCREAMING_SNAKE_CASE__     , builder.name     , """default"""     , """0.0.0"""     , F'''{builder.name}-train.arrow'''					)					)					)
																		self.assertDictEqual(builder.info.features     , datasets.Features({"""content""": datasets.Value("""string"""					)}					)					)
																		SCREAMING_SNAKE_CASE__		: str     =     builder.as_dataset()
																		self.assertEqual(dset["""train"""].num_rows     , SCREAMING_SNAKE_CASE__					)
																		self.assertEqual(dset["""train"""].info.splits["""train"""].num_examples     , SCREAMING_SNAKE_CASE__					)
																		self.assertDictEqual(dset["""train"""][0]     , get_test_dummy_examples()[0][1]					)
																		self.assertDictEqual(
																		    dset["""train"""][expected_num_examples - 1]     , get_test_dummy_examples()[expected_num_examples - 1][1]					)
																		self.assertTrue(
																		    os.path.exists(os.path.join(SCREAMING_SNAKE_CASE__     , builder.name     , """default"""     , """0.0.0"""     , """dataset_info.json"""					)					)					)
																		del dset



				@require_beam
				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											import apache_beam as beam

											SCREAMING_SNAKE_CASE__		: Dict     =     beam.io.parquetio.WriteToParquet

											SCREAMING_SNAKE_CASE__		: Any     =     len(get_test_dummy_examples()					)
											with tempfile.TemporaryDirectory() as tmp_cache_dir:
																		SCREAMING_SNAKE_CASE__		: Tuple     =     DummyBeamDataset(cache_dir=SCREAMING_SNAKE_CASE__     , beam_runner="""DirectRunner"""					)
																		with patch("""apache_beam.io.parquetio.WriteToParquet"""					) as write_parquet_mock:
																									SCREAMING_SNAKE_CASE__		: Dict     =     partial(SCREAMING_SNAKE_CASE__     , num_shards=2					)
																									builder.download_and_prepare()
																		self.assertTrue(
																		    os.path.exists(
																		        os.path.join(
																		            SCREAMING_SNAKE_CASE__     , builder.name     , """default"""     , """0.0.0"""     , F'''{builder.name}-train-00000-of-00002.arrow'''					)					)					)
																		self.assertTrue(
																		    os.path.exists(
																		        os.path.join(
																		            SCREAMING_SNAKE_CASE__     , builder.name     , """default"""     , """0.0.0"""     , F'''{builder.name}-train-00000-of-00002.arrow'''					)					)					)
																		self.assertDictEqual(builder.info.features     , datasets.Features({"""content""": datasets.Value("""string"""					)}					)					)
																		SCREAMING_SNAKE_CASE__		: List[Any]     =     builder.as_dataset()
																		self.assertEqual(dset["""train"""].num_rows     , SCREAMING_SNAKE_CASE__					)
																		self.assertEqual(dset["""train"""].info.splits["""train"""].num_examples     , SCREAMING_SNAKE_CASE__					)
																		# Order is not preserved when sharding, so we just check that all the elements are there
																		self.assertListEqual(sorted(dset["""train"""]["""content"""]					)     , sorted(["""foo""", """bar""", """foobar"""]					)					)
																		self.assertTrue(
																		    os.path.exists(os.path.join(SCREAMING_SNAKE_CASE__     , builder.name     , """default"""     , """0.0.0"""     , """dataset_info.json"""					)					)					)
																		del dset



				@require_beam
				def 			__magic_name__					(self					)      ->	Optional[Any]:



											"""simple docstring"""




											with tempfile.TemporaryDirectory() as tmp_cache_dir:
																		SCREAMING_SNAKE_CASE__		: Optional[int]     =     DummyBeamDataset(cache_dir=SCREAMING_SNAKE_CASE__					)
																		self.assertRaises(datasets.builder.MissingBeamOptions     , builder.download_and_prepare					)



				@require_beam
				def 			__magic_name__					(self					)      ->	int:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: int     =     len(get_test_nested_examples()					)
											with tempfile.TemporaryDirectory() as tmp_cache_dir:
																		SCREAMING_SNAKE_CASE__		: Optional[int]     =     NestedBeamDataset(cache_dir=SCREAMING_SNAKE_CASE__     , beam_runner="""DirectRunner"""					)
																		builder.download_and_prepare()
																		self.assertTrue(
																		    os.path.exists(
																		        os.path.join(SCREAMING_SNAKE_CASE__     , builder.name     , """default"""     , """0.0.0"""     , F'''{builder.name}-train.arrow'''					)					)					)
																		self.assertDictEqual(
																		    builder.info.features     , datasets.Features({"""a""": datasets.Sequence({"""b""": datasets.Value("""string"""					)}					)}					)					)
																		SCREAMING_SNAKE_CASE__		: Any     =     builder.as_dataset()
																		self.assertEqual(dset["""train"""].num_rows     , SCREAMING_SNAKE_CASE__					)
																		self.assertEqual(dset["""train"""].info.splits["""train"""].num_examples     , SCREAMING_SNAKE_CASE__					)
																		self.assertDictEqual(dset["""train"""][0]     , get_test_nested_examples()[0][1]					)
																		self.assertDictEqual(
																		    dset["""train"""][expected_num_examples - 1]     , get_test_nested_examples()[expected_num_examples - 1][1]					)
																		self.assertTrue(
																		    os.path.exists(os.path.join(SCREAMING_SNAKE_CASE__     , builder.name     , """default"""     , """0.0.0"""     , """dataset_info.json"""					)					)					)
																		del dset






"""simple docstring"""




import functools
import operator

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


UpperCAmelCase__   :					str												=				logging.get_logger(__name__)

UpperCAmelCase__   :					Dict												=				{
    'microsoft/unispeech-large-1500h-cv': (
        'https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json'
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}



class 			lowerCAmelCase_		(a__						):


				"""simple docstring"""



				__UpperCamelCase   :		List[str]       =     '''unispeech'''



				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__="gelu"     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=0.0     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=0.02     , SCREAMING_SNAKE_CASE__=1E-5     , SCREAMING_SNAKE_CASE__="group"     , SCREAMING_SNAKE_CASE__="gelu"     , SCREAMING_SNAKE_CASE__=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)     , SCREAMING_SNAKE_CASE__=(5, 2, 2, 2, 2, 2, 2)     , SCREAMING_SNAKE_CASE__=(10, 3, 3, 3, 3, 2, 2)     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__=1_28     , SCREAMING_SNAKE_CASE__=16     , SCREAMING_SNAKE_CASE__=False     , 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__=3_20     , SCREAMING_SNAKE_CASE__=2     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__=1_00     , SCREAMING_SNAKE_CASE__=2_56     , SCREAMING_SNAKE_CASE__=2_56     , SCREAMING_SNAKE_CASE__=0.1     , SCREAMING_SNAKE_CASE__="mean"     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__=False     , SCREAMING_SNAKE_CASE__=2_56     , SCREAMING_SNAKE_CASE__=80     , SCREAMING_SNAKE_CASE__=0     , SCREAMING_SNAKE_CASE__=1     , SCREAMING_SNAKE_CASE__=2     , SCREAMING_SNAKE_CASE__=0.5     , **SCREAMING_SNAKE_CASE__     , )      ->	List[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__		: Optional[Any]     =     hidden_size
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     feat_extract_norm
											SCREAMING_SNAKE_CASE__		: Any     =     feat_extract_activation
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     list(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: str     =     list(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: Tuple     =     list(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[str]     =     conv_bias
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     num_conv_pos_embeddings
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     num_conv_pos_embedding_groups
											SCREAMING_SNAKE_CASE__		: Dict     =     len(self.conv_dim					)
											SCREAMING_SNAKE_CASE__		: List[str]     =     num_hidden_layers
											SCREAMING_SNAKE_CASE__		: str     =     intermediate_size
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     hidden_act
											SCREAMING_SNAKE_CASE__		: Any     =     num_attention_heads
											SCREAMING_SNAKE_CASE__		: Dict     =     hidden_dropout
											SCREAMING_SNAKE_CASE__		: List[str]     =     attention_dropout
											SCREAMING_SNAKE_CASE__		: Any     =     activation_dropout
											SCREAMING_SNAKE_CASE__		: int     =     feat_proj_dropout
											SCREAMING_SNAKE_CASE__		: List[Any]     =     final_dropout
											SCREAMING_SNAKE_CASE__		: str     =     layerdrop
											SCREAMING_SNAKE_CASE__		: Optional[int]     =     layer_norm_eps
											SCREAMING_SNAKE_CASE__		: Dict     =     initializer_range
											SCREAMING_SNAKE_CASE__		: Dict     =     num_ctc_classes
											SCREAMING_SNAKE_CASE__		: List[Any]     =     vocab_size
											SCREAMING_SNAKE_CASE__		: str     =     do_stable_layer_norm
											SCREAMING_SNAKE_CASE__		: Dict     =     use_weighted_layer_sum
											SCREAMING_SNAKE_CASE__		: Union[str, Any]     =     classifier_proj_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)`, but is `len(config.conv_dim) ="""
																		    F''' {len(self.conv_dim					)}`, `len(config.conv_stride) = {len(self.conv_stride					)}`,'''
																		    F''' `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__		: Optional[int]     =     mask_time_prob
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     mask_time_length
											SCREAMING_SNAKE_CASE__		: List[str]     =     mask_time_min_masks
											SCREAMING_SNAKE_CASE__		: Tuple     =     mask_feature_prob
											SCREAMING_SNAKE_CASE__		: Any     =     mask_feature_length
											SCREAMING_SNAKE_CASE__		: int     =     mask_feature_min_masks

											# parameters for pretraining with codevector quantized representations
											SCREAMING_SNAKE_CASE__		: Dict     =     num_codevectors_per_group
											SCREAMING_SNAKE_CASE__		: Any     =     num_codevector_groups
											SCREAMING_SNAKE_CASE__		: str     =     contrastive_logits_temperature
											SCREAMING_SNAKE_CASE__		: str     =     feat_quantizer_dropout
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     num_negatives
											SCREAMING_SNAKE_CASE__		: Tuple     =     codevector_dim
											SCREAMING_SNAKE_CASE__		: List[Any]     =     proj_codevector_dim
											SCREAMING_SNAKE_CASE__		: Tuple     =     diversity_loss_weight

											# ctc loss
											SCREAMING_SNAKE_CASE__		: int     =     ctc_loss_reduction
											SCREAMING_SNAKE_CASE__		: str     =     ctc_zero_infinity

											# pretraining loss
											SCREAMING_SNAKE_CASE__		: List[str]     =     replace_prob



				@property
				def 			__magic_name__					(self					)      ->	Tuple:



											"""simple docstring"""




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




