



'''simple docstring'''

import functools
import operator

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


snake_case_      =  logging.get_logger(__name__)

snake_case_      =  {
    '''microsoft/wavlm-base''': '''https://huggingface.co/microsoft/wavlm-base/resolve/main/config.json''',
    # See all WavLM models at https://huggingface.co/models?filter=wavlm
}


class 						a__  (					_snake_case						):
	__magic_name__		:     Union[str, Any]						     =  "wavlm"


	def __init__(self			:			Optional[Any],       __UpperCAmelCase			:			int=32,       __UpperCAmelCase			:			int=768,       __UpperCAmelCase			:			Optional[int]=12,       __UpperCAmelCase			:			Optional[int]=12,       __UpperCAmelCase			:			List[Any]=3072,       __UpperCAmelCase			:			Union[str, Any]="gelu",       __UpperCAmelCase			:			Optional[int]=0.1,       __UpperCAmelCase			:			List[Any]=0.1,       __UpperCAmelCase			:			Any=0.1,       __UpperCAmelCase			:			str=0.0,       __UpperCAmelCase			:			List[str]=0.1,       __UpperCAmelCase			:			Union[str, Any]=0.1,       __UpperCAmelCase			:			Optional[Any]=0.02,       __UpperCAmelCase			:			List[Any]=1e-5,       __UpperCAmelCase			:			int="group",       __UpperCAmelCase			:			Optional[Any]="gelu",       __UpperCAmelCase			:			Optional[Any]=(512, 512, 512, 512, 512, 512, 512),       __UpperCAmelCase			:			Optional[int]=(5, 2, 2, 2, 2, 2, 2),       __UpperCAmelCase			:			Optional[Any]=(10, 3, 3, 3, 3, 2, 2),       __UpperCAmelCase			:			Any=False,       __UpperCAmelCase			:			Union[str, Any]=128,       __UpperCAmelCase			:			List[str]=16,       __UpperCAmelCase			:			List[Any]=320,       __UpperCAmelCase			:			Dict=800,       __UpperCAmelCase			:			int=False,       __UpperCAmelCase			:			str=True,       __UpperCAmelCase			:			Optional[int]=0.05,       __UpperCAmelCase			:			List[str]=10,       __UpperCAmelCase			:			Tuple=2,       __UpperCAmelCase			:			List[str]=0.0,       __UpperCAmelCase			:			Optional[int]=10,       __UpperCAmelCase			:			List[Any]=320,       __UpperCAmelCase			:			Optional[Any]=2,       __UpperCAmelCase			:			Dict=0.1,       __UpperCAmelCase			:			Any=100,       __UpperCAmelCase			:			Optional[Any]=256,       __UpperCAmelCase			:			List[str]=256,       __UpperCAmelCase			:			Optional[Any]=0.1,       __UpperCAmelCase			:			str="mean",       __UpperCAmelCase			:			Any=False,       __UpperCAmelCase			:			Any=False,       __UpperCAmelCase			:			Any=256,       __UpperCAmelCase			:			List[Any]=(512, 512, 512, 512, 1500),       __UpperCAmelCase			:			Union[str, Any]=(5, 3, 3, 1, 1),       __UpperCAmelCase			:			Tuple=(1, 2, 3, 1, 1),       __UpperCAmelCase			:			Optional[int]=512,       __UpperCAmelCase			:			str=80,       __UpperCAmelCase			:			Dict=0,       __UpperCAmelCase			:			Optional[int]=1,       __UpperCAmelCase			:			int=2,       __UpperCAmelCase			:			int=False,       __UpperCAmelCase			:			List[str]=3,       __UpperCAmelCase			:			int=2,       __UpperCAmelCase			:			Optional[Any]=3,       __UpperCAmelCase			:			int=None,       **__UpperCAmelCase			:			Optional[int],       )  ->      Any:

					"""simple docstring"""

					super().__init__(**_lowerCamelCase,       pad_token_id=_lowerCamelCase,       bos_token_id=_lowerCamelCase,       eos_token_id=_lowerCamelCase   )
					SCREAMING_SNAKE_CASE	:    Union[str, Any]          =			hidden_size
					SCREAMING_SNAKE_CASE	:    List[Any]          =			feat_extract_norm
					SCREAMING_SNAKE_CASE	:    Tuple          =			feat_extract_activation
					SCREAMING_SNAKE_CASE	:    Tuple          =			list(_lowerCamelCase   )
					SCREAMING_SNAKE_CASE	:    Optional[Any]          =			list(_lowerCamelCase   )
					SCREAMING_SNAKE_CASE	:    Optional[Any]          =			list(_lowerCamelCase   )
					SCREAMING_SNAKE_CASE	:    int          =			conv_bias
					SCREAMING_SNAKE_CASE	:    Tuple          =			num_buckets
					SCREAMING_SNAKE_CASE	:    Tuple          =			max_bucket_distance
					SCREAMING_SNAKE_CASE	:    int          =			num_conv_pos_embeddings
					SCREAMING_SNAKE_CASE	:    List[str]          =			num_conv_pos_embedding_groups
					SCREAMING_SNAKE_CASE	:    Tuple          =			len(self.conv_dim   )
					SCREAMING_SNAKE_CASE	:    Any          =			num_hidden_layers
					SCREAMING_SNAKE_CASE	:    Tuple          =			intermediate_size
					SCREAMING_SNAKE_CASE	:    Any          =			hidden_act
					SCREAMING_SNAKE_CASE	:    List[str]          =			num_attention_heads
					SCREAMING_SNAKE_CASE	:    int          =			hidden_dropout
					SCREAMING_SNAKE_CASE	:    Optional[Any]          =			attention_dropout
					SCREAMING_SNAKE_CASE	:    Dict          =			activation_dropout
					SCREAMING_SNAKE_CASE	:    Any          =			feat_proj_dropout
					SCREAMING_SNAKE_CASE	:    Dict          =			final_dropout
					SCREAMING_SNAKE_CASE	:    int          =			layerdrop
					SCREAMING_SNAKE_CASE	:    Tuple          =			layer_norm_eps
					SCREAMING_SNAKE_CASE	:    Union[str, Any]          =			initializer_range
					SCREAMING_SNAKE_CASE	:    Union[str, Any]          =			num_ctc_classes
					SCREAMING_SNAKE_CASE	:    Optional[Any]          =			vocab_size
					SCREAMING_SNAKE_CASE	:    str          =			do_stable_layer_norm
					SCREAMING_SNAKE_CASE	:    Dict          =			use_weighted_layer_sum
					SCREAMING_SNAKE_CASE	:    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	:    List[Any]          =			apply_spec_augment
					SCREAMING_SNAKE_CASE	:    Optional[int]          =			mask_time_prob
					SCREAMING_SNAKE_CASE	:    Optional[Any]          =			mask_time_length
					SCREAMING_SNAKE_CASE	:    Tuple          =			mask_time_min_masks
					SCREAMING_SNAKE_CASE	:    Dict          =			mask_feature_prob
					SCREAMING_SNAKE_CASE	:    List[Any]          =			mask_feature_length

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

					# ctc loss
					SCREAMING_SNAKE_CASE	:    Dict          =			ctc_loss_reduction
					SCREAMING_SNAKE_CASE	:    Optional[int]          =			ctc_zero_infinity

					# adapter
					SCREAMING_SNAKE_CASE	:    Any          =			add_adapter
					SCREAMING_SNAKE_CASE	:    str          =			adapter_kernel_size
					SCREAMING_SNAKE_CASE	:    Tuple          =			adapter_stride
					SCREAMING_SNAKE_CASE	:    Dict          =			num_adapter_layers
					SCREAMING_SNAKE_CASE	:    Any          =			output_hidden_size or hidden_size

					# SequenceClassification-specific parameter. Feel free to ignore for other classes.
					SCREAMING_SNAKE_CASE	:    Tuple          =			classifier_proj_size

					# XVector-specific parameters. Feel free to ignore for other classes.
					SCREAMING_SNAKE_CASE	:    List[Any]          =			list(_lowerCamelCase   )
					SCREAMING_SNAKE_CASE	:    Optional[int]          =			list(_lowerCamelCase   )
					SCREAMING_SNAKE_CASE	:    List[str]          =			list(_lowerCamelCase   )
					SCREAMING_SNAKE_CASE	:    Optional[int]          =			xvector_output_dim






	@property
	def 					lowercase__	(self			:			int   )  ->      List[str]:

					"""simple docstring"""

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








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 						_snake_case    ( datasets.BeamBasedBuilder				):




 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       return datasets.DatasetInfo(
           features=datasets.Features({'''content''': datasets.Value('''string'''       )}       )   ,    supervised_keys=_lowerCamelCase   ,    )




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase   ,    _lowerCamelCase       ):
       return [datasets.SplitGenerator(name=datasets.Split.TRAIN   ,    gen_kwargs={'''examples''': get_test_dummy_examples()}       )]




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase   ,    _lowerCamelCase       ):
       import apache_beam as beam

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







class 						_snake_case    ( datasets.BeamBasedBuilder				):




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




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase   ,    _lowerCamelCase       ):
       return [
           datasets.SplitGenerator(name=datasets.Split.TRAIN   ,    gen_kwargs={'''examples''': get_test_nested_examples()}       )
       ]




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase   ,    _lowerCamelCase       ):
       import apache_beam as beam

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







def 							__lowerCamelCase		(					):




      """simple docstring"""





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




      """simple docstring"""





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







class 						_snake_case    ( _snake_case				):




 @require_beam
 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       a		:Dict									=			len(get_test_dummy_examples()       )
       with tempfile.TemporaryDirectory() as tmp_cache_dir:
             a		:Optional[Any]									=			DummyBeamDataset(cache_dir=_lowerCamelCase   ,    beam_runner='''DirectRunner'''       )
             builder.download_and_prepare()
             self.assertTrue(
                 os.path.exists(
                     os.path.join(_lowerCamelCase   ,    builder.name   ,    '''default'''   ,    '''0.0.0'''   ,    F'''{builder.name}-train.arrow'''       )       )       )
             self.assertDictEqual(builder.info.features   ,    datasets.Features({'''content''': datasets.Value('''string'''       )}       )       )
             a		:str									=			builder.as_dataset()
             self.assertEqual(dset['''train'''].num_rows   ,    _lowerCamelCase       )
             self.assertEqual(dset['''train'''].info.splits['''train'''].num_examples   ,    _lowerCamelCase       )
             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(_lowerCamelCase   ,    builder.name   ,    '''default'''   ,    '''0.0.0'''   ,    '''dataset_info.json'''       )       )       )
             del dset




 @require_beam
 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       import apache_beam as beam

       a		:Any									=			beam.io.parquetio.WriteToParquet

       a		:Any									=			len(get_test_dummy_examples()       )
       with tempfile.TemporaryDirectory() as tmp_cache_dir:
             a		:Union[str, Any]									=			DummyBeamDataset(cache_dir=_lowerCamelCase   ,    beam_runner='''DirectRunner'''       )
             with patch('''apache_beam.io.parquetio.WriteToParquet'''       ) as write_parquet_mock:
                   a		:str									=			partial(_lowerCamelCase   ,    num_shards=2       )
                   builder.download_and_prepare()
             self.assertTrue(
                 os.path.exists(
                     os.path.join(
                         _lowerCamelCase   ,    builder.name   ,    '''default'''   ,    '''0.0.0'''   ,    F'''{builder.name}-train-00000-of-00002.arrow'''       )       )       )
             self.assertTrue(
                 os.path.exists(
                     os.path.join(
                         _lowerCamelCase   ,    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'''       )}       )       )
             a		:List[str]									=			builder.as_dataset()
             self.assertEqual(dset['''train'''].num_rows   ,    _lowerCamelCase       )
             self.assertEqual(dset['''train'''].info.splits['''train'''].num_examples   ,    _lowerCamelCase       )
             # 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(_lowerCamelCase   ,    builder.name   ,    '''default'''   ,    '''0.0.0'''   ,    '''dataset_info.json'''       )       )       )
             del dset




 @require_beam
 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       with tempfile.TemporaryDirectory() as tmp_cache_dir:
             a		:Dict									=			DummyBeamDataset(cache_dir=_lowerCamelCase       )
             self.assertRaises(datasets.builder.MissingBeamOptions   ,    builder.download_and_prepare       )




 @require_beam
 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       a		:str									=			len(get_test_nested_examples()       )
       with tempfile.TemporaryDirectory() as tmp_cache_dir:
             a		:List[Any]									=			NestedBeamDataset(cache_dir=_lowerCamelCase   ,    beam_runner='''DirectRunner'''       )
             builder.download_and_prepare()
             self.assertTrue(
                 os.path.exists(
                     os.path.join(_lowerCamelCase   ,    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'''       )}       )}       )       )
             a		:Any									=			builder.as_dataset()
             self.assertEqual(dset['''train'''].num_rows   ,    _lowerCamelCase       )
             self.assertEqual(dset['''train'''].info.splits['''train'''].num_examples   ,    _lowerCamelCase       )
             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(_lowerCamelCase   ,    builder.name   ,    '''default'''   ,    '''0.0.0'''   ,    '''dataset_info.json'''       )       )       )
             del dset





