
"""simple docstring"""





import functools
import operator

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


UpperCamelCase_       :    Dict						      =			logging.get_logger(__name__)

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




			"""simple docstring"""







			snake_case						   =					"unispeech"




			def __init__(					self    :       Union[str, Any]							, _snake_case    :       Dict=32							, _snake_case    :       Optional[Any]=768							, _snake_case    :       Optional[Any]=12							, _snake_case    :       int=12							, _snake_case    :       Optional[int]=3_072							, _snake_case    :       int="gelu"							, _snake_case    :       Union[str, Any]=0.1							, _snake_case    :       Optional[int]=0.1							, _snake_case    :       Dict=0.1							, _snake_case    :       List[str]=0.0							, _snake_case    :       List[Any]=0.0							, _snake_case    :       List[Any]=0.1							, _snake_case    :       int=0.1							, _snake_case    :       Optional[Any]=0.0_2							, _snake_case    :       List[Any]=1e-5							, _snake_case    :       int="group"							, _snake_case    :       Optional[int]="gelu"							, _snake_case    :       Any=(512, 512, 512, 512, 512, 512, 512)							, _snake_case    :       Union[str, Any]=(5, 2, 2, 2, 2, 2, 2)							, _snake_case    :       Dict=(10, 3, 3, 3, 3, 2, 2)							, _snake_case    :       List[str]=False							, _snake_case    :       Any=128							, _snake_case    :       Tuple=16							, _snake_case    :       Optional[int]=False							, _snake_case    :       List[str]=True							, _snake_case    :       Any=0.0_5							, _snake_case    :       Any=10							, _snake_case    :       Optional[int]=2							, _snake_case    :       Tuple=0.0							, _snake_case    :       Any=10							, _snake_case    :       str=0							, _snake_case    :       List[str]=320							, _snake_case    :       int=2							, _snake_case    :       List[Any]=0.1							, _snake_case    :       Optional[int]=100							, _snake_case    :       List[Any]=256							, _snake_case    :       Optional[Any]=256							, _snake_case    :       Optional[Any]=0.1							, _snake_case    :       int="mean"							, _snake_case    :       Dict=False							, _snake_case    :       Tuple=False							, _snake_case    :       Dict=256							, _snake_case    :       Union[str, Any]=80							, _snake_case    :       List[str]=0							, _snake_case    :       List[Any]=1							, _snake_case    :       List[Any]=2							, _snake_case    :       Union[str, Any]=0.5							, **_snake_case    :       Union[str, Any]							, )   ->			Union[str, Any]:







								"""simple docstring"""
								super().__init__(**_snake_case							, pad_token_id=_snake_case							, bos_token_id=_snake_case							, eos_token_id=_snake_case						)
								A_								=    hidden_size
								A_								=    feat_extract_norm
								A_								=    feat_extract_activation
								A_								=    list(_snake_case						)
								A_								=    list(_snake_case						)
								A_								=    list(_snake_case						)
								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_								=    num_ctc_classes
								A_								=    vocab_size
								A_								=    do_stable_layer_norm
								A_								=    use_weighted_layer_sum
								A_								=    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
								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

								# pretraining loss
								A_								=    replace_prob






			@property
			def   lowerCamelCase__  (					self    :       List[Any]						)   ->			Dict:







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






"""simple docstring"""





import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad



class __lowerCAmelCase					(       unittest.TestCase   ):




			"""simple docstring"""







			def   lowerCamelCase__  (					self    :       Optional[int]						)   ->			List[str]:







								"""simple docstring"""
								A_								=    10




			def   lowerCamelCase__  (					self    :       Union[str, Any]						)   ->			Union[str, Any]:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4]
								A_								=    [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       List[str]						)   ->			List[Any]:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       str						)   ->			Dict:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       Dict						)   ->			Dict:







								"""simple docstring"""
								A_								=    "It was the year of Our Lord one thousand seven hundred and\n        seventy-five.\n\nSpiritual revelations were conceded to England at that\n        favoured period, as at this."
								A_			,     A_								=    process_story(_snake_case						)
								self.assertEqual(_snake_case							, []						)




			def   lowerCamelCase__  (					self    :       str						)   ->			str:







								"""simple docstring"""
								A_								=    ""
								A_			,     A_								=    process_story(_snake_case						)
								self.assertEqual(_snake_case							, []						)
								self.assertEqual(_snake_case							, []						)




			def   lowerCamelCase__  (					self    :       Tuple						)   ->			Optional[Any]:







								"""simple docstring"""
								A_								=    (
								    "It was the year of Our Lord one thousand seven hundred and "
								    "seventy-five\n\nSpiritual revelations were conceded to England "
								    "at that favoured period, as at this.\n@highlight\n\nIt was the best of times"
								)
								A_			,     A_								=    process_story(_snake_case						)

								A_								=    [
								    "It was the year of Our Lord one thousand seven hundred and seventy-five.",
								    "Spiritual revelations were conceded to England at that favoured period, as at this.",
								]
								self.assertEqual(_snake_case							, _snake_case						)

								A_								=    ["It was the best of times."]
								self.assertEqual(_snake_case							, _snake_case						)




			def   lowerCamelCase__  (					self    :       List[str]						)   ->			Optional[Any]:







								"""simple docstring"""
								A_								=    torch.tensor([1, 2, 3, 4]						)
								A_								=    torch.tensor([1, 1, 1, 1]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 0						).numpy()							, expected.numpy()						)




			def   lowerCamelCase__  (					self    :       List[Any]						)   ->			Optional[int]:







								"""simple docstring"""
								A_								=    torch.tensor([1, 2, 3, 4, 23, 23, 23]						)
								A_								=    torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 23						).numpy()							, expected.numpy()						)




			def   lowerCamelCase__  (					self    :       str						)   ->			Union[str, Any]:







								"""simple docstring"""
								A_								=    torch.tensor([8, 2, 3, 4, 1, 1, 1]						)
								A_								=    torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 1						).numpy()							, expected.numpy()						)






			def   lowerCamelCase__  (					self    :       int						)   ->			List[str]:







								"""simple docstring"""
								A_								=    101
								A_								=    torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]						)
								A_								=    torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]						)

								A_								=    compute_token_type_ids(_snake_case							, _snake_case						)
								np.testing.assert_array_equal(_snake_case							, _snake_case						)




