'''simple docstring'''






import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin







class lowercase_       (		A__    ,    unittest.TestCase			):







   """simple docstring"""

   __lowerCAmelCase         =   ProphetNetTokenizer
   __lowerCAmelCase         =   False
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Optional[Any]:
        super().setUp()

        _A    		=  [
            '[UNK]',
            '[CLS]',
            '[SEP]',
            '[PAD]',
            '[MASK]',
            'want',
            '##want',
            '##ed',
            'wa',
            'un',
            'runn',
            '##ing',
            ',',
            'low',
            'lowest',
        ]
        _A    		=  os.path.join(self.tmpdirname, VOCAB_FILES_NAMES['vocab_file']     )
        with open(self.vocab_file, 'w', encoding='utf-8'     ) as vocab_writer:
             vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]     )     )
   def 	__UpperCAmelCase   (      self      :			Any, UpperCamelCase__      :			str     )  ->			Any:
        _A    		=  'UNwant\u00E9d,running'
        _A    		=  'unwanted, running'
        return input_text, output_text
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Tuple:
        _A    		=  self.tokenizer_class(self.vocab_file     )

        _A    		=  tokenizer.tokenize('UNwant\u00E9d,running'     )
        self.assertListEqual(_lowerCamelCase, ['un', '##want', '##ed', ',', 'runn', '##ing']     )
        self.assertListEqual(tokenizer.convert_tokens_to_ids(_lowerCamelCase     ), [9, 6, 7, 12, 10, 11]     )
   def 	__UpperCAmelCase   (      self      :			Any     )  ->			List[str]:
        _A    		=  BasicTokenizer()

        self.assertListEqual(tokenizer.tokenize('ah\u535A\u63A8zz'     ), ['ah', '\u535A', '\u63A8', 'zz']     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Dict:
        _A    		=  BasicTokenizer(do_lower_case=_lowerCamelCase     )

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '     ), ['hello', '!', 'how', 'are', 'you', '?']     )
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     ), ['hello']     )
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			int:
        _A    		=  BasicTokenizer(do_lower_case=_lowerCamelCase, strip_accents=_lowerCamelCase     )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     ), ['hällo', '!', 'how', 'are', 'you', '?']     )
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     ), ['h\u00E9llo']     )
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Union[str, Any]:
        _A    		=  BasicTokenizer(do_lower_case=_lowerCamelCase, strip_accents=_lowerCamelCase     )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     ), ['hallo', '!', 'how', 'are', 'you', '?']     )
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     ), ['hello']     )
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			Any:
        _A    		=  BasicTokenizer(do_lower_case=_lowerCamelCase     )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     ), ['hallo', '!', 'how', 'are', 'you', '?']     )
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'     ), ['hello']     )
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			Union[str, Any]:
        _A    		=  BasicTokenizer(do_lower_case=_lowerCamelCase     )

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '     ), ['HeLLo', '!', 'how', 'Are', 'yoU', '?']     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Optional[int]:
        _A    		=  BasicTokenizer(do_lower_case=_lowerCamelCase, strip_accents=_lowerCamelCase     )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     ), ['HäLLo', '!', 'how', 'Are', 'yoU', '?']     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Union[str, Any]:
        _A    		=  BasicTokenizer(do_lower_case=_lowerCamelCase, strip_accents=_lowerCamelCase     )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '     ), ['HaLLo', '!', 'how', 'Are', 'yoU', '?']     )
   def 	__UpperCAmelCase   (      self      :			Any     )  ->			List[Any]:
        _A    		=  BasicTokenizer(do_lower_case=_lowerCamelCase, never_split=['[UNK]']     )

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo!how  \n Are yoU? [UNK]'     ), ['HeLLo', '!', 'how', 'Are', 'yoU', '?', '[UNK]']     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Dict:
        _A    		=  ['[UNK]', '[CLS]', '[SEP]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing']

        _A    		=  {}
        for i, token in enumerate(_lowerCamelCase     ):
             _A    		=  i
        _A    		=  WordpieceTokenizer(vocab=_lowerCamelCase, unk_token='[UNK]'     )

        self.assertListEqual(tokenizer.tokenize(''     ), []     )

        self.assertListEqual(tokenizer.tokenize('unwanted running'     ), ['un', '##want', '##ed', 'runn', '##ing']     )

        self.assertListEqual(tokenizer.tokenize('unwantedX running'     ), ['[UNK]', 'runn', '##ing']     )
   @require_torch
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Optional[int]:
        _A    		=  self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'     )

        _A    		=  ['A long paragraph for summarization.', 'Another paragraph for summarization.']
        _A    		=  [10_37, 21_46, 2_04_23, 20_05, 76_80, 78_49, 39_89, 10_12, 1_02]
        _A    		=  tokenizer(_lowerCamelCase, padding=_lowerCamelCase, return_tensors='pt'     )
        self.assertIsInstance(_lowerCamelCase, _lowerCamelCase     )
        _A    		=  list(batch.input_ids.numpy()[0]     )
        self.assertListEqual(_lowerCamelCase, _lowerCamelCase     )

        self.assertEqual((2, 9), batch.input_ids.shape     )
        self.assertEqual((2, 9), batch.attention_mask.shape     )
   def 	__UpperCAmelCase   (      self      :			int     )  ->			Optional[Any]:
        self.assertTrue(_is_whitespace(' '     )     )
        self.assertTrue(_is_whitespace('\t'     )     )
        self.assertTrue(_is_whitespace('\r'     )     )
        self.assertTrue(_is_whitespace('\n'     )     )
        self.assertTrue(_is_whitespace('\u00A0'     )     )

        self.assertFalse(_is_whitespace('A'     )     )
        self.assertFalse(_is_whitespace('-'     )     )
   def 	__UpperCAmelCase   (      self      :			Any     )  ->			int:
        self.assertTrue(_is_control('\u0005'     )     )

        self.assertFalse(_is_control('A'     )     )
        self.assertFalse(_is_control(' '     )     )
        self.assertFalse(_is_control('\t'     )     )
        self.assertFalse(_is_control('\r'     )     )
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Optional[int]:
        self.assertTrue(_is_punctuation('-'     )     )
        self.assertTrue(_is_punctuation('$'     )     )
        self.assertTrue(_is_punctuation('`'     )     )
        self.assertTrue(_is_punctuation('.'     )     )

        self.assertFalse(_is_punctuation('A'     )     )
        self.assertFalse(_is_punctuation(' '     )     )

   @slow
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			List[Any]:
        _A    		=  self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'     )

        _A    		=  tokenizer.encode('sequence builders', add_special_tokens=_lowerCamelCase     )
        _A    		=  tokenizer.encode('multi-sequence build', add_special_tokens=_lowerCamelCase     )

        _A    		=  tokenizer.build_inputs_with_special_tokens(_lowerCamelCase     )
        _A    		=  tokenizer.build_inputs_with_special_tokens(_lowerCamelCase, _lowerCamelCase     )

        assert encoded_sentence == text + [1_02]
        assert encoded_pair == text + [1_02] + text_a + [1_02]





"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__SCREAMING_SNAKE_CASE							=     logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							=     {
    'microsoft/focalnet-tiny': 'https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json',
}





class 				a__					(						A__   ,							A__       ):
     UpperCAmelCase__         =      '''focalnet'''



     def __init__(							self :Any      ,  _lowerCamelCase :List[Any]=224      ,  _lowerCamelCase :str=4      ,  _lowerCamelCase :List[str]=3      ,  _lowerCamelCase :Optional[Any]=96      ,  _lowerCamelCase :Dict=False      ,  _lowerCamelCase :Optional[Any]=[192, 384, 768, 768]      ,  _lowerCamelCase :Tuple=[2, 2, 6, 2]      ,  _lowerCamelCase :List[Any]=[2, 2, 2, 2]      ,  _lowerCamelCase :Optional[int]=[3, 3, 3, 3]      ,  _lowerCamelCase :Optional[Any]="gelu"      ,  _lowerCamelCase :Tuple=4.0      ,  _lowerCamelCase :Optional[Any]=0.0      ,  _lowerCamelCase :int=0.1      ,  _lowerCamelCase :List[str]=False      ,  _lowerCamelCase :str=1E-4      ,  _lowerCamelCase :Optional[int]=False      ,  _lowerCamelCase :List[str]=False      ,  _lowerCamelCase :str=False      ,  _lowerCamelCase :Optional[int]=0.02      ,  _lowerCamelCase :int=1E-5      ,  _lowerCamelCase :Tuple=32      ,  _lowerCamelCase :List[str]=None      ,  _lowerCamelCase :Dict=None      ,  **_lowerCamelCase :List[Any]      ,  ):







      '''simple docstring'''



      super().__init__(**_lowerCamelCase   )

      UpperCamelCase_     :					Any   	=image_size
      UpperCamelCase_     :					int   	=patch_size
      UpperCamelCase_     :					int   	=num_channels
      UpperCamelCase_     :					Union[str, Any]   	=embed_dim
      UpperCamelCase_     :					int   	=use_conv_embed
      UpperCamelCase_     :					Optional[int]   	=hidden_sizes
      UpperCamelCase_     :					str   	=depths
      UpperCamelCase_     :					Any   	=focal_levels
      UpperCamelCase_     :					List[str]   	=focal_windows
      UpperCamelCase_     :					str   	=hidden_act
      UpperCamelCase_     :					Dict   	=mlp_ratio
      UpperCamelCase_     :					List[str]   	=hidden_dropout_prob
      UpperCamelCase_     :					Optional[int]   	=drop_path_rate
      UpperCamelCase_     :					str   	=use_layerscale
      UpperCamelCase_     :					List[Any]   	=layerscale_value
      UpperCamelCase_     :					Optional[int]   	=use_post_layernorm
      UpperCamelCase_     :					Dict   	=use_post_layernorm_in_modulation
      UpperCamelCase_     :					Optional[Any]   	=normalize_modulator
      UpperCamelCase_     :					List[Any]   	=initializer_range
      UpperCamelCase_     :					List[str]   	=layer_norm_eps
      UpperCamelCase_     :					List[Any]   	=encoder_stride
      UpperCamelCase_     :					str   	=['stem'] + [f'''stage{idx}''' for idx in range(1      ,  len(self.depths   ) + 1   )]
      UpperCamelCase_	,     UpperCamelCase_     :					int   	=get_aligned_output_features_output_indices(
          out_features=_lowerCamelCase      ,  out_indices=_lowerCamelCase      ,  stage_names=self.stage_names   )
