


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


snake_case_  :	Tuple							  =							{
    '''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''': [5_15]},
}







@pytest.mark.parametrize(
    '''task_cls'''		,[
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]		,)
def   lowerCamelCase(      a__):
				_SCREAMING_SNAKE_CASE	     =task_cls()
				_SCREAMING_SNAKE_CASE	     =asdict(a__)
				_SCREAMING_SNAKE_CASE	     =task_template_from_dict(a__)
				assert task == reloaded

class   A__							:




						def 							__UpperCamelCase (				self    :					str     )							->   Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =LanguageModeling(text_column='''input_text'''     )
										assert {"input_text": "text"} == task.column_mapping




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


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =Features({'''text''': Value('''string'''     )}     )
										_SCREAMING_SNAKE_CASE	     ={'''text_column''': '''input_text'''}
										_SCREAMING_SNAKE_CASE	     =LanguageModeling.from_dict(_a     )
										assert "language-modeling" == task.task
										assert input_schema == task.input_schema

class   A__							(						UpperCamelCase__     ):




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


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =sorted(['''pos''', '''neg''']     )




						def 							__UpperCamelCase (				self    :					Tuple     )							->   str:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =TextClassification(text_column='''input_text''' ,			label_column='''input_label'''     )
										self.assertDictEqual({'''input_text''': '''text''', '''input_label''': '''labels'''} ,			task.column_mapping     )




						def 							__UpperCamelCase (				self    :					Optional[Any]     )							->   List[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =Features({'''text''': Value('''string'''     )}     )
										# Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
										_SCREAMING_SNAKE_CASE	     =Features({'''labels''': ClassLabel}     )
										_SCREAMING_SNAKE_CASE	     ={'''text_column''': '''input_text''', '''label_column''': '''input_labels'''}
										_SCREAMING_SNAKE_CASE	     =TextClassification.from_dict(_a     )
										self.assertEqual('''text-classification''' ,			task.task     )
										self.assertEqual(_a ,			task.input_schema     )
										self.assertEqual(_a ,			task.label_schema     )




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


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =TextClassification(text_column='''input_text''' ,			label_column='''input_label'''     )
										self.assertEqual(task.label_schema['''labels'''] ,			_a     )
										_SCREAMING_SNAKE_CASE	     =task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels     )}     )     )
										self.assertEqual(task.label_schema['''labels'''] ,			ClassLabel(names=self.labels     )     )

class   A__							(						UpperCamelCase__     ):




						def 							__UpperCamelCase (				self    :					Optional[Any]     )							->   List[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =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    :					Optional[int]     )							->   Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =Features({'''question''': Value('''string'''     ), '''context''': Value('''string'''     )}     )
										_SCREAMING_SNAKE_CASE	     =Features(
										    {
										        '''answers''': Sequence(
										            {
										                '''text''': Value('''string'''     ),
										                '''answer_start''': Value('''int32'''     ),
										            }     )
										    }     )
										_SCREAMING_SNAKE_CASE	     ={
										    '''context_column''': '''input_input_context''',
										    '''question_column''': '''input_question''',
										    '''answers_column''': '''input_answers''',
										}
										_SCREAMING_SNAKE_CASE	     =QuestionAnsweringExtractive.from_dict(_a     )
										self.assertEqual('''question-answering-extractive''' ,			task.task     )
										self.assertEqual(_a ,			task.input_schema     )
										self.assertEqual(_a ,			task.label_schema     )

class   A__							(						UpperCamelCase__     ):




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


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =Summarization(text_column='''input_text''' ,			summary_column='''input_summary'''     )
										self.assertDictEqual({'''input_text''': '''text''', '''input_summary''': '''summary'''} ,			task.column_mapping     )




						def 							__UpperCamelCase (				self    :					Tuple     )							->   Optional[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =Features({'''text''': Value('''string'''     )}     )
										_SCREAMING_SNAKE_CASE	     =Features({'''summary''': Value('''string'''     )}     )
										_SCREAMING_SNAKE_CASE	     ={'''text_column''': '''input_text''', '''summary_column''': '''input_summary'''}
										_SCREAMING_SNAKE_CASE	     =Summarization.from_dict(_a     )
										self.assertEqual('''summarization''' ,			task.task     )
										self.assertEqual(_a ,			task.input_schema     )
										self.assertEqual(_a ,			task.label_schema     )

class   A__							(						UpperCamelCase__     ):




						def 							__UpperCamelCase (				self    :					int     )							->   Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =AutomaticSpeechRecognition(audio_column='''input_audio''' ,			transcription_column='''input_transcription'''     )
										self.assertDictEqual({'''input_audio''': '''audio''', '''input_transcription''': '''transcription'''} ,			task.column_mapping     )




						def 							__UpperCamelCase (				self    :					int     )							->   List[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =Features({'''audio''': Audio()}     )
										_SCREAMING_SNAKE_CASE	     =Features({'''transcription''': Value('''string'''     )}     )
										_SCREAMING_SNAKE_CASE	     ={
										    '''audio_column''': '''input_audio''',
										    '''transcription_column''': '''input_transcription''',
										}
										_SCREAMING_SNAKE_CASE	     =AutomaticSpeechRecognition.from_dict(_a     )
										self.assertEqual('''automatic-speech-recognition''' ,			task.task     )
										self.assertEqual(_a ,			task.input_schema     )
										self.assertEqual(_a ,			task.label_schema     )

class   A__							(						UpperCamelCase__     ):




						def 							__UpperCamelCase (				self    :					List[str]     )							->   Union[str, Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =sorted(['''pos''', '''neg''']     )




						def 							__UpperCamelCase (				self    :					Any     )							->   Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =AudioClassification(audio_column='''input_audio''' ,			label_column='''input_label'''     )
										self.assertDictEqual({'''input_audio''': '''audio''', '''input_label''': '''labels'''} ,			task.column_mapping     )




						def 							__UpperCamelCase (				self    :					Any     )							->   str:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =Features({'''audio''': Audio()}     )
										_SCREAMING_SNAKE_CASE	     =Features({'''labels''': ClassLabel}     )
										_SCREAMING_SNAKE_CASE	     ={
										    '''audio_column''': '''input_image''',
										    '''label_column''': '''input_label''',
										}
										_SCREAMING_SNAKE_CASE	     =AudioClassification.from_dict(_a     )
										self.assertEqual('''audio-classification''' ,			task.task     )
										self.assertEqual(_a ,			task.input_schema     )
										self.assertEqual(_a ,			task.label_schema     )




						def 							__UpperCamelCase (				self    :					List[Any]     )							->   Union[str, Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =AudioClassification(audio_column='''input_audio''' ,			label_column='''input_label'''     )
										self.assertEqual(task.label_schema['''labels'''] ,			_a     )
										_SCREAMING_SNAKE_CASE	     =task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels     )}     )     )
										self.assertEqual(task.label_schema['''labels'''] ,			ClassLabel(names=self.labels     )     )

class   A__							(						UpperCamelCase__     ):




						def 							__UpperCamelCase (				self    :					Dict     )							->   Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =sorted(['''pos''', '''neg''']     )




						def 							__UpperCamelCase (				self    :					int     )							->   Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =ImageClassification(image_column='''input_image''' ,			label_column='''input_label'''     )
										self.assertDictEqual({'''input_image''': '''image''', '''input_label''': '''labels'''} ,			task.column_mapping     )




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


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =Features({'''image''': Image()}     )
										_SCREAMING_SNAKE_CASE	     =Features({'''labels''': ClassLabel}     )
										_SCREAMING_SNAKE_CASE	     ={
										    '''image_column''': '''input_image''',
										    '''label_column''': '''input_label''',
										}
										_SCREAMING_SNAKE_CASE	     =ImageClassification.from_dict(_a     )
										self.assertEqual('''image-classification''' ,			task.task     )
										self.assertEqual(_a ,			task.input_schema     )
										self.assertEqual(_a ,			task.label_schema     )




						def 							__UpperCamelCase (				self    :					int     )							->   Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =ImageClassification(image_column='''input_image''' ,			label_column='''input_label'''     )
										self.assertEqual(task.label_schema['''labels'''] ,			_a     )
										_SCREAMING_SNAKE_CASE	     =task.align_with_features(Features({'''input_label''': ClassLabel(names=self.labels     )}     )     )
										self.assertEqual(task.label_schema['''labels'''] ,			ClassLabel(names=self.labels     )     )

class   A__							(						UpperCamelCase__     ):




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


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =DatasetInfo(task_templates=QuestionAnsweringExtractive()     )
										_SCREAMING_SNAKE_CASE	     =Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()} ,			info=_a     )
										assert isinstance(dataset.info.task_templates ,			_a     )
										assert len(dataset.info.task_templates     ) == 1

										def keep_task(_a    :					List[Any]     ):
														return x

										def dont_keep_task(_a    :					int     ):
														_SCREAMING_SNAKE_CASE	     =deepcopy(_a     )
														_SCREAMING_SNAKE_CASE	     =0
														return out

										_SCREAMING_SNAKE_CASE	     =dataset.map(_a     )
										assert mapped_dataset.info.task_templates == dataset.info.task_templates
										# reload from cache
										_SCREAMING_SNAKE_CASE	     =dataset.map(_a     )
										assert mapped_dataset.info.task_templates == dataset.info.task_templates

										_SCREAMING_SNAKE_CASE	     =dataset.map(_a     )
										assert mapped_dataset.info.task_templates == []
										# reload from cache
										_SCREAMING_SNAKE_CASE	     =dataset.map(_a     )
										assert mapped_dataset.info.task_templates == []




						def 							__UpperCamelCase (				self    :					Any     )							->   int:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE	     =Features({'''text''': Value('''string'''     ), '''label''': ClassLabel(names=('''pos''', '''neg''')     )}     )
										_SCREAMING_SNAKE_CASE	     =TextClassification(text_column='''text''' ,			label_column='''label'''     )
										_SCREAMING_SNAKE_CASE	     =DatasetInfo(features=_a ,			task_templates=_a     )
										_SCREAMING_SNAKE_CASE	     =Dataset.from_dict({'''text''': ['''A sentence.'''], '''label''': ['''pos''']} ,			info=_a     )

										def process(_a    :					Dict     ):
														return example

										_SCREAMING_SNAKE_CASE	     =dataset.remove_columns('''label'''     )
										_SCREAMING_SNAKE_CASE	     =modified_dataset.map(_a     )
										assert mapped_dataset.info.task_templates == []



from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


snake_case_  :	Any							  =							logging.get_logger(__name__)

snake_case_  :	Any							  =							{
    '''apple/mobilevit-small''': '''https://huggingface.co/apple/mobilevit-small/resolve/main/config.json''',
    '''apple/mobilevit-x-small''': '''https://huggingface.co/apple/mobilevit-x-small/resolve/main/config.json''',
    '''apple/mobilevit-xx-small''': '''https://huggingface.co/apple/mobilevit-xx-small/resolve/main/config.json''',
    '''apple/deeplabv3-mobilevit-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-small/resolve/main/config.json'''
    ),
    '''apple/deeplabv3-mobilevit-x-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-x-small/resolve/main/config.json'''
    ),
    '''apple/deeplabv3-mobilevit-xx-small''': (
        '''https://huggingface.co/apple/deeplabv3-mobilevit-xx-small/resolve/main/config.json'''
    ),
    # See all MobileViT models at https://huggingface.co/models?filter=mobilevit
}

class   A__							(						UpperCamelCase__     ):
						UpperCAmelCase									=  "mobilevit"




						def __init__(				self    :					Tuple ,			_a    :					Any=3 ,			_a    :					Any=256 ,			_a    :					Any=2 ,			_a    :					List[str]=[144, 192, 240] ,			_a    :					Optional[int]=[16, 32, 64, 96, 128, 160, 640] ,			_a    :					Union[str, Any]=4 ,			_a    :					Any=2.0 ,			_a    :					List[str]=4.0 ,			_a    :					Tuple="silu" ,			_a    :					Optional[Any]=3 ,			_a    :					List[str]=32 ,			_a    :					Union[str, Any]=0.1 ,			_a    :					Tuple=0.0 ,			_a    :					Union[str, Any]=0.1 ,			_a    :					Union[str, Any]=0.02 ,			_a    :					Tuple=1E-5 ,			_a    :					Any=True ,			_a    :					str=256 ,			_a    :					Tuple=[6, 12, 18] ,			_a    :					int=0.1 ,			_a    :					str=255 ,			**_a    :					Any ,			)							->   Optional[int]:


										"""simple docstring"""





										super().__init__(**_a     )

										_SCREAMING_SNAKE_CASE	     =num_channels
										_SCREAMING_SNAKE_CASE	     =image_size
										_SCREAMING_SNAKE_CASE	     =patch_size
										_SCREAMING_SNAKE_CASE	     =hidden_sizes
										_SCREAMING_SNAKE_CASE	     =neck_hidden_sizes
										_SCREAMING_SNAKE_CASE	     =num_attention_heads
										_SCREAMING_SNAKE_CASE	     =mlp_ratio
										_SCREAMING_SNAKE_CASE	     =expand_ratio
										_SCREAMING_SNAKE_CASE	     =hidden_act
										_SCREAMING_SNAKE_CASE	     =conv_kernel_size
										_SCREAMING_SNAKE_CASE	     =output_stride
										_SCREAMING_SNAKE_CASE	     =hidden_dropout_prob
										_SCREAMING_SNAKE_CASE	     =attention_probs_dropout_prob
										_SCREAMING_SNAKE_CASE	     =classifier_dropout_prob
										_SCREAMING_SNAKE_CASE	     =initializer_range
										_SCREAMING_SNAKE_CASE	     =layer_norm_eps
										_SCREAMING_SNAKE_CASE	     =qkv_bias

										# decode head attributes for semantic segmentation
										_SCREAMING_SNAKE_CASE	     =aspp_out_channels
										_SCREAMING_SNAKE_CASE	     =atrous_rates
										_SCREAMING_SNAKE_CASE	     =aspp_dropout_prob
										_SCREAMING_SNAKE_CASE	     =semantic_loss_ignore_index

class   A__							(						UpperCamelCase__     ):
						UpperCAmelCase									=  version.parse("1.11"     )




						@property
						def 							__UpperCamelCase (				self    :					Union[str, Any]     )							->   Mapping[str, Mapping[int, str]]:


										"""simple docstring"""





										return OrderedDict([('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''})]     )




						@property
						def 							__UpperCamelCase (				self    :					Dict     )							->   Mapping[str, Mapping[int, str]]:


										"""simple docstring"""





										if self.task == "image-classification":
														return OrderedDict([('''logits''', {0: '''batch'''})]     )
										else:
														return OrderedDict([('''last_hidden_state''', {0: '''batch'''}), ('''pooler_output''', {0: '''batch'''})]     )




						@property
						def 							__UpperCamelCase (				self    :					List[Any]     )							->   float:


										"""simple docstring"""





										return 1E-4