

import functools
import operator

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


lowerCAmelCase__		      =       logging.get_logger(__name__)

lowerCAmelCase__		      =       {
    """facebook/wav2vec2-base-960h""": """https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json""",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}

class     a__  (    snake_case	):
			"""simple docstring"""







			__lowerCamelCase       				=				'wav2vec2'


			def __init__(			self					,					lowercase=32					,					lowercase=768					,					lowercase=12					,					lowercase=12					,					lowercase=3072					,					lowercase="gelu"					,					lowercase=0.1					,					lowercase=0.1					,					lowercase=0.1					,					lowercase=0.0					,					lowercase=0.0					,					lowercase=0.1					,					lowercase=0.1					,					lowercase=0.02					,					lowercase=1e-5					,					lowercase="group"					,					lowercase="gelu"					,					lowercase=(512, 512, 512, 512, 512, 512, 512)					,					lowercase=(5, 2, 2, 2, 2, 2, 2)					,					lowercase=(10, 3, 3, 3, 3, 2, 2)					,					lowercase=False					,					lowercase=128					,					lowercase=16					,					lowercase=False					,					lowercase=True					,					lowercase=0.05					,					lowercase=10					,					lowercase=2					,					lowercase=0.0					,					lowercase=10					,					lowercase=0					,					lowercase=320					,					lowercase=2					,					lowercase=0.1					,					lowercase=100					,					lowercase=256					,					lowercase=256					,					lowercase=0.1					,					lowercase="sum"					,					lowercase=False					,					lowercase=False					,					lowercase=256					,					lowercase=(512, 512, 512, 512, 1500)					,					lowercase=(5, 3, 3, 1, 1)					,					lowercase=(1, 2, 3, 1, 1)					,					lowercase=512					,					lowercase=0					,					lowercase=1					,					lowercase=2					,					lowercase=False					,					lowercase=3					,					lowercase=2					,					lowercase=3					,					lowercase=None					,					lowercase=None					,					**lowercase					,					)     ->  Any:
							'''simple docstring'''






							super().__init__(**lowercase					,					pad_token_id=lowercase					,					bos_token_id=lowercase					,					eos_token_id=lowercase				)
							A__						=	hidden_size
							A__						=	feat_extract_norm
							A__						=	feat_extract_activation
							A__						=	list(lowercase				)
							A__						=	list(lowercase				)
							A__						=	list(lowercase				)
							A__						=	conv_bias
							A__						=	num_conv_pos_embeddings
							A__						=	num_conv_pos_embedding_groups
							A__						=	len(self.conv_dim				)
							A__						=	num_hidden_layers
							A__						=	intermediate_size
							A__						=	hidden_act
							A__						=	num_attention_heads
							A__						=	hidden_dropout
							A__						=	attention_dropout
							A__						=	activation_dropout
							A__						=	feat_proj_dropout
							A__						=	final_dropout
							A__						=	layerdrop
							A__						=	layer_norm_eps
							A__						=	initializer_range
							A__						=	vocab_size
							A__						=	do_stable_layer_norm
							A__						=	use_weighted_layer_sum

							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
							A__						=	apply_spec_augment
							A__						=	mask_time_prob
							A__						=	mask_time_length
							A__						=	mask_time_min_masks
							A__						=	mask_feature_prob
							A__						=	mask_feature_length
							A__						=	mask_feature_min_masks

							# parameters for pretraining with codevector quantized representations
							A__						=	num_codevectors_per_group
							A__						=	num_codevector_groups
							A__						=	contrastive_logits_temperature
							A__						=	feat_quantizer_dropout
							A__						=	num_negatives
							A__						=	codevector_dim
							A__						=	proj_codevector_dim
							A__						=	diversity_loss_weight

							# ctc loss
							A__						=	ctc_loss_reduction
							A__						=	ctc_zero_infinity

							# adapter
							A__						=	add_adapter
							A__						=	adapter_kernel_size
							A__						=	adapter_stride
							A__						=	num_adapter_layers
							A__						=	output_hidden_size or hidden_size
							A__						=	adapter_attn_dim

							# SequenceClassification-specific parameter. Feel free to ignore for other classes.
							A__						=	classifier_proj_size

							# XVector-specific parameters. Feel free to ignore for other classes.
							A__						=	list(lowercase				)
							A__						=	list(lowercase				)
							A__						=	list(lowercase				)
							A__						=	xvector_output_dim


			@property
			def    UpperCamelCase						(			self				)     ->  Any:
							'''simple docstring'''






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





import unittest

from transformers.testing_utils import require_bsa
from transformers.utils import is_bsa_available

from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin


if is_bsa_available():
						from transformers import MarkupLMFeatureExtractor
class        _lowercase      (			unittest.TestCase       ):






				'''simple docstring'''



				def __init__(       self			:Optional[Any]			,			lowerCAmelCase__			:Optional[Any]	)		->			str:
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		parent



				def 		__magic_name__(       self			:List[Any]	)		->			Tuple:
										return {}




def        _UpperCamelCase							(      ):
						__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		'''<HTML>

    <HEAD>
    <TITLE>sample document</TITLE>
    </HEAD>

    <BODY BGCOLOR="FFFFFF">
    <HR>
    <a href="http://google.com">Goog</a>
    <H1>This is one header</H1>
    <H2>This is a another Header</H2>
    <P>Travel from
        <P>
        <B>SFO to JFK</B>
        <BR>
        <B><I>on May 2, 2015 at 2:00 pm. For details go to confirm.com </I></B>
        <HR>
        <div style="color:#0000FF">
            <h3>Traveler <b> name </b> is
            <p> John Doe </p>
        </div>'''

						__SCREAMING_SNAKE_CASE						:     str					=		'''
    <!DOCTYPE html>
    <html>
    <body>

    <h1>My First Heading</h1>
    <p>My first paragraph.</p>

    </body>
    </html>
    '''

						return [html_string_a, html_string_a]
@require_bsa
class        _lowercase      (			A__						,			unittest.TestCase       ):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__				:			Optional[int]						=		MarkupLMFeatureExtractor if is_bsa_available() else None


				def 		__magic_name__(       self			:int	)		->			Optional[Any]:
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		MarkupLMFeatureExtractionTester(self	)


				@property
				def 		__magic_name__(       self			:Any	)		->			Optional[Any]:
										return self.feature_extract_tester.prepare_feat_extract_dict()



				def 		__magic_name__(       self			:Optional[int]	)		->			Any:
										# Initialize feature_extractor
										__SCREAMING_SNAKE_CASE						:     int					=		self.feature_extraction_class()

										# Test not batched input
										__SCREAMING_SNAKE_CASE						:     Tuple					=		get_html_strings()[0]
										__SCREAMING_SNAKE_CASE						:     Dict					=		feature_extractor(lowerCAmelCase__	)

										# fmt: off
										__SCREAMING_SNAKE_CASE						:     str					=		[['''sample document''', '''Goog''', '''This is one header''', '''This is a another Header''', '''Travel from''', '''SFO to JFK''', '''on May 2, 2015 at 2:00 pm. For details go to confirm.com''', '''Traveler''', '''name''', '''is''', '''John Doe''']]
										__SCREAMING_SNAKE_CASE						:     List[str]					=		[['''/html/head/title''', '''/html/body/a''', '''/html/body/h1''', '''/html/body/h2''', '''/html/body/p''', '''/html/body/p/p/b[1]''', '''/html/body/p/p/b[2]/i''', '''/html/body/p/p/div/h3''', '''/html/body/p/p/div/h3/b''', '''/html/body/p/p/div/h3''', '''/html/body/p/p/div/h3/p''']]
										# fmt: on

										self.assertEqual(encoding.nodes			,			lowerCAmelCase__	)
										self.assertEqual(encoding.xpaths			,			lowerCAmelCase__	)

										# Test batched
										__SCREAMING_SNAKE_CASE						:     Tuple					=		get_html_strings()
										__SCREAMING_SNAKE_CASE						:     Dict					=		feature_extractor(lowerCAmelCase__	)

										# fmt: off
										__SCREAMING_SNAKE_CASE						:     int					=		expected_nodes + [['''My First Heading''', '''My first paragraph.''']]
										__SCREAMING_SNAKE_CASE						:     str					=		expected_xpaths + [['''/html/body/h1''', '''/html/body/p''']]

										self.assertEqual(len(encoding.nodes	)			,			2	)
										self.assertEqual(len(encoding.xpaths	)			,			2	)

										self.assertEqual(encoding.nodes			,			lowerCAmelCase__	)
										self.assertEqual(encoding.xpaths			,			lowerCAmelCase__	)
