import collections.abc
from typing import Optional, Tuple, Union

import torch
import torch.utils.checkpoint
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_poolformer import PoolFormerConfig


__a:			Optional[Any]	       =       logging.get_logger(__name__)

# General docstring
__a:			List[Any]	       =       """PoolFormerConfig"""

# Base docstring
__a:			Dict	       =       """sail/poolformer_s12"""
__a:			int	       =       [1, 5_12, 7, 7]

# Image classification docstring
__a:			str	       =       """sail/poolformer_s12"""
__a:			Dict	       =       """tabby, tabby cat"""

__a:			List[Any]	       =       [
    """sail/poolformer_s12""",
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
]
def       __UpperCamelCase	(       UpperCAmelCase		,					UpperCAmelCase = 0.0		,					UpperCAmelCase = False					):





 if drop_prob == 0.0 or not training:
  return input
 lowercase__    :   Tuple						= 1 - drop_prob
 lowercase__    :   Union[str, Any]						= (input.shape[0],) + (1,) * (input.ndim - 1)  # work with diff dim tensors, not just 2D ConvNets
 lowercase__    :   Any						= keep_prob + torch.rand(lowercase_		,					dtype=input.dtype		,					device=input.device					)
 random_tensor.floor_()  # binarize
 lowercase__    :   Dict						= input.div(lowercase_					) * random_tensor
 return output



class       UpperCAmelCase  (						nn.Module ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase = None			)  ->  None:
        super().__init__()
        lowercase__    :   List[Any]						= drop_prob

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  torch.Tensor:
        return drop_path(__lowerCAmelCase     ,       self.drop_prob     ,       self.training			)


       def _lowerCAmelCase(						self			)  ->  str:
        return "p={}".format(self.drop_prob			)



class       UpperCAmelCase  (						nn.Module ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase=None			)  ->  Union[str, Any]:
        super().__init__()
        lowercase__    :   Any						= patch_size if isinstance(__lowerCAmelCase     ,       collections.abc.Iterable			) else (patch_size, patch_size)
        lowercase__    :   List[str]						= stride if isinstance(__lowerCAmelCase     ,       collections.abc.Iterable			) else (stride, stride)
        lowercase__    :   List[Any]						= padding if isinstance(__lowerCAmelCase     ,       collections.abc.Iterable			) else (padding, padding)

        lowercase__    :   str						= nn.Convad(__lowerCAmelCase     ,       __lowerCAmelCase     ,       kernel_size=__lowerCAmelCase     ,       stride=__lowerCAmelCase     ,       padding=__lowerCAmelCase			)
        lowercase__    :   str						= norm_layer(__lowerCAmelCase			) if norm_layer else nn.Identity()


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  Any:
        lowercase__    :   int						= self.projection(__lowerCAmelCase			)
        lowercase__    :   Any						= self.norm(__lowerCAmelCase			)
        return embeddings



class       UpperCAmelCase  (						nn.GroupNorm ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase     ,       **__lowerCAmelCase			)  ->  Optional[Any]:
        super().__init__(1     ,       __lowerCAmelCase     ,       **__lowerCAmelCase			)



class       UpperCAmelCase  (						nn.Module ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase			)  ->  Any:
        super().__init__()
        lowercase__    :   List[str]						= nn.AvgPoolad(__lowerCAmelCase     ,       stride=1     ,       padding=pool_size // 2     ,       count_include_pad=__lowerCAmelCase			)


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  int:
        return self.pool(__lowerCAmelCase			) - hidden_states



class       UpperCAmelCase  (						nn.Module ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase			)  ->  Union[str, Any]:
        super().__init__()
        lowercase__    :   Union[str, Any]						= nn.Convad(__lowerCAmelCase     ,       __lowerCAmelCase     ,       1			)
        lowercase__    :   Dict						= nn.Convad(__lowerCAmelCase     ,       __lowerCAmelCase     ,       1			)
        lowercase__    :   Tuple						= PoolFormerDropPath(__lowerCAmelCase			)
        if isinstance(config.hidden_act     ,       __lowerCAmelCase			):
         lowercase__    :   Union[str, Any]						= ACTaFN[config.hidden_act]
        else:
         lowercase__    :   str						= config.hidden_act


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  List[str]:
        lowercase__    :   Any						= self.conva(__lowerCAmelCase			)
        lowercase__    :   Union[str, Any]						= self.act_fn(__lowerCAmelCase			)
        lowercase__    :   List[Any]						= self.drop(__lowerCAmelCase			)
        lowercase__    :   List[Any]						= self.conva(__lowerCAmelCase			)
        lowercase__    :   Optional[Any]						= self.drop(__lowerCAmelCase			)

        return hidden_states



class       UpperCAmelCase  (						nn.Module ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase			)  ->  Union[str, Any]:
        super().__init__()
        lowercase__    :   Any						= PoolFormerPooling(__lowerCAmelCase			)
        lowercase__    :   Tuple						= PoolFormerOutput(__lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase     ,       __lowerCAmelCase			)
        lowercase__    :   int						= PoolFormerGroupNorm(__lowerCAmelCase			)
        lowercase__    :   int						= PoolFormerGroupNorm(__lowerCAmelCase			)

        # Useful for training neural nets
        lowercase__    :   int						= PoolFormerDropPath(__lowerCAmelCase			) if drop_path > 0.0 else nn.Identity()
        lowercase__    :   Union[str, Any]						= config.use_layer_scale
        if config.use_layer_scale:
         lowercase__    :   Optional[Any]						= nn.Parameter(
             config.layer_scale_init_value * torch.ones((__lowerCAmelCase)			)     ,       requires_grad=__lowerCAmelCase			)
         lowercase__    :   Optional[int]						= nn.Parameter(
             config.layer_scale_init_value * torch.ones((__lowerCAmelCase)			)     ,       requires_grad=__lowerCAmelCase			)


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  Optional[int]:
        if self.use_layer_scale:
         lowercase__    :   List[str]						= self.pooling(self.before_norm(__lowerCAmelCase			)			)
         lowercase__    :   int						= self.layer_scale_a.unsqueeze(-1			).unsqueeze(-1			) * pooling_output
         # First residual connection
         lowercase__    :   Union[str, Any]						= hidden_states + self.drop_path(__lowerCAmelCase			)
         lowercase__    :   Dict						= ()

         lowercase__    :   Optional[int]						= self.output(self.after_norm(__lowerCAmelCase			)			)
         lowercase__    :   List[str]						= self.layer_scale_a.unsqueeze(-1			).unsqueeze(-1			) * layer_output
         # Second residual connection
         lowercase__    :   Any						= hidden_states + self.drop_path(__lowerCAmelCase			)

         lowercase__    :   Tuple						= (output,) + outputs
         return outputs

        else:
         lowercase__    :   str						= self.drop_path(self.pooling(self.before_norm(__lowerCAmelCase			)			)			)
         # First residual connection
         lowercase__    :   Any						= pooling_output + hidden_states
         lowercase__    :   str						= ()

         # Second residual connection inside the PoolFormerOutput block
         lowercase__    :   Union[str, Any]						= self.drop_path(self.output(self.after_norm(__lowerCAmelCase			)			)			)
         lowercase__    :   Optional[Any]						= hidden_states + layer_output

         lowercase__    :   Dict						= (output,) + outputs
         return outputs



class       UpperCAmelCase  (						nn.Module ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase			)  ->  Optional[Any]:
        super().__init__()
        lowercase__    :   Any						= config
        # stochastic depth decay rule
        lowercase__    :   int						= [x.item() for x in torch.linspace(0     ,       config.drop_path_rate     ,       sum(config.depths			)			)]

        # patch embeddings
        lowercase__    :   Optional[int]						= []
        for i in range(config.num_encoder_blocks			):
         embeddings.append(
             PoolFormerEmbeddings(
                 patch_size=config.patch_sizes[i]     ,       stride=config.strides[i]     ,       padding=config.padding[i]     ,       num_channels=config.num_channels if i == 0 else config.hidden_sizes[i - 1]     ,       hidden_size=config.hidden_sizes[i]     ,       )			)
        lowercase__    :   Optional[Any]						= nn.ModuleList(__lowerCAmelCase			)

        # Transformer blocks
        lowercase__    :   List[str]						= []
        lowercase__    :   List[str]						= 0
        for i in range(config.num_encoder_blocks			):
         # each block consists of layers
         lowercase__    :   str						= []
         if i != 0:
          cur += config.depths[i - 1]
         for j in range(config.depths[i]			):
          layers.append(
              PoolFormerLayer(
                  __lowerCAmelCase     ,       num_channels=config.hidden_sizes[i]     ,       pool_size=config.pool_size     ,       hidden_size=config.hidden_sizes[i]     ,       intermediate_size=int(config.hidden_sizes[i] * config.mlp_ratio			)     ,       drop_path=dpr[cur + j]     ,       )			)
         blocks.append(nn.ModuleList(__lowerCAmelCase			)			)

        lowercase__    :   List[str]						= nn.ModuleList(__lowerCAmelCase			)


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase=False     ,       __lowerCAmelCase=True			)  ->  Union[str, Any]:
        lowercase__    :   Union[str, Any]						= () if output_hidden_states else None

        lowercase__    :   Union[str, Any]						= pixel_values
        for idx, layers in enumerate(zip(self.patch_embeddings     ,       self.block			)			):
         lowercase__			,							lowercase__    :   str						= layers
         # Get patch embeddings from hidden_states
         lowercase__    :   Dict						= embedding_layer(__lowerCAmelCase			)
         # Send the embeddings through the blocks
         for _, blk in enumerate(__lowerCAmelCase			):
          lowercase__    :   Dict						= blk(__lowerCAmelCase			)
          lowercase__    :   Any						= layer_outputs[0]

         if output_hidden_states:
          lowercase__    :   Optional[int]						= all_hidden_states + (hidden_states,)

        if not return_dict:
         return tuple(v for v in [hidden_states, all_hidden_states] if v is not None			)

        return BaseModelOutputWithNoAttention(last_hidden_state=__lowerCAmelCase     ,       hidden_states=__lowerCAmelCase			)



class       UpperCAmelCase  (						__snake_case ):





       '''simple docstring'''



       SCREAMING_SNAKE_CASE 		=   PoolFormerConfig
       SCREAMING_SNAKE_CASE 		=   'poolformer'
       SCREAMING_SNAKE_CASE 		=   'pixel_values'
       SCREAMING_SNAKE_CASE 		=   True

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  List[str]:
        if isinstance(__lowerCAmelCase     ,       (nn.Linear, nn.Convad)			):
         module.weight.data.normal_(mean=0.0     ,       std=self.config.initializer_range			)
         if module.bias is not None:
          module.bias.data.zero_()
        elif isinstance(__lowerCAmelCase     ,       nn.LayerNorm			):
         module.bias.data.zero_()
         module.weight.data.fill_(1.0			)


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase     ,       __lowerCAmelCase=False			)  ->  Any:
        if isinstance(__lowerCAmelCase     ,       __lowerCAmelCase			):
         lowercase__    :   Optional[Any]						= value


__a:			Any	       =       R"""
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use
    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`PoolFormerConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
"""

__a:			Union[str, Any]	       =       R"""
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`PoolFormerImageProcessor.__call__`] for details.
"""



@add_start_docstrings(
    "The bare PoolFormer Model transformer outputting raw hidden-states without any specific head on top."   ,						__snake_case   ,						)
class       UpperCAmelCase  (						__snake_case ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase			)  ->  int:
        super().__init__(__lowerCAmelCase			)
        lowercase__    :   str						= config

        lowercase__    :   Any						= PoolFormerEncoder(__lowerCAmelCase			)

        # Initialize weights and apply final processing
        self.post_init()

       def _lowerCAmelCase(						self			)  ->  List[str]:
        return self.embeddings.patch_embeddings


       @add_start_docstrings_to_model_forward(__lowerCAmelCase			)
       @add_code_sample_docstrings(
           checkpoint=_CHECKPOINT_FOR_DOC     ,       output_type=__lowerCAmelCase     ,       config_class=_CONFIG_FOR_DOC     ,       modality='''vision'''     ,       expected_output=_EXPECTED_OUTPUT_SHAPE     ,       )
       def _lowerCAmelCase(						self     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       )  ->  Union[Tuple, BaseModelOutputWithNoAttention]:
        lowercase__    :   Tuple						= (
            output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
        )
        lowercase__    :   Optional[Any]						= return_dict if return_dict is not None else self.config.use_return_dict

        if pixel_values is None:
         raise ValueError('''You have to specify pixel_values'''			)

        lowercase__    :   Any						= self.encoder(
            __lowerCAmelCase     ,       output_hidden_states=__lowerCAmelCase     ,       return_dict=__lowerCAmelCase     ,       )
        lowercase__    :   Optional[Any]						= encoder_outputs[0]

        if not return_dict:
         return (sequence_output, None) + encoder_outputs[1:]

        return BaseModelOutputWithNoAttention(
            last_hidden_state=__lowerCAmelCase     ,       hidden_states=encoder_outputs.hidden_states     ,       )



class       UpperCAmelCase  (						nn.Module ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase			)  ->  Optional[int]:
        super().__init__()
        lowercase__    :   Any						= nn.Linear(config.hidden_size     ,       config.hidden_size			)


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  Tuple:
        lowercase__    :   List[Any]						= self.dense(__lowerCAmelCase			)
        return output



@add_start_docstrings(
    "\n    PoolFormer Model transformer with an image classification head on top\n    "   ,						__snake_case   ,						)
class       UpperCAmelCase  (						__snake_case ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase			)  ->  Optional[Any]:
        super().__init__(__lowerCAmelCase			)
        lowercase__    :   str						= config.num_labels
        lowercase__    :   Optional[Any]						= PoolFormerModel(__lowerCAmelCase			)

        # Final norm
        lowercase__    :   int						= PoolFormerGroupNorm(config.hidden_sizes[-1]			)
        # Classifier head
        lowercase__    :   str						= (
            nn.Linear(config.hidden_sizes[-1]     ,       config.num_labels			) if config.num_labels > 0 else nn.Identity()
        )

        # Initialize weights and apply final processing
        self.post_init()


       @add_start_docstrings_to_model_forward(__lowerCAmelCase			)
       @add_code_sample_docstrings(
           checkpoint=_IMAGE_CLASS_CHECKPOINT     ,       output_type=__lowerCAmelCase     ,       config_class=_CONFIG_FOR_DOC     ,       expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT     ,       )
       def _lowerCAmelCase(						self     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       __lowerCAmelCase = None     ,       )  ->  Union[Tuple, ImageClassifierOutputWithNoAttention]:
        lowercase__    :   Dict						= return_dict if return_dict is not None else self.config.use_return_dict

        lowercase__    :   Optional[Any]						= self.poolformer(
            __lowerCAmelCase     ,       output_hidden_states=__lowerCAmelCase     ,       return_dict=__lowerCAmelCase     ,       )

        lowercase__    :   Union[str, Any]						= outputs[0]

        lowercase__    :   str						= self.classifier(self.norm(__lowerCAmelCase			).mean([-2, -1]			)			)

        lowercase__    :   Any						= None
        if labels is not None:
         if self.config.problem_type is None:
          if self.num_labels == 1:
           lowercase__    :   str						= '''regression'''
          elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
           lowercase__    :   int						= '''single_label_classification'''
          else:
           lowercase__    :   Union[str, Any]						= '''multi_label_classification'''

         if self.config.problem_type == "regression":
          lowercase__    :   Union[str, Any]						= MSELoss()
          if self.num_labels == 1:
           lowercase__    :   Optional[Any]						= loss_fct(logits.squeeze()     ,       labels.squeeze()			)
          else:
           lowercase__    :   Optional[Any]						= loss_fct(__lowerCAmelCase     ,       __lowerCAmelCase			)
         elif self.config.problem_type == "single_label_classification":
          lowercase__    :   List[Any]						= CrossEntropyLoss()
          lowercase__    :   List[str]						= loss_fct(logits.view(-1     ,       self.num_labels			)     ,       labels.view(-1			)			)
         elif self.config.problem_type == "multi_label_classification":
          lowercase__    :   List[Any]						= BCEWithLogitsLoss()
          lowercase__    :   List[Any]						= loss_fct(__lowerCAmelCase     ,       __lowerCAmelCase			)

        if not return_dict:
         lowercase__    :   str						= (logits,) + outputs[2:]
         return ((loss,) + output) if loss is not None else output

        return ImageClassifierOutputWithNoAttention(loss=__lowerCAmelCase     ,       logits=__lowerCAmelCase     ,       hidden_states=outputs.hidden_states			)


'''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       UpperCAmelCase  (						a__   ,						unittest.TestCase ):





       '''simple docstring'''



       SCREAMING_SNAKE_CASE 		=   ProphetNetTokenizer
       SCREAMING_SNAKE_CASE 		=   False

       def _lowerCAmelCase(						self			)  ->  Any:
        super().setUp()

        lowercase__    :   Tuple						= [
            '''[UNK]''',
            '''[CLS]''',
            '''[SEP]''',
            '''[PAD]''',
            '''[MASK]''',
            '''want''',
            '''##want''',
            '''##ed''',
            '''wa''',
            '''un''',
            '''runn''',
            '''##ing''',
            ''',''',
            '''low''',
            '''lowest''',
        ]
        lowercase__    :   List[str]						= 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 _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  str:
        lowercase__    :   Union[str, Any]						= '''UNwant\u00E9d,running'''
        lowercase__    :   List[Any]						= '''unwanted, running'''
        return input_text, output_text

       def _lowerCAmelCase(						self			)  ->  Any:
        lowercase__    :   List[str]						= self.tokenizer_class(self.vocab_file			)

        lowercase__    :   Union[str, Any]						= 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 _lowerCAmelCase(						self			)  ->  List[str]:
        lowercase__    :   List[str]						= BasicTokenizer()

        self.assertListEqual(tokenizer.tokenize('''ah\u535A\u63A8zz'''			)     ,       ['''ah''', '''\u535A''', '''\u63A8''', '''zz''']			)

       def _lowerCAmelCase(						self			)  ->  Tuple:
        lowercase__    :   List[Any]						= 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 _lowerCAmelCase(						self			)  ->  Union[str, Any]:
        lowercase__    :   Optional[int]						= 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 _lowerCAmelCase(						self			)  ->  Tuple:
        lowercase__    :   str						= 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 _lowerCAmelCase(						self			)  ->  int:
        lowercase__    :   Union[str, Any]						= 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 _lowerCAmelCase(						self			)  ->  List[Any]:
        lowercase__    :   int						= BasicTokenizer(do_lower_case=__lowerCAmelCase			)

        self.assertListEqual(
            tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU?  '''			)     ,       ['''HeLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']			)

       def _lowerCAmelCase(						self			)  ->  List[str]:
        lowercase__    :   Tuple						= BasicTokenizer(do_lower_case=__lowerCAmelCase     ,       strip_accents=__lowerCAmelCase			)

        self.assertListEqual(
            tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''			)     ,       ['''HäLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']			)

       def _lowerCAmelCase(						self			)  ->  Any:
        lowercase__    :   Tuple						= BasicTokenizer(do_lower_case=__lowerCAmelCase     ,       strip_accents=__lowerCAmelCase			)

        self.assertListEqual(
            tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''			)     ,       ['''HaLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']			)

       def _lowerCAmelCase(						self			)  ->  Optional[int]:
        lowercase__    :   Optional[int]						= BasicTokenizer(do_lower_case=__lowerCAmelCase     ,       never_split=['''[UNK]''']			)

        self.assertListEqual(
            tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU? [UNK]'''			)     ,       ['''HeLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''', '''[UNK]''']			)

       def _lowerCAmelCase(						self			)  ->  int:
        lowercase__    :   Union[str, Any]						= ['''[UNK]''', '''[CLS]''', '''[SEP]''', '''want''', '''##want''', '''##ed''', '''wa''', '''un''', '''runn''', '''##ing''']

        lowercase__    :   Union[str, Any]						= {}
        for i, token in enumerate(__lowerCAmelCase			):
         lowercase__    :   List[Any]						= i
        lowercase__    :   Dict						= 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 _lowerCAmelCase(						self			)  ->  Union[str, Any]:
        lowercase__    :   Union[str, Any]						= self.tokenizer_class.from_pretrained('''microsoft/prophetnet-large-uncased'''			)

        lowercase__    :   Optional[int]						= ['''A long paragraph for summarization.''', '''Another paragraph for summarization.''']
        lowercase__    :   Dict						= [1037, 2146, 20423, 2005, 7680, 7849, 3989, 1012, 102]
        lowercase__    :   int						= tokenizer(__lowerCAmelCase     ,       padding=__lowerCAmelCase     ,       return_tensors='''pt'''			)
        self.assertIsInstance(__lowerCAmelCase     ,       __lowerCAmelCase			)
        lowercase__    :   Optional[int]						= 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 _lowerCAmelCase(						self			)  ->  str:
        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 _lowerCAmelCase(						self			)  ->  Optional[Any]:
        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 _lowerCAmelCase(						self			)  ->  Dict:
        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 _lowerCAmelCase(						self			)  ->  Optional[Any]:
        lowercase__    :   List[Any]						= self.tokenizer_class.from_pretrained('''microsoft/prophetnet-large-uncased'''			)

        lowercase__    :   List[str]						= tokenizer.encode('''sequence builders'''     ,       add_special_tokens=__lowerCAmelCase			)
        lowercase__    :   Optional[int]						= tokenizer.encode('''multi-sequence build'''     ,       add_special_tokens=__lowerCAmelCase			)

        lowercase__    :   Tuple						= tokenizer.build_inputs_with_special_tokens(__lowerCAmelCase			)
        lowercase__    :   List[str]						= tokenizer.build_inputs_with_special_tokens(__lowerCAmelCase     ,       __lowerCAmelCase			)

        assert encoded_sentence == text + [102]
        assert encoded_pair == text + [102] + text_a + [102]

