


'''simple docstring'''





from copy import deepcopy
from unittest.case import TestCase

import pytest

from datasets.arrow_dataset import Dataset
from datasets.features import Audio, ClassLabel, Features, Image, Sequence, Value
from datasets.info import DatasetInfo
from datasets.tasks import (
    AudioClassification,
    AutomaticSpeechRecognition,
    ImageClassification,
    LanguageModeling,
    QuestionAnsweringExtractive,
    Summarization,
    TextClassification,
    task_template_from_dict,
)
from datasets.utils.py_utils import asdict


lowerCamelCase		=	{
    '''id''': '''5733be284776f41900661182''',
    '''title''': '''University_of_Notre_Dame''',
    '''context''': '''Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend "Venite Ad Me Omnes". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.''',
    '''question''': '''To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?''',
    '''answers''': {'''text''': ['''Saint Bernadette Soubirous'''], '''answer_start''': [515]},
}






@pytest.mark.parametrize(
    '''task_cls'''			,     [
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]			,     )
def   lowerCamelCase_					( _a ):




		"""simple docstring"""






		lowerCAmelCase__     :    List[Any]					  =      task_cls()
		lowerCAmelCase__     :    Any					  =      asdict(_UpperCAmelCase )
		lowerCAmelCase__     :    str					  =      task_template_from_dict(_UpperCAmelCase )
		assert task == reloaded





class       _a							:




	def 							UpperCAmelCase__(      self		:	Any	)-> Optional[Any]:
			lowerCAmelCase__     :    Union[str, Any]					  =      LanguageModeling(text_column='''input_text'''	)
			assert {"input_text": "text"} == task.column_mapping




	def 							UpperCAmelCase__(      self		:	Dict	)-> Union[str, Any]:
			lowerCAmelCase__     :    Optional[Any]					  =      Features({'''text''': Value('''string'''	)}	)
			lowerCAmelCase__     :    Dict					  =      {'''text_column''': '''input_text'''}
			lowerCAmelCase__     :    List[Any]					  =      LanguageModeling.from_dict(SCREAMING_SNAKE_CASE_	)
			assert "language-modeling" == task.task
			assert input_schema == task.input_schema





class       _a							(       lowerCamelCase__):




	def 							UpperCAmelCase__(      self		:	int	)-> List[str]:
			lowerCAmelCase__     :    int					  =      sorted(['''pos''', '''neg''']	)




	def 							UpperCAmelCase__(      self		:	Dict	)-> int:
			lowerCAmelCase__     :    str					  =      TextClassification(text_column='''input_text'''	,      label_column='''input_label'''	)
			self.assertDictEqual({'''input_text''': '''text''', '''input_label''': '''labels'''}	,      task.column_mapping	)




	def 							UpperCAmelCase__(      self		:	str	)-> Tuple:
			lowerCAmelCase__     :    List[str]					  =      Features({'''text''': Value('''string'''	)}	)
			# Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
			lowerCAmelCase__     :    Optional[int]					  =      Features({'''labels''': ClassLabel}	)
			lowerCAmelCase__     :    List[Any]					  =      {'''text_column''': '''input_text''', '''label_column''': '''input_labels'''}
			lowerCAmelCase__     :    Dict					  =      TextClassification.from_dict(SCREAMING_SNAKE_CASE_	)
			self.assertEqual('''text-classification'''	,      task.task	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.input_schema	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.label_schema	)




	def 							UpperCAmelCase__(      self		:	Union[str, Any]	)-> List[Any]:
			lowerCAmelCase__     :    Optional[Any]					  =      TextClassification(text_column='''input_text'''	,      label_column='''input_label'''	)
			self.assertEqual(task.label_schema['''labels''']	,      SCREAMING_SNAKE_CASE_	)
			lowerCAmelCase__     :    Tuple					  =      task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels	)}	)	)
			self.assertEqual(task.label_schema['''labels''']	,      ClassLabel(names=self.labels	)	)





class       _a							(       lowerCamelCase__):




	def 							UpperCAmelCase__(      self		:	List[Any]	)-> List[Any]:
			lowerCAmelCase__     :    int					  =      QuestionAnsweringExtractive(
			    context_column='''input_context'''	,      question_column='''input_question'''	,      answers_column='''input_answers'''	)
			self.assertDictEqual(
			    {'''input_context''': '''context''', '''input_question''': '''question''', '''input_answers''': '''answers'''}	,      task.column_mapping	)




	def 							UpperCAmelCase__(      self		:	List[str]	)-> Any:
			lowerCAmelCase__     :    Optional[Any]					  =      Features({'''question''': Value('''string'''	), '''context''': Value('''string'''	)}	)
			lowerCAmelCase__     :    str					  =      Features(
			    {
			        '''answers''': Sequence(
			            {
			                '''text''': Value('''string'''	),
			                '''answer_start''': Value('''int32'''	),
			            }	)
			    }	)
			lowerCAmelCase__     :    Dict					  =      {
			    '''context_column''': '''input_input_context''',
			    '''question_column''': '''input_question''',
			    '''answers_column''': '''input_answers''',
			}
			lowerCAmelCase__     :    int					  =      QuestionAnsweringExtractive.from_dict(SCREAMING_SNAKE_CASE_	)
			self.assertEqual('''question-answering-extractive'''	,      task.task	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.input_schema	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.label_schema	)





class       _a							(       lowerCamelCase__):




	def 							UpperCAmelCase__(      self		:	Any	)-> int:
			lowerCAmelCase__     :    List[Any]					  =      Summarization(text_column='''input_text'''	,      summary_column='''input_summary'''	)
			self.assertDictEqual({'''input_text''': '''text''', '''input_summary''': '''summary'''}	,      task.column_mapping	)




	def 							UpperCAmelCase__(      self		:	Dict	)-> Optional[Any]:
			lowerCAmelCase__     :    Optional[int]					  =      Features({'''text''': Value('''string'''	)}	)
			lowerCAmelCase__     :    List[str]					  =      Features({'''summary''': Value('''string'''	)}	)
			lowerCAmelCase__     :    Optional[int]					  =      {'''text_column''': '''input_text''', '''summary_column''': '''input_summary'''}
			lowerCAmelCase__     :    List[Any]					  =      Summarization.from_dict(SCREAMING_SNAKE_CASE_	)
			self.assertEqual('''summarization'''	,      task.task	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.input_schema	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.label_schema	)





class       _a							(       lowerCamelCase__):




	def 							UpperCAmelCase__(      self		:	Tuple	)-> List[Any]:
			lowerCAmelCase__     :    str					  =      AutomaticSpeechRecognition(audio_column='''input_audio'''	,      transcription_column='''input_transcription'''	)
			self.assertDictEqual({'''input_audio''': '''audio''', '''input_transcription''': '''transcription'''}	,      task.column_mapping	)




	def 							UpperCAmelCase__(      self		:	Dict	)-> Any:
			lowerCAmelCase__     :    Optional[int]					  =      Features({'''audio''': Audio()}	)
			lowerCAmelCase__     :    Dict					  =      Features({'''transcription''': Value('''string'''	)}	)
			lowerCAmelCase__     :    List[str]					  =      {
			    '''audio_column''': '''input_audio''',
			    '''transcription_column''': '''input_transcription''',
			}
			lowerCAmelCase__     :    str					  =      AutomaticSpeechRecognition.from_dict(SCREAMING_SNAKE_CASE_	)
			self.assertEqual('''automatic-speech-recognition'''	,      task.task	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.input_schema	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.label_schema	)





class       _a							(       lowerCamelCase__):




	def 							UpperCAmelCase__(      self		:	List[str]	)-> Optional[int]:
			lowerCAmelCase__     :    str					  =      sorted(['''pos''', '''neg''']	)




	def 							UpperCAmelCase__(      self		:	Tuple	)-> List[str]:
			lowerCAmelCase__     :    Optional[Any]					  =      AudioClassification(audio_column='''input_audio'''	,      label_column='''input_label'''	)
			self.assertDictEqual({'''input_audio''': '''audio''', '''input_label''': '''labels'''}	,      task.column_mapping	)




	def 							UpperCAmelCase__(      self		:	List[str]	)-> List[str]:
			lowerCAmelCase__     :    int					  =      Features({'''audio''': Audio()}	)
			lowerCAmelCase__     :    str					  =      Features({'''labels''': ClassLabel}	)
			lowerCAmelCase__     :    Dict					  =      {
			    '''audio_column''': '''input_image''',
			    '''label_column''': '''input_label''',
			}
			lowerCAmelCase__     :    Union[str, Any]					  =      AudioClassification.from_dict(SCREAMING_SNAKE_CASE_	)
			self.assertEqual('''audio-classification'''	,      task.task	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.input_schema	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.label_schema	)




	def 							UpperCAmelCase__(      self		:	str	)-> Optional[Any]:
			lowerCAmelCase__     :    List[str]					  =      AudioClassification(audio_column='''input_audio'''	,      label_column='''input_label'''	)
			self.assertEqual(task.label_schema['''labels''']	,      SCREAMING_SNAKE_CASE_	)
			lowerCAmelCase__     :    List[Any]					  =      task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels	)}	)	)
			self.assertEqual(task.label_schema['''labels''']	,      ClassLabel(names=self.labels	)	)





class       _a							(       lowerCamelCase__):




	def 							UpperCAmelCase__(      self		:	Tuple	)-> Dict:
			lowerCAmelCase__     :    Any					  =      sorted(['''pos''', '''neg''']	)




	def 							UpperCAmelCase__(      self		:	List[Any]	)-> List[str]:
			lowerCAmelCase__     :    Dict					  =      ImageClassification(image_column='''input_image'''	,      label_column='''input_label'''	)
			self.assertDictEqual({'''input_image''': '''image''', '''input_label''': '''labels'''}	,      task.column_mapping	)




	def 							UpperCAmelCase__(      self		:	List[str]	)-> Optional[Any]:
			lowerCAmelCase__     :    Dict					  =      Features({'''image''': Image()}	)
			lowerCAmelCase__     :    Dict					  =      Features({'''labels''': ClassLabel}	)
			lowerCAmelCase__     :    Tuple					  =      {
			    '''image_column''': '''input_image''',
			    '''label_column''': '''input_label''',
			}
			lowerCAmelCase__     :    Tuple					  =      ImageClassification.from_dict(SCREAMING_SNAKE_CASE_	)
			self.assertEqual('''image-classification'''	,      task.task	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.input_schema	)
			self.assertEqual(SCREAMING_SNAKE_CASE_	,      task.label_schema	)




	def 							UpperCAmelCase__(      self		:	Dict	)-> Optional[Any]:
			lowerCAmelCase__     :    Tuple					  =      ImageClassification(image_column='''input_image'''	,      label_column='''input_label'''	)
			self.assertEqual(task.label_schema['''labels''']	,      SCREAMING_SNAKE_CASE_	)
			lowerCAmelCase__     :    int					  =      task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels	)}	)	)
			self.assertEqual(task.label_schema['''labels''']	,      ClassLabel(names=self.labels	)	)





class       _a							(       lowerCamelCase__):




	def 							UpperCAmelCase__(      self		:	Optional[Any]	)-> List[str]:
			lowerCAmelCase__     :    Optional[Any]					  =      DatasetInfo(task_templates=QuestionAnsweringExtractive()	)
			lowerCAmelCase__     :    Any					  =      Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}	,      info=SCREAMING_SNAKE_CASE_	)
			assert isinstance(dataset.info.task_templates	,      SCREAMING_SNAKE_CASE_	)
			assert len(dataset.info.task_templates	) == 1

			def keep_task(_SCREAMING_SNAKE_CASE		:	Any	):
					return x

			def dont_keep_task(_SCREAMING_SNAKE_CASE		:	Any	):
					lowerCAmelCase__     :    Any					  =      deepcopy(SCREAMING_SNAKE_CASE_	)
					lowerCAmelCase__     :    int					  =      0
					return out

			lowerCAmelCase__     :    Tuple					  =      dataset.map(SCREAMING_SNAKE_CASE_	)
			assert mapped_dataset.info.task_templates == dataset.info.task_templates
			# reload from cache
			lowerCAmelCase__     :    Tuple					  =      dataset.map(SCREAMING_SNAKE_CASE_	)
			assert mapped_dataset.info.task_templates == dataset.info.task_templates

			lowerCAmelCase__     :    int					  =      dataset.map(SCREAMING_SNAKE_CASE_	)
			assert mapped_dataset.info.task_templates == []
			# reload from cache
			lowerCAmelCase__     :    Dict					  =      dataset.map(SCREAMING_SNAKE_CASE_	)
			assert mapped_dataset.info.task_templates == []




	def 							UpperCAmelCase__(      self		:	str	)-> List[Any]:
			lowerCAmelCase__     :    str					  =      Features({'''text''': Value('''string'''	), '''label''': ClassLabel(names=('''pos''', '''neg''')	)}	)
			lowerCAmelCase__     :    Any					  =      TextClassification(text_column='''text'''	,      label_column='''label'''	)
			lowerCAmelCase__     :    Union[str, Any]					  =      DatasetInfo(features=SCREAMING_SNAKE_CASE_	,      task_templates=SCREAMING_SNAKE_CASE_	)
			lowerCAmelCase__     :    Dict					  =      Dataset.from_dict({'''text''': ['''A sentence.'''], '''label''': ['''pos''']}	,      info=SCREAMING_SNAKE_CASE_	)

			def process(_SCREAMING_SNAKE_CASE		:	int	):
					return example

			lowerCAmelCase__     :    int					  =      dataset.remove_columns('''label'''	)
			lowerCAmelCase__     :    str					  =      modified_dataset.map(SCREAMING_SNAKE_CASE_	)
			assert mapped_dataset.info.task_templates == []








import copy

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


lowerCamelCase		=	logging.get_logger(__name__)

lowerCamelCase		=	{
    '''facebook/sam-vit-huge''': '''https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json''',
    '''facebook/sam-vit-large''': '''https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json''',
    '''facebook/sam-vit-base''': '''https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json''',
}





class       _a							(       _lowercase):




	def __init__(      self		:	Union[str, Any]	,      _SCREAMING_SNAKE_CASE		:	Tuple=256	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]=1024	,      _SCREAMING_SNAKE_CASE		:	List[Any]=16	,      _SCREAMING_SNAKE_CASE		:	Optional[int]=16	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]=4	,      _SCREAMING_SNAKE_CASE		:	Any="gelu"	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]=1E-6	,      **_SCREAMING_SNAKE_CASE		:	List[Any]	,      )-> Tuple:
			super().__init__(**_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    Any					  =      hidden_size
			lowerCAmelCase__     :    Tuple					  =      image_size
			lowerCAmelCase__     :    List[Any]					  =      patch_size
			lowerCAmelCase__     :    Any					  =      image_size // patch_size
			lowerCAmelCase__     :    Dict					  =      mask_input_channels
			lowerCAmelCase__     :    Dict					  =      num_point_embeddings
			lowerCAmelCase__     :    str					  =      hidden_act
			lowerCAmelCase__     :    List[Any]					  =      layer_norm_eps





class       _a							(       _lowercase):




	def __init__(      self		:	Tuple	,      _SCREAMING_SNAKE_CASE		:	Union[str, Any]=256	,      _SCREAMING_SNAKE_CASE		:	Dict="relu"	,      _SCREAMING_SNAKE_CASE		:	str=2048	,      _SCREAMING_SNAKE_CASE		:	List[Any]=2	,      _SCREAMING_SNAKE_CASE		:	Dict=8	,      _SCREAMING_SNAKE_CASE		:	str=2	,      _SCREAMING_SNAKE_CASE		:	Tuple=3	,      _SCREAMING_SNAKE_CASE		:	Optional[int]=3	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]=256	,      _SCREAMING_SNAKE_CASE		:	Dict=1E-6	,      **_SCREAMING_SNAKE_CASE		:	Any	,      )-> List[Any]:
			super().__init__(**_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    List[str]					  =      hidden_size
			lowerCAmelCase__     :    Union[str, Any]					  =      hidden_act
			lowerCAmelCase__     :    str					  =      mlp_dim
			lowerCAmelCase__     :    Optional[int]					  =      num_hidden_layers
			lowerCAmelCase__     :    int					  =      num_attention_heads
			lowerCAmelCase__     :    List[str]					  =      attention_downsample_rate
			lowerCAmelCase__     :    str					  =      num_multimask_outputs
			lowerCAmelCase__     :    Optional[int]					  =      iou_head_depth
			lowerCAmelCase__     :    Union[str, Any]					  =      iou_head_hidden_dim
			lowerCAmelCase__     :    Tuple					  =      layer_norm_eps





class       _a							(       _lowercase):




	def __init__(      self		:	List[str]	,      _SCREAMING_SNAKE_CASE		:	int=768	,      _SCREAMING_SNAKE_CASE		:	str=256	,      _SCREAMING_SNAKE_CASE		:	int=12	,      _SCREAMING_SNAKE_CASE		:	Tuple=12	,      _SCREAMING_SNAKE_CASE		:	Dict=3	,      _SCREAMING_SNAKE_CASE		:	Optional[int]=1024	,      _SCREAMING_SNAKE_CASE		:	Tuple=16	,      _SCREAMING_SNAKE_CASE		:	List[Any]="gelu"	,      _SCREAMING_SNAKE_CASE		:	Optional[int]=1E-06	,      _SCREAMING_SNAKE_CASE		:	int=0.0	,      _SCREAMING_SNAKE_CASE		:	int=1E-10	,      _SCREAMING_SNAKE_CASE		:	List[Any]=True	,      _SCREAMING_SNAKE_CASE		:	Any=4.0	,      _SCREAMING_SNAKE_CASE		:	List[str]=True	,      _SCREAMING_SNAKE_CASE		:	int=True	,      _SCREAMING_SNAKE_CASE		:	List[str]=14	,      _SCREAMING_SNAKE_CASE		:	Dict=[2, 5, 8, 11]	,      _SCREAMING_SNAKE_CASE		:	List[Any]=128	,      _SCREAMING_SNAKE_CASE		:	Dict=None	,      **_SCREAMING_SNAKE_CASE		:	str	,      )-> Any:
			super().__init__(**_SCREAMING_SNAKE_CASE	)

			lowerCAmelCase__     :    Optional[Any]					  =      hidden_size
			lowerCAmelCase__     :    Any					  =      output_channels
			lowerCAmelCase__     :    Optional[int]					  =      num_hidden_layers
			lowerCAmelCase__     :    Dict					  =      num_attention_heads
			lowerCAmelCase__     :    List[Any]					  =      num_channels
			lowerCAmelCase__     :    int					  =      image_size
			lowerCAmelCase__     :    Tuple					  =      patch_size
			lowerCAmelCase__     :    Union[str, Any]					  =      hidden_act
			lowerCAmelCase__     :    List[str]					  =      layer_norm_eps
			lowerCAmelCase__     :    Any					  =      attention_dropout
			lowerCAmelCase__     :    int					  =      initializer_range
			lowerCAmelCase__     :    List[Any]					  =      qkv_bias
			lowerCAmelCase__     :    List[Any]					  =      mlp_ratio
			lowerCAmelCase__     :    List[Any]					  =      use_abs_pos
			lowerCAmelCase__     :    Union[str, Any]					  =      use_rel_pos
			lowerCAmelCase__     :    Optional[Any]					  =      window_size
			lowerCAmelCase__     :    Union[str, Any]					  =      global_attn_indexes
			lowerCAmelCase__     :    Union[str, Any]					  =      num_pos_feats
			lowerCAmelCase__     :    str					  =      int(hidden_size * mlp_ratio	) if mlp_dim is None else mlp_dim





class       _a							(       _lowercase):
	_a						:						Tuple   					=							'''sam'''
	_a						:						Optional[Any]   					=							True




	def __init__(      self		:	Optional[Any]	,      _SCREAMING_SNAKE_CASE		:	Any=None	,      _SCREAMING_SNAKE_CASE		:	Optional[Any]=None	,      _SCREAMING_SNAKE_CASE		:	int=None	,      _SCREAMING_SNAKE_CASE		:	Tuple=0.02	,      **_SCREAMING_SNAKE_CASE		:	int	,      )-> Optional[int]:
			super().__init__(**_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    Tuple					  =      vision_config if vision_config is not None else {}
			lowerCAmelCase__     :    List[str]					  =      prompt_encoder_config if prompt_encoder_config is not None else {}
			lowerCAmelCase__     :    List[str]					  =      mask_decoder_config if mask_decoder_config is not None else {}

			if isinstance(_SCREAMING_SNAKE_CASE	,      _SCREAMING_SNAKE_CASE	):
					lowerCAmelCase__     :    Any					  =      vision_config.to_dict()
			if isinstance(_SCREAMING_SNAKE_CASE	,      _SCREAMING_SNAKE_CASE	):
					lowerCAmelCase__     :    Any					  =      prompt_encoder_config.to_dict()
			if isinstance(_SCREAMING_SNAKE_CASE	,      _SCREAMING_SNAKE_CASE	):
					lowerCAmelCase__     :    List[Any]					  =      mask_decoder_config.to_dict()

			lowerCAmelCase__     :    Any					  =      SamVisionConfig(**_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    List[Any]					  =      SamPromptEncoderConfig(**_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    Dict					  =      SamMaskDecoderConfig(**_SCREAMING_SNAKE_CASE	)
			lowerCAmelCase__     :    List[Any]					  =      initializer_range




	def 							UpperCAmelCase__(      self		:	Any	)-> int:
			lowerCAmelCase__     :    Optional[int]					  =      copy.deepcopy(self.__dict__	)
			lowerCAmelCase__     :    Any					  =      self.vision_config.to_dict()
			lowerCAmelCase__     :    Optional[Any]					  =      self.prompt_encoder_config.to_dict()
			lowerCAmelCase__     :    str					  =      self.mask_decoder_config.to_dict()
			lowerCAmelCase__     :    Any					  =      self.__class__.model_type
			return output




