





'''simple docstring'''

import copy

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


__lowerCamelCase : Any											=			logging.get_logger(__name__)

__lowerCamelCase : Any											=			{
    "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       UpperCAmelCase (						_lowercase  ):
  UpperCAmelCase					:	Dict 			=		'''deformable_detr'''
  UpperCAmelCase					:	List[str] 			=		{
      '''hidden_size''': '''d_model''',
      '''num_attention_heads''': '''encoder_attention_heads''',
  }




  def __init__(self      :	int							,			A__      :	Optional[Any]=True							,			A__      :	Tuple=None							,			A__      :	str=3							,			A__      :	Optional[Any]=3_0_0							,			A__      :	List[Any]=1_0_2_4							,			A__      :	str=6							,			A__      :	List[Any]=1_0_2_4							,			A__      :	Union[str, Any]=8							,			A__      :	str=6							,			A__      :	Dict=1_0_2_4							,			A__      :	List[str]=8							,			A__      :	Tuple=0.0							,			A__      :	Any=True							,			A__      :	List[str]="relu"							,			A__      :	Tuple=2_5_6							,			A__      :	List[str]=0.1							,			A__      :	List[Any]=0.0							,			A__      :	str=0.0							,			A__      :	str=0.0_2							,			A__      :	Tuple=1.0							,			A__      :	Union[str, Any]=True							,			A__      :	List[Any]=False							,			A__      :	Union[str, Any]="sine"							,			A__      :	Optional[Any]="resnet50"							,			A__      :	List[str]=True							,			A__      :	Tuple=False							,			A__      :	int=4							,			A__      :	Tuple=4							,			A__      :	List[Any]=4							,			A__      :	Any=False							,			A__      :	Any=3_0_0							,			A__      :	Optional[Any]=False							,			A__      :	str=1							,			A__      :	List[str]=5							,			A__      :	Dict=2							,			A__      :	Tuple=1							,			A__      :	int=1							,			A__      :	List[str]=5							,			A__      :	List[str]=2							,			A__      :	Tuple=0.1							,			A__      :	int=0.2_5							,			A__      :	Optional[Any]=False							,			**A__      :	Optional[Any]							,			)					-> Tuple:
      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."				)
              lowercase         = CONFIG_MAPPING["resnet"](out_features=["stage4"]				)
          elif isinstance(A__							,			A__				):
              lowercase         = backbone_config.get("model_type"				)
              lowercase         = CONFIG_MAPPING[backbone_model_type]
              lowercase         = config_class.from_dict(A__				)
      lowercase         = use_timm_backbone
      lowercase         = backbone_config
      lowercase         = num_channels
      lowercase         = num_queries
      lowercase         = max_position_embeddings
      lowercase         = d_model
      lowercase         = encoder_ffn_dim
      lowercase         = encoder_layers
      lowercase         = encoder_attention_heads
      lowercase         = decoder_ffn_dim
      lowercase         = decoder_layers
      lowercase         = decoder_attention_heads
      lowercase         = dropout
      lowercase         = attention_dropout
      lowercase         = activation_dropout
      lowercase         = activation_function
      lowercase         = init_std
      lowercase         = init_xavier_std
      lowercase         = encoder_layerdrop
      lowercase         = auxiliary_loss
      lowercase         = position_embedding_type
      lowercase         = backbone
      lowercase         = use_pretrained_backbone
      lowercase         = dilation
      # deformable attributes
      lowercase         = num_feature_levels
      lowercase         = encoder_n_points
      lowercase         = decoder_n_points
      lowercase         = two_stage
      lowercase         = two_stage_num_proposals
      lowercase         = 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
      lowercase         = class_cost
      lowercase         = bbox_cost
      lowercase         = giou_cost
      # Loss coefficients
      lowercase         = mask_loss_coefficient
      lowercase         = dice_loss_coefficient
      lowercase         = bbox_loss_coefficient
      lowercase         = giou_loss_coefficient
      lowercase         = eos_coefficient
      lowercase         = focal_alpha
      lowercase         = disable_custom_kernels
      super().__init__(is_encoder_decoder=A__							,			**A__				)




  @property
  def 				UpperCAmelCase__   (self      :	Tuple				)					-> int:
      return self.encoder_attention_heads




  @property
  def 				UpperCAmelCase__   (self      :	List[str]				)					-> int:
      return self.d_model





  def 				UpperCAmelCase__   (self      :	Optional[Any]				)					-> int:
      lowercase         = copy.deepcopy(self.__dict__				)
      if self.backbone_config is not None:
          lowercase         = self.backbone_config.to_dict()
      lowercase         = self.__class__.model_type
      return output











'''simple docstring'''

import datasets

from .evaluate import evaluate


__lowerCamelCase : Optional[Any]											=			"\\n@inproceedings{Rajpurkar2016SQuAD10,\n  title={SQuAD: 100, 000+ Questions for Machine Comprehension of Text},\n  author={Pranav Rajpurkar and Jian Zhang and Konstantin Lopyrev and Percy Liang},\n  booktitle={EMNLP},\n  year={2016}\n}\n"

__lowerCamelCase : Any											=			"\nThis metric wrap the official scoring script for version 1 of the Stanford Question Answering Dataset (SQuAD).\n\nStanford Question Answering Dataset (SQuAD) is a reading comprehension dataset, consisting of questions posed by\ncrowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text, or span,\nfrom the corresponding reading passage, or the question might be unanswerable.\n"

__lowerCamelCase : Union[str, Any]											=			"\nComputes SQuAD scores (F1 and EM).\nArgs:\n    predictions: List of question-answers dictionaries with the following key-values:\n        - 'id': id of the question-answer pair as given in the references (see below)\n        - 'prediction_text': the text of the answer\n    references: List of question-answers dictionaries with the following key-values:\n        - 'id': id of the question-answer pair (see above),\n        - 'answers': a Dict in the SQuAD dataset format\n            {\n                'text': list of possible texts for the answer, as a list of strings\n                'answer_start': list of start positions for the answer, as a list of ints\n            }\n            Note that answer_start values are not taken into account to compute the metric.\nReturns:\n    'exact_match': Exact match (the normalized answer exactly match the gold answer)\n    'f1': The F-score of predicted tokens versus the gold answer\nExamples:\n\n    >>> predictions = [{'prediction_text': '1976', 'id': '56e10a3be3433e1400422b22'}]\n    >>> references = [{'answers': {'answer_start': [97], 'text': ['1976']}, 'id': '56e10a3be3433e1400422b22'}]\n    >>> squad_metric = datasets.load_metric(\"squad\")\n    >>> results = squad_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'exact_match': 100.0, 'f1': 100.0}\n"

@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION			,       _KWARGS_DESCRIPTION  )
class       UpperCAmelCase (						datasets.Metric  ):




		def 				UpperCAmelCase__   (self      :	Union[str, Any]				)					-> Union[str, Any]:
						return datasets.MetricInfo(
						    description=_DESCRIPTION							,			citation=_CITATION							,			inputs_description=_KWARGS_DESCRIPTION							,			features=datasets.Features(
						        {
						            "predictions": {"id": datasets.Value("string"				), "prediction_text": datasets.Value("string"				)},
						            "references": {
						                "id": datasets.Value("string"				),
						                "answers": datasets.features.Sequence(
						                    {
						                        "text": datasets.Value("string"				),
						                        "answer_start": datasets.Value("int32"				),
						                    }				),
						            },
						        }				)							,			codebase_urls=["https://rajpurkar.github.io/SQuAD-explorer/"]							,			reference_urls=["https://rajpurkar.github.io/SQuAD-explorer/"]							,			)





		def 				UpperCAmelCase__   (self      :	List[str]							,			A__      :	List[Any]							,			A__      :	List[str]				)					-> str:
						lowercase         = {prediction["id"]: prediction["prediction_text"] for prediction in predictions}
						lowercase         = [
						    {
						        "paragraphs": [
						            {
						                "qas": [
						                    {
						                        "answers": [{"text": answer_text} for answer_text in ref["answers"]["text"]],
						                        "id": ref["id"],
						                    }
						                    for ref in references
						                ]
						            }
						        ]
						    }
						]
						lowercase         = evaluate(dataset=A__							,			predictions=A__				)
						return score




