






'''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    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE       ,unittest.TestCase	):
			__a							:							int					     =					ProphetNetTokenizer
			__a							:							Dict					     =					False






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

									'''simple docstring'''







									super().setUp()

									UpperCamelCase__         = [
									    """[UNK]""",
									    """[CLS]""",
									    """[SEP]""",
									    """[PAD]""",
									    """[MASK]""",
									    """want""",
									    """##want""",
									    """##ed""",
									    """wa""",
									    """un""",
									    """runn""",
									    """##ing""",
									    """,""",
									    """low""",
									    """lowest""",
									]
									UpperCamelCase__         = 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 				A      (   self							:						Optional[Any] ,      lowercase							:						Union[str, Any]			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = """UNwant\u00E9d,running"""
									UpperCamelCase__         = """unwanted, running"""
									return input_text, output_text






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

									'''simple docstring'''







									UpperCamelCase__         = self.tokenizer_class(self.vocab_file			)

									UpperCamelCase__         = tokenizer.tokenize("""UNwant\u00E9d,running"""			)
									self.assertListEqual(lowercase ,      ["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]			)
									self.assertListEqual(tokenizer.convert_tokens_to_ids(lowercase			) ,      [9, 6, 7, 1_2, 1_0, 1_1]			)






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

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer()

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






			def 				A      (   self							:						str			)							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase			)

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """			) ,      ["""hello""", """!""", """how""", """are""", """you""", """?"""]			)
									self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""			) ,      ["""hello"""]			)






			def 				A      (   self							:						Dict			)							->    Dict:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      strip_accents=lowercase			)

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """			) ,      ["""hällo""", """!""", """how""", """are""", """you""", """?"""]			)
									self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""			) ,      ["""h\u00E9llo"""]			)






			def 				A      (   self							:						List[Any]			)							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      strip_accents=lowercase			)

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """			) ,      ["""hallo""", """!""", """how""", """are""", """you""", """?"""]			)
									self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""			) ,      ["""hello"""]			)






			def 				A      (   self							:						List[Any]			)							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase			)

									self.assertListEqual(
									    tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """			) ,      ["""hallo""", """!""", """how""", """are""", """you""", """?"""]			)
									self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""			) ,      ["""hello"""]			)






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

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase			)

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






			def 				A      (   self							:						List[str]			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      strip_accents=lowercase			)

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






			def 				A      (   self							:						Dict			)							->    Dict:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      strip_accents=lowercase			)

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






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

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      never_split=["""[UNK]"""]			)

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






			def 				A      (   self							:						Tuple			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = ["""[UNK]""", """[CLS]""", """[SEP]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing"""]

									UpperCamelCase__         = {}
									for i, token in enumerate(lowercase			):
															UpperCamelCase__         = i
									UpperCamelCase__         = WordpieceTokenizer(vocab=lowercase ,      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 				A      (   self							:						Tuple			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""			)

									UpperCamelCase__         = ["""A long paragraph for summarization.""", """Another paragraph for summarization."""]
									UpperCamelCase__         = [1_0_3_7, 2_1_4_6, 2_0_4_2_3, 2_0_0_5, 7_6_8_0, 7_8_4_9, 3_9_8_9, 1_0_1_2, 1_0_2]
									UpperCamelCase__         = tokenizer(lowercase ,      padding=lowercase ,      return_tensors="""pt"""			)
									self.assertIsInstance(lowercase ,      lowercase			)
									UpperCamelCase__         = list(batch.input_ids.numpy()[0]			)
									self.assertListEqual(lowercase ,      lowercase			)

									self.assertEqual((2, 9) ,      batch.input_ids.shape			)
									self.assertEqual((2, 9) ,      batch.attention_mask.shape			)






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

									'''simple docstring'''







									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 				A      (   self							:						List[Any]			)							->    Union[str, Any]:

									'''simple docstring'''







									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 				A      (   self							:						Optional[Any]			)							->    Union[str, Any]:

									'''simple docstring'''







									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 				A      (   self							:						List[Any]			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""			)

									UpperCamelCase__         = tokenizer.encode("""sequence builders""" ,      add_special_tokens=lowercase			)
									UpperCamelCase__         = tokenizer.encode("""multi-sequence build""" ,      add_special_tokens=lowercase			)

									UpperCamelCase__         = tokenizer.build_inputs_with_special_tokens(lowercase			)
									UpperCamelCase__         = tokenizer.build_inputs_with_special_tokens(lowercase ,      lowercase			)

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








'''simple docstring'''


import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


lowerCamelCase_				: str    	=							logging.get_logger(__name__)

lowerCamelCase_				: Optional[int]    	=							{
    '''SenseTime/deformable-detr''': '''https://huggingface.co/sensetime/deformable-detr/resolve/main/config.json''',
    # See all Deformable DETR models at https://huggingface.co/models?filter=deformable-detr
}
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			__a							:							Tuple					     =					"deformable_detr"
			__a							:							str					     =					{
			    "hidden_size": "d_model",
			    "num_attention_heads": "encoder_attention_heads",
			}






			def __init__(   self							:						List[Any] ,      lowercase							:						List[Any]=True ,      lowercase							:						Tuple=None ,      lowercase							:						Tuple=3 ,      lowercase							:						List[str]=3_0_0 ,      lowercase							:						List[Any]=1_0_2_4 ,      lowercase							:						List[Any]=6 ,      lowercase							:						Tuple=1_0_2_4 ,      lowercase							:						Union[str, Any]=8 ,      lowercase							:						Optional[Any]=6 ,      lowercase							:						Tuple=1_0_2_4 ,      lowercase							:						Any=8 ,      lowercase							:						List[str]=0.0 ,      lowercase							:						Any=True ,      lowercase							:						Union[str, Any]="relu" ,      lowercase							:						Dict=2_5_6 ,      lowercase							:						Optional[int]=0.1 ,      lowercase							:						Optional[int]=0.0 ,      lowercase							:						List[str]=0.0 ,      lowercase							:						Any=0.0_2 ,      lowercase							:						Optional[int]=1.0 ,      lowercase							:						Tuple=True ,      lowercase							:						Optional[int]=False ,      lowercase							:						Any="sine" ,      lowercase							:						List[str]="resnet50" ,      lowercase							:						List[str]=True ,      lowercase							:						Optional[int]=False ,      lowercase							:						int=4 ,      lowercase							:						str=4 ,      lowercase							:						Dict=4 ,      lowercase							:						int=False ,      lowercase							:						List[Any]=3_0_0 ,      lowercase							:						List[Any]=False ,      lowercase							:						Dict=1 ,      lowercase							:						int=5 ,      lowercase							:						List[Any]=2 ,      lowercase							:						List[str]=1 ,      lowercase							:						Tuple=1 ,      lowercase							:						Dict=5 ,      lowercase							:						Dict=2 ,      lowercase							:						Dict=0.1 ,      lowercase							:						List[str]=0.2_5 ,      lowercase							:						Tuple=False ,      **lowercase							:						str ,      )							->    str:

									'''simple docstring'''







									if backbone_config is not None and use_timm_backbone:
															raise ValueError("""You can't specify both `backbone_config` and `use_timm_backbone`."""			)

									if not use_timm_backbone:
															if backbone_config is None:
																					logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""			)
																					UpperCamelCase__         = CONFIG_MAPPING["""resnet"""](out_features=["""stage4"""]			)
															elif isinstance(lowercase ,      lowercase			):
																					UpperCamelCase__         = backbone_config.get("""model_type"""			)
																					UpperCamelCase__         = CONFIG_MAPPING[backbone_model_type]
																					UpperCamelCase__         = config_class.from_dict(lowercase			)
									UpperCamelCase__         = use_timm_backbone
									UpperCamelCase__         = backbone_config
									UpperCamelCase__         = num_channels
									UpperCamelCase__         = num_queries
									UpperCamelCase__         = max_position_embeddings
									UpperCamelCase__         = d_model
									UpperCamelCase__         = encoder_ffn_dim
									UpperCamelCase__         = encoder_layers
									UpperCamelCase__         = encoder_attention_heads
									UpperCamelCase__         = decoder_ffn_dim
									UpperCamelCase__         = decoder_layers
									UpperCamelCase__         = decoder_attention_heads
									UpperCamelCase__         = dropout
									UpperCamelCase__         = attention_dropout
									UpperCamelCase__         = activation_dropout
									UpperCamelCase__         = activation_function
									UpperCamelCase__         = init_std
									UpperCamelCase__         = init_xavier_std
									UpperCamelCase__         = encoder_layerdrop
									UpperCamelCase__         = auxiliary_loss
									UpperCamelCase__         = position_embedding_type
									UpperCamelCase__         = backbone
									UpperCamelCase__         = use_pretrained_backbone
									UpperCamelCase__         = dilation
									# deformable attributes
									UpperCamelCase__         = num_feature_levels
									UpperCamelCase__         = encoder_n_points
									UpperCamelCase__         = decoder_n_points
									UpperCamelCase__         = two_stage
									UpperCamelCase__         = two_stage_num_proposals
									UpperCamelCase__         = with_box_refine
									if two_stage is True and with_box_refine is False:
															raise ValueError("""If two_stage is True, with_box_refine must be True."""			)
									# Hungarian matcher
									UpperCamelCase__         = class_cost
									UpperCamelCase__         = bbox_cost
									UpperCamelCase__         = giou_cost
									# Loss coefficients
									UpperCamelCase__         = mask_loss_coefficient
									UpperCamelCase__         = dice_loss_coefficient
									UpperCamelCase__         = bbox_loss_coefficient
									UpperCamelCase__         = giou_loss_coefficient
									UpperCamelCase__         = eos_coefficient
									UpperCamelCase__         = focal_alpha
									UpperCamelCase__         = disable_custom_kernels
									super().__init__(is_encoder_decoder=lowercase ,      **lowercase			)






			@property
			def 				A      (   self							:						str			)							->    int:

									'''simple docstring'''







									return self.encoder_attention_heads






			@property
			def 				A      (   self							:						Tuple			)							->    int:

									'''simple docstring'''







									return self.d_model







			def 				A      (   self							:						Dict			)							->    Optional[Any]:

									'''simple docstring'''







									UpperCamelCase__         = copy.deepcopy(self.__dict__			)
									if self.backbone_config is not None:
															UpperCamelCase__         = self.backbone_config.to_dict()
									UpperCamelCase__         = self.__class__.model_type
									return output
