'''simple docstring'''
import functools
import operator

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


a=  logging.get_logger(__name__)

a=  {
    '''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 			__lowercase		(						_lowerCamelCase						):







     """simple docstring"""






     SCREAMING_SNAKE_CASE__		   =						'''wav2vec2'''







     def __init__(		self     ,			_lowerCamelCase=3_2     ,			_lowerCamelCase=7_6_8     ,			_lowerCamelCase=1_2     ,			_lowerCamelCase=1_2     ,			_lowerCamelCase=3_0_7_2     ,			_lowerCamelCase="gelu"     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.0     ,			_lowerCamelCase=0.0     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=0.0_2     ,			_lowerCamelCase=1E-5     ,			_lowerCamelCase="group"     ,			_lowerCamelCase="gelu"     ,			_lowerCamelCase=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)     ,			_lowerCamelCase=(5, 2, 2, 2, 2, 2, 2)     ,			_lowerCamelCase=(1_0, 3, 3, 3, 3, 2, 2)     ,			_lowerCamelCase=False     ,			_lowerCamelCase=1_2_8     ,			_lowerCamelCase=1_6     ,			_lowerCamelCase=False     ,			_lowerCamelCase=True     ,			_lowerCamelCase=0.0_5     ,			_lowerCamelCase=1_0     ,			_lowerCamelCase=2     ,			_lowerCamelCase=0.0     ,			_lowerCamelCase=1_0     ,			_lowerCamelCase=0     ,			_lowerCamelCase=3_2_0     ,			_lowerCamelCase=2     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase=1_0_0     ,			_lowerCamelCase=2_5_6     ,			_lowerCamelCase=2_5_6     ,			_lowerCamelCase=0.1     ,			_lowerCamelCase="sum"     ,			_lowerCamelCase=False     ,			_lowerCamelCase=False     ,			_lowerCamelCase=2_5_6     ,			_lowerCamelCase=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 1_5_0_0)     ,			_lowerCamelCase=(5, 3, 3, 1, 1)     ,			_lowerCamelCase=(1, 2, 3, 1, 1)     ,			_lowerCamelCase=5_1_2     ,			_lowerCamelCase=0     ,			_lowerCamelCase=1     ,			_lowerCamelCase=2     ,			_lowerCamelCase=False     ,			_lowerCamelCase=3     ,			_lowerCamelCase=2     ,			_lowerCamelCase=3     ,			_lowerCamelCase=None     ,			_lowerCamelCase=None     ,			**_lowerCamelCase     ,			):
         super().__init__(**_lowerCamelCase     ,			pad_token_id=_lowerCamelCase     ,			bos_token_id=_lowerCamelCase     ,			eos_token_id=_lowerCamelCase    )
         __UpperCamelCase	:	Optional[int]		    =  hidden_size
         __UpperCamelCase	:	Optional[Any]		    =  feat_extract_norm
         __UpperCamelCase	:	int		    =  feat_extract_activation
         __UpperCamelCase	:	List[Any]		    =  list(_lowerCamelCase    )
         __UpperCamelCase	:	int		    =  list(_lowerCamelCase    )
         __UpperCamelCase	:	int		    =  list(_lowerCamelCase    )
         __UpperCamelCase	:	List[Any]		    =  conv_bias
         __UpperCamelCase	:	List[Any]		    =  num_conv_pos_embeddings
         __UpperCamelCase	:	str		    =  num_conv_pos_embedding_groups
         __UpperCamelCase	:	List[str]		    =  len(self.conv_dim    )
         __UpperCamelCase	:	str		    =  num_hidden_layers
         __UpperCamelCase	:	str		    =  intermediate_size
         __UpperCamelCase	:	List[str]		    =  hidden_act
         __UpperCamelCase	:	Optional[Any]		    =  num_attention_heads
         __UpperCamelCase	:	Optional[int]		    =  hidden_dropout
         __UpperCamelCase	:	Tuple		    =  attention_dropout
         __UpperCamelCase	:	Any		    =  activation_dropout
         __UpperCamelCase	:	List[Any]		    =  feat_proj_dropout
         __UpperCamelCase	:	List[str]		    =  final_dropout
         __UpperCamelCase	:	Union[str, Any]		    =  layerdrop
         __UpperCamelCase	:	str		    =  layer_norm_eps
         __UpperCamelCase	:	Union[str, Any]		    =  initializer_range
         __UpperCamelCase	:	str		    =  vocab_size
         __UpperCamelCase	:	str		    =  do_stable_layer_norm
         __UpperCamelCase	:	List[Any]		    =  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
         __UpperCamelCase	:	int		    =  apply_spec_augment
         __UpperCamelCase	:	Tuple		    =  mask_time_prob
         __UpperCamelCase	:	Tuple		    =  mask_time_length
         __UpperCamelCase	:	Optional[Any]		    =  mask_time_min_masks
         __UpperCamelCase	:	Optional[Any]		    =  mask_feature_prob
         __UpperCamelCase	:	str		    =  mask_feature_length
         __UpperCamelCase	:	Union[str, Any]		    =  mask_feature_min_masks

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

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

         # adapter
         __UpperCamelCase	:	List[Any]		    =  add_adapter
         __UpperCamelCase	:	Tuple		    =  adapter_kernel_size
         __UpperCamelCase	:	str		    =  adapter_stride
         __UpperCamelCase	:	List[str]		    =  num_adapter_layers
         __UpperCamelCase	:	List[Any]		    =  output_hidden_size or hidden_size
         __UpperCamelCase	:	Tuple		    =  adapter_attn_dim

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

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







     @property
     def lowerCAmelCase     (		self    ):
         return functools.reduce(operator.mul     ,			self.conv_stride     ,			1    )




'''simple docstring'''
import html

from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...utils import is_bsa_available, logging, requires_backends


if is_bsa_available():
  import bsa
  from bsa import BeautifulSoup


a=  logging.get_logger(__name__)






class 			__lowercase		(						_lowerCamelCase						):







     """simple docstring"""






     def __init__(		self     ,			**_lowerCamelCase    ):
         requires_backends(self     ,			['bs4']    )
         super().__init__(**_lowerCamelCase    )







     def lowerCAmelCase     (		self     ,			_lowerCamelCase    ):
         __UpperCamelCase	:	str		    =  []
         __UpperCamelCase	:	Dict		    =  []
         __UpperCamelCase	:	Union[str, Any]		    =  element if element.name else element.parent
         for parent in child.parents:  # type: bs4.element.Tag
             __UpperCamelCase	:	str		    =  parent.find_all(child.name     ,			recursive=_lowerCamelCase    )
             xpath_tags.append(child.name    )
             xpath_subscripts.append(
                 0 if 1 == len(_lowerCamelCase    ) else next(i for i, s in enumerate(_lowerCamelCase     ,			1    ) if s is child    )    )
             __UpperCamelCase	:	Union[str, Any]		    =  parent
         xpath_tags.reverse()
         xpath_subscripts.reverse()
         return xpath_tags, xpath_subscripts







     def lowerCAmelCase     (		self     ,			_lowerCamelCase    ):
         __UpperCamelCase	:	List[str]		    =  BeautifulSoup(_lowerCamelCase     ,			'html.parser'    )

         __UpperCamelCase	:	int		    =  []
         __UpperCamelCase	:	List[Any]		    =  []
         __UpperCamelCase	:	int		    =  []

         for element in html_code.descendants:
             if type(_lowerCamelCase    ) == bsa.element.NavigableString:
                 if type(element.parent    ) != bsa.element.Tag:
                     continue

                 __UpperCamelCase	:	Tuple		    =  html.unescape(_lowerCamelCase    ).strip()
                 if not text_in_this_tag:
                     continue

                 all_doc_strings.append(_lowerCamelCase    )

                 __UpperCamelCase    ,					__UpperCamelCase	:	Union[str, Any]		    =  self.xpath_soup(_lowerCamelCase    )
                 stringaxtag_seq.append(_lowerCamelCase    )
                 stringaxsubs_seq.append(_lowerCamelCase    )

         if len(_lowerCamelCase    ) != len(_lowerCamelCase    ):
             raise ValueError('Number of doc strings and xtags does not correspond'    )
         if len(_lowerCamelCase    ) != len(_lowerCamelCase    ):
             raise ValueError('Number of doc strings and xsubs does not correspond'    )

         return all_doc_strings, stringaxtag_seq, stringaxsubs_seq







     def lowerCAmelCase     (		self     ,			_lowerCamelCase     ,			_lowerCamelCase    ):
         __UpperCamelCase	:	Dict		    =  ''
         for tagname, subs in zip(_lowerCamelCase     ,			_lowerCamelCase    ):
             xpath += f"""/{tagname}"""
             if subs != 0:
                 xpath += f"""[{subs}]"""
         return xpath







     def __call__(		self     ,			_lowerCamelCase    ):
         __UpperCamelCase	:	List[Any]		    =  False

         # Check that strings has a valid type
         if isinstance(_lowerCamelCase     ,			_lowerCamelCase    ):
             __UpperCamelCase	:	List[str]		    =  True
         elif isinstance(_lowerCamelCase     ,			(list, tuple)    ):
             if len(_lowerCamelCase    ) == 0 or isinstance(html_strings[0]     ,			_lowerCamelCase    ):
                 __UpperCamelCase	:	Optional[int]		    =  True

         if not valid_strings:
             raise ValueError(
                 'HTML strings must of type `str`, `List[str]` (batch of examples), '
                 f"""but is of type {type(_lowerCamelCase    )}."""    )

         __UpperCamelCase	:	Dict		    =  bool(isinstance(_lowerCamelCase     ,			(list, tuple)    ) and (isinstance(html_strings[0]     ,			_lowerCamelCase    ))    )

         if not is_batched:
             __UpperCamelCase	:	Tuple		    =  [html_strings]

         # Get nodes + xpaths
         __UpperCamelCase	:	Tuple		    =  []
         __UpperCamelCase	:	Tuple		    =  []
         for html_string in html_strings:
             __UpperCamelCase    ,					__UpperCamelCase    ,					__UpperCamelCase	:	str		    =  self.get_three_from_single(_lowerCamelCase    )
             nodes.append(_lowerCamelCase    )
             __UpperCamelCase	:	Union[str, Any]		    =  []
             for node, tag_list, sub_list in zip(_lowerCamelCase     ,			_lowerCamelCase     ,			_lowerCamelCase    ):
                 __UpperCamelCase	:	Optional[Any]		    =  self.construct_xpath(_lowerCamelCase     ,			_lowerCamelCase    )
                 xpath_strings.append(_lowerCamelCase    )
             xpaths.append(_lowerCamelCase    )

         # return as Dict
         __UpperCamelCase	:	Optional[int]		    =  {'nodes': nodes, 'xpaths': xpaths}
         __UpperCamelCase	:	Union[str, Any]		    =  BatchFeature(data=_lowerCamelCase     ,			tensor_type=_lowerCamelCase    )

         return encoded_inputs



