






import functools
import operator

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


A__      :     Dict       =					logging.get_logger(__name__)

A__      :     Optional[Any]       =					{
    '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  _UpperCAmelCase   (			A__      ):

				"""simple docstring"""




				lowercase__											=			"""wavlm"""




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

								'''simple docstring'''
								super().__init__(**lowerCamelCase,    pad_token_id=lowerCamelCase,    bos_token_id=lowerCamelCase,    eos_token_id=lowerCamelCase    )
								lowercase__  					=     hidden_size
								lowercase__  					=     feat_extract_norm
								lowercase__  					=     feat_extract_activation
								lowercase__  					=     list(lowerCamelCase    )
								lowercase__  					=     list(lowerCamelCase    )
								lowercase__  					=     list(lowerCamelCase    )
								lowercase__  					=     conv_bias
								lowercase__  					=     num_buckets
								lowercase__  					=     max_bucket_distance
								lowercase__  					=     num_conv_pos_embeddings
								lowercase__  					=     num_conv_pos_embedding_groups
								lowercase__  					=     len(self.conv_dim    )
								lowercase__  					=     num_hidden_layers
								lowercase__  					=     intermediate_size
								lowercase__  					=     hidden_act
								lowercase__  					=     num_attention_heads
								lowercase__  					=     hidden_dropout
								lowercase__  					=     attention_dropout
								lowercase__  					=     activation_dropout
								lowercase__  					=     feat_proj_dropout
								lowercase__  					=     final_dropout
								lowercase__  					=     layerdrop
								lowercase__  					=     layer_norm_eps
								lowercase__  					=     initializer_range
								lowercase__  					=     num_ctc_classes
								lowercase__  					=     vocab_size
								lowercase__  					=     do_stable_layer_norm
								lowercase__  					=     use_weighted_layer_sum
								lowercase__  					=     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
								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

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

								# ctc loss
								lowercase__  					=     ctc_loss_reduction
								lowercase__  					=     ctc_zero_infinity

								# adapter
								lowercase__  					=     add_adapter
								lowercase__  					=     adapter_kernel_size
								lowercase__  					=     adapter_stride
								lowercase__  					=     num_adapter_layers
								lowercase__  					=     output_hidden_size or hidden_size

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

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




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

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












import os
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
							from .tokenization_pegasus import PegasusTokenizer
else:
							A__      :     Optional[Any]       =					None


A__      :     str       =					logging.get_logger(__name__)


A__      :     Optional[int]       =					'▁'

A__      :     List[str]       =					{'vocab_file': 'spiece.model', 'tokenizer_file': 'tokenizer.json'}

A__      :     Dict       =					{
    'vocab_file': {'google/pegasus-xsum': 'https://huggingface.co/google/pegasus-xsum/resolve/main/spiece.model'},
    'tokenizer_file': {
        'google/pegasus-xsum': 'https://huggingface.co/google/pegasus-xsum/resolve/main/tokenizer.json'
    },
}

A__      :     int       =					{
    'google/pegasus-xsum': 5_12,
}
class  _UpperCAmelCase   (			A__      ):

				"""simple docstring"""




				lowercase__											=			VOCAB_FILES_NAMES
				lowercase__											=			PRETRAINED_VOCAB_FILES_MAP
				lowercase__											=			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowercase__											=			PegasusTokenizer
				lowercase__											=			["""input_ids""", """attention_mask"""]




				def __init__(	self		:       Dict,    lowerCamelCase		:       str=None,    lowerCamelCase		:       List[str]=None,    lowerCamelCase		:       int="<pad>",    lowerCamelCase		:       str="</s>",    lowerCamelCase		:       Optional[Any]="<unk>",    lowerCamelCase		:       Any="<mask_2>",    lowerCamelCase		:       Optional[Any]="<mask_1>",    lowerCamelCase		:       int=None,    lowerCamelCase		:       Dict=103,    **lowerCamelCase		:       List[Any],    ):

								'''simple docstring'''
								lowercase__  					=     offset

								if additional_special_tokens is not None:
												if not isinstance(lowerCamelCase,    lowerCamelCase    ):
																raise TypeError(
																    F"""additional_special_tokens should be of type {type(lowerCamelCase    )}, but is"""
																    F""" {type(lowerCamelCase    )}"""    )

												lowercase__  					=     (
												    ([mask_token_sent] + additional_special_tokens)
												    if mask_token_sent not in additional_special_tokens and mask_token_sent is not None
												    else additional_special_tokens
												)
												# fill additional tokens with ..., <unk_token_102> in case not all additional tokens are already taken
												additional_special_tokens_extended += [
												    F"""<unk_{i}>""" for i in range(len(lowerCamelCase    ),    self.offset - 1    )
												]

												if len(set(lowerCamelCase    )    ) != len(lowerCamelCase    ):
																raise ValueError(
																    '''Please make sure that the provided additional_special_tokens do not contain an incorrectly'''
																    F""" shifted list of <unk_x> tokens. Found {additional_special_tokens_extended}."""    )
												lowercase__  					=     additional_special_tokens_extended
								else:
												lowercase__  					=     [mask_token_sent] if mask_token_sent is not None else []
												additional_special_tokens += [F"""<unk_{i}>""" for i in range(2,    self.offset    )]

								super().__init__(
								    lowerCamelCase,    tokenizer_file=lowerCamelCase,    pad_token=lowerCamelCase,    eos_token=lowerCamelCase,    unk_token=lowerCamelCase,    mask_token=lowerCamelCase,    mask_token_sent=lowerCamelCase,    offset=lowerCamelCase,    additional_special_tokens=lowerCamelCase,    **lowerCamelCase,    )
								lowercase__  					=     vocab_file
								lowercase__  					=     False if not self.vocab_file else True




				def 							lowercase__  (	self		:       Optional[Any],    lowerCamelCase		:       int    ):

								'''simple docstring'''
								lowercase__  					=     set(self.all_special_ids    )  # call it once instead of inside list comp
								all_special_ids.remove(self.unk_token_id    )  # <unk> is only sometimes special

								if all_special_ids != set(range(len(self.additional_special_tokens    ) + 3    )    ):
												raise ValueError(
												    '''There should be 3 special tokens: mask_token, pad_token, and eos_token +'''
												    F""" {len(self.additional_special_tokens    )} additional_special_tokens, but got {all_special_ids}"""    )

								return [1 if x in all_special_ids else 0 for x in seq]




				def 							lowercase__  (	self		:       Optional[Any],    lowerCamelCase		:       List,    lowerCamelCase		:       Optional[List] = None,    lowerCamelCase		:       bool = False    ):

								'''simple docstring'''
								if already_has_special_tokens:
												return self._special_token_mask(lowerCamelCase    )
								elif token_ids_a is None:
												return self._special_token_mask(lowerCamelCase    ) + [1]
								else:
												return self._special_token_mask(token_ids_a + token_ids_a    ) + [1]




				def 							lowercase__  (	self		:       Optional[Any],    lowerCamelCase		:       Optional[int],    lowerCamelCase		:       Optional[Any]=None    ):

								'''simple docstring'''
								if token_ids_a is None:
												return token_ids_a + [self.eos_token_id]
								# We don't expect to process pairs, but leave the pair logic for API consistency
								return token_ids_a + token_ids_a + [self.eos_token_id]




				def 							lowercase__  (	self		:       Optional[Any],    lowerCamelCase		:       str,    lowerCamelCase		:       Optional[str] = None    ):

								'''simple docstring'''
								if not self.can_save_slow_tokenizer:
												raise ValueError(
												    '''Your fast tokenizer does not have the necessary information to save the vocabulary for a slow '''
												    '''tokenizer.'''    )

								if not os.path.isdir(lowerCamelCase    ):
												logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""    )
												return
								lowercase__  					=     os.path.join(
								    lowerCamelCase,    (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']    )

								if os.path.abspath(self.vocab_file    ) != os.path.abspath(lowerCamelCase    ):
												copyfile(self.vocab_file,    lowerCamelCase    )

								return (out_vocab_file,)




