



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


A__       =			{
    """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 						_UpperCAmelCase							( snake_case     ):





					"""simple docstring"""

					_lowerCAmelCase         =       task_cls()
					_lowerCAmelCase         =       asdict(snake_case     )
					_lowerCAmelCase         =       task_template_from_dict(snake_case     )
					assert task == reloaded





class    __lowerCAmelCase					:




				def 				snake_case  (				self						):



									"""simple docstring"""





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




				def 				snake_case  (				self						):



									"""simple docstring"""





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





class    __lowerCAmelCase					(	lowerCamelCase__			):




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       sorted(["""pos""", """neg"""]						)




				def 				snake_case  (				self						):



									"""simple docstring"""





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




				def 				snake_case  (				self						):



									"""simple docstring"""





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




				def 				snake_case  (				self						):



									"""simple docstring"""





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





class    __lowerCAmelCase					(	lowerCamelCase__			):




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       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 				snake_case  (				self						):



									"""simple docstring"""





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





class    __lowerCAmelCase					(	lowerCamelCase__			):




				def 				snake_case  (				self						):



									"""simple docstring"""





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




				def 				snake_case  (				self						):



									"""simple docstring"""





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





class    __lowerCAmelCase					(	lowerCamelCase__			):




				def 				snake_case  (				self						):



									"""simple docstring"""





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




				def 				snake_case  (				self						):



									"""simple docstring"""





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





class    __lowerCAmelCase					(	lowerCamelCase__			):




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       sorted(["""pos""", """neg"""]						)




				def 				snake_case  (				self						):



									"""simple docstring"""





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




				def 				snake_case  (				self						):



									"""simple docstring"""





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




				def 				snake_case  (				self						):



									"""simple docstring"""





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





class    __lowerCAmelCase					(	lowerCamelCase__			):




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       sorted(["""pos""", """neg"""]						)




				def 				snake_case  (				self						):



									"""simple docstring"""





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




				def 				snake_case  (				self						):



									"""simple docstring"""





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




				def 				snake_case  (				self						):



									"""simple docstring"""





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





class    __lowerCAmelCase					(	lowerCamelCase__			):




				def 				snake_case  (				self						):



									"""simple docstring"""





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

									def keep_task(_snake_case						):
														return x

									def dont_keep_task(_snake_case						):
														_lowerCAmelCase         =       deepcopy(_snake_case						)
														_lowerCAmelCase         =       0
														return out

									_lowerCAmelCase         =       dataset.map(_snake_case						)
									assert mapped_dataset.info.task_templates == dataset.info.task_templates
									# reload from cache
									_lowerCAmelCase         =       dataset.map(_snake_case						)
									assert mapped_dataset.info.task_templates == dataset.info.task_templates

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




				def 				snake_case  (				self						):



									"""simple docstring"""





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

									def process(_snake_case						):
														return example

									_lowerCAmelCase         =       dataset.remove_columns("""label"""						)
									_lowerCAmelCase         =       modified_dataset.map(_snake_case						)
									assert mapped_dataset.info.task_templates == []








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


A__       =			logging.get_logger(__name__)

A__       =			{
    """MCG-NJU/videomae-base""": """https://huggingface.co/MCG-NJU/videomae-base/resolve/main/config.json""",
}





class    __lowerCAmelCase					(	lowerCamelCase__			):
				__lowerCamelCase					=							'''videomae'''




				def __init__(				self		,							_snake_case=224		,							_snake_case=16		,							_snake_case=3		,							_snake_case=16		,							_snake_case=2		,							_snake_case=768		,							_snake_case=12		,							_snake_case=12		,							_snake_case=3072		,							_snake_case="gelu"		,							_snake_case=0.0		,							_snake_case=0.0		,							_snake_case=0.02		,							_snake_case=1e-12		,							_snake_case=True		,							_snake_case=True		,							_snake_case=6		,							_snake_case=384		,							_snake_case=4		,							_snake_case=1536		,							_snake_case=True		,							**_snake_case		,							):



									"""simple docstring"""





									super().__init__(**_snake_case						)

									_lowerCAmelCase         =       image_size
									_lowerCAmelCase         =       patch_size
									_lowerCAmelCase         =       num_channels
									_lowerCAmelCase         =       num_frames
									_lowerCAmelCase         =       tubelet_size

									_lowerCAmelCase         =       hidden_size
									_lowerCAmelCase         =       num_hidden_layers
									_lowerCAmelCase         =       num_attention_heads
									_lowerCAmelCase         =       intermediate_size
									_lowerCAmelCase         =       hidden_act
									_lowerCAmelCase         =       hidden_dropout_prob
									_lowerCAmelCase         =       attention_probs_dropout_prob
									_lowerCAmelCase         =       initializer_range
									_lowerCAmelCase         =       layer_norm_eps
									_lowerCAmelCase         =       qkv_bias
									_lowerCAmelCase         =       use_mean_pooling

									_lowerCAmelCase         =       decoder_num_attention_heads
									_lowerCAmelCase         =       decoder_hidden_size
									_lowerCAmelCase         =       decoder_num_hidden_layers
									_lowerCAmelCase         =       decoder_intermediate_size
									_lowerCAmelCase         =       norm_pix_loss



