






"""simple docstring"""






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


UpperCAmelCase_   : Optional[int]   			= logging.get_logger(__name__)

UpperCAmelCase_   : int   			= {
    """speechbrain/m-ctc-t-large""": """https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json""",
    # See all M-CTC-T models at https://huggingface.co/models?filter=mctct
}




class 							lowerCAmelCase__				(			UpperCAmelCase__ ):






      '''simple docstring'''

      __UpperCamelCase	 =  "mctct"
      def __init__(						self     :  Union[str, Any]						,	lowercase_     :  str=8065						,	lowercase_     :  Optional[Any]=1536						,	lowercase_     :  str=36						,	lowercase_     :  List[str]=6144						,	lowercase_     :  Optional[Any]=4						,	lowercase_     :  Optional[Any]=384						,	lowercase_     :  Tuple=920						,	lowercase_     :  Any=1e-5						,	lowercase_     :  Optional[Any]=0.3						,	lowercase_     :  Any="relu"						,	lowercase_     :  Any=0.02						,	lowercase_     :  Dict=0.3						,	lowercase_     :  int=0.3						,	lowercase_     :  Union[str, Any]=1						,	lowercase_     :  Union[str, Any]=0						,	lowercase_     :  Union[str, Any]=2						,	lowercase_     :  Union[str, Any]=1						,	lowercase_     :  List[str]=0.3						,	lowercase_     :  Optional[int]=1						,	lowercase_     :  Dict=(7,)						,	lowercase_     :  Union[str, Any]=(3,)						,	lowercase_     :  Tuple=80						,	lowercase_     :  Union[str, Any]=1						,	lowercase_     :  Any=None						,	lowercase_     :  Any="sum"						,	lowercase_     :  List[Any]=False						,	**lowercase_     :  Any						,	):




          '''simple docstring'''


          super().__init__(**lowercase_						,	pad_token_id=lowercase_						,	bos_token_id=lowercase_						,	eos_token_id=lowercase_)
          SCREAMING_SNAKE_CASE_      :  str    						=		vocab_size
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		hidden_size
          SCREAMING_SNAKE_CASE_      :  int    						=		num_hidden_layers
          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		intermediate_size
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		num_attention_heads
          SCREAMING_SNAKE_CASE_      :  Any    						=		attention_head_dim
          SCREAMING_SNAKE_CASE_      :  int    						=		max_position_embeddings
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		layer_norm_eps
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		layerdrop
          SCREAMING_SNAKE_CASE_      :  str    						=		hidden_act
          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		initializer_range
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		hidden_dropout_prob
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		attention_probs_dropout_prob
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		pad_token_id
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		bos_token_id
          SCREAMING_SNAKE_CASE_      :  int    						=		eos_token_id
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		conv_glu_dim
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		conv_dropout
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		num_conv_layers
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		input_feat_per_channel
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		input_channels
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		conv_channels
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		ctc_loss_reduction
          SCREAMING_SNAKE_CASE_      :  str    						=		ctc_zero_infinity

          # prevents config testing fail with exporting to json
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		list(lowercase_)
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		list(lowercase_)

          if len(self.conv_kernel) != self.num_conv_layers:
              raise ValueError(
                  '''Configuration for convolutional module is incorrect. '''
                  '''It is required that `len(config.conv_kernel)` == `config.num_conv_layers` '''
                  F'but is `len(config.conv_kernel) = {len(self.conv_kernel)}`, '
                  F'`config.num_conv_layers = {self.num_conv_layers}`.')









"""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      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Dict											=							1_0






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Optional[int]											=							[1, 2, 3, 4]
         lowerCAmelCase__			:Tuple											=							[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
         self.assertEqual(truncate_or_pad(__UpperCAmelCase    , self.block_size    , 0      )    , __UpperCAmelCase      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Optional[Any]											=							[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0]
         lowerCAmelCase__			:List[Any]											=							[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0]
         self.assertEqual(truncate_or_pad(__UpperCAmelCase    , self.block_size    , 0      )    , __UpperCAmelCase      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Dict											=							[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0, 1_1, 1_2, 1_3]
         lowerCAmelCase__			:List[Any]											=							[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0]
         self.assertEqual(truncate_or_pad(__UpperCAmelCase    , self.block_size    , 0      )    , __UpperCAmelCase      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Tuple											=							'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.'
         lowerCAmelCase__							,				lowerCAmelCase__			:List[Any]											=							process_story(__UpperCAmelCase      )
         self.assertEqual(__UpperCAmelCase    , []      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Any											=							''
         lowerCAmelCase__							,				lowerCAmelCase__			:Any											=							process_story(__UpperCAmelCase      )
         self.assertEqual(__UpperCAmelCase    , []      )
         self.assertEqual(__UpperCAmelCase    , []      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:List[str]											=							(
             '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'
         )
         lowerCAmelCase__							,				lowerCAmelCase__			:str											=							process_story(__UpperCAmelCase      )

         lowerCAmelCase__			:List[str]											=							[
             '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(__UpperCAmelCase    , __UpperCAmelCase      )

         lowerCAmelCase__			:List[str]											=							['It was the best of times.']
         self.assertEqual(__UpperCAmelCase    , __UpperCAmelCase      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Tuple											=							torch.tensor([1, 2, 3, 4]      )
         lowerCAmelCase__			:List[str]											=							torch.tensor([1, 1, 1, 1]      )
         np.testing.assert_array_equal(build_mask(__UpperCAmelCase    , 0      ).numpy()    , expected.numpy()      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:List[Any]											=							torch.tensor([1, 2, 3, 4, 2_3, 2_3, 2_3]      )
         lowerCAmelCase__			:Optional[int]											=							torch.tensor([1, 1, 1, 1, 0, 0, 0]      )
         np.testing.assert_array_equal(build_mask(__UpperCAmelCase    , 2_3      ).numpy()    , expected.numpy()      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:List[Any]											=							torch.tensor([8, 2, 3, 4, 1, 1, 1]      )
         lowerCAmelCase__			:Optional[Any]											=							torch.tensor([1, 1, 1, 1, 0, 0, 0]      )
         np.testing.assert_array_equal(build_mask(__UpperCAmelCase    , 1      ).numpy()    , expected.numpy()      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Optional[Any]											=							1_0_1
         lowerCAmelCase__			:str											=							torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 1_0_1, 5, 6], [1, 1_0_1, 3, 4, 1_0_1, 6]]      )
         lowerCAmelCase__			:Any											=							torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]      )

         lowerCAmelCase__			:List[Any]											=							compute_token_type_ids(__UpperCAmelCase    , __UpperCAmelCase      )
         np.testing.assert_array_equal(__UpperCAmelCase    , __UpperCAmelCase      )
