




'''simple docstring'''

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


a__         =     logging.get_logger(__name__)

a__         =     {
    '''uw-madison/nystromformer-512''': '''https://huggingface.co/uw-madison/nystromformer-512/resolve/main/config.json''',
    # See all Nystromformer models at https://huggingface.co/models?filter=nystromformer
}





class __magic_name__(						__lowerCAmelCase      ):
						UpperCAmelCase_		:					int    =  """nystromformer"""






						def __init__(   self						:						int					,   __UpperCamelCase						:						Optional[int]=3_0_0_0_0					,   __UpperCamelCase						:						int=7_6_8					,   __UpperCamelCase						:						Union[str, Any]=1_2					,   __UpperCamelCase						:						Optional[int]=1_2					,   __UpperCamelCase						:						List[Any]=3_0_7_2					,   __UpperCamelCase						:						Dict="gelu_new"					,   __UpperCamelCase						:						Optional[Any]=0.1					,   __UpperCamelCase						:						List[Any]=0.1					,   __UpperCamelCase						:						int=5_1_0					,   __UpperCamelCase						:						List[Any]=2					,   __UpperCamelCase						:						List[str]=6_4					,   __UpperCamelCase						:						Tuple=6_4					,   __UpperCamelCase						:						Optional[int]=6_5					,   __UpperCamelCase						:						int=False					,   __UpperCamelCase						:						Optional[int]=0.02					,   __UpperCamelCase						:						str=1E-5					,   __UpperCamelCase						:						Optional[Any]=1					,   __UpperCamelCase						:						Dict=0					,   __UpperCamelCase						:						Tuple=2					,   **__UpperCamelCase						:						Any					,   ):



									'''simple docstring'''






									snake_case__          =						vocab_size
									snake_case__          =						max_position_embeddings
									snake_case__          =						hidden_size
									snake_case__          =						num_hidden_layers
									snake_case__          =						num_attention_heads
									snake_case__          =						intermediate_size
									snake_case__          =						hidden_act
									snake_case__          =						hidden_dropout_prob
									snake_case__          =						attention_probs_dropout_prob
									snake_case__          =						initializer_range
									snake_case__          =						type_vocab_size
									snake_case__          =						segment_means_seq_len
									snake_case__          =						num_landmarks
									snake_case__          =						conv_kernel_size
									snake_case__          =						inv_coeff_init_option
									snake_case__          =						layer_norm_eps
									super().__init__(pad_token_id=__UpperCamelCase					,   bos_token_id=__UpperCamelCase					,   eos_token_id=__UpperCamelCase					,   **__UpperCamelCase       )
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    :  int										= {
    '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   a_					(_lowerCAmelCase  :   List[Any]       )->				Tuple:
    snake_case:						Dict         =   task_cls()
    snake_case:						Any         =   asdict(_lowerCAmelCase       )
    snake_case:						Any         =   task_template_from_dict(_lowerCAmelCase       )
    assert task == reloaded
class 				lowerCamelCase			:






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


          '''simple docstring'''







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






      def 			lowerCAmelCase_   (      self						)     ->				Tuple:


          '''simple docstring'''







          snake_case:						List[Any]         =   Features({"""text""": Value("""string"""						)}						)
          snake_case:						Optional[int]         =   {"""text_column""": """input_text"""}
          snake_case:						List[Any]         =   LanguageModeling.from_dict(__lowerCamelCase						)
          assert "language-modeling" == task.task
          assert input_schema == task.input_schema





class 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				Optional[Any]:


          '''simple docstring'''







          snake_case:						Optional[int]         =   sorted(["""pos""", """neg"""]						)






      def 			lowerCAmelCase_   (      self						)     ->				List[str]:


          '''simple docstring'''







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






      def 			lowerCAmelCase_   (      self						)     ->				Any:


          '''simple docstring'''







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






      def 			lowerCAmelCase_   (      self						)     ->				Optional[Any]:


          '''simple docstring'''







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





class 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				Optional[Any]:


          '''simple docstring'''







          snake_case:						List[Any]         =   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 			lowerCAmelCase_   (      self						)     ->				Any:


          '''simple docstring'''







          snake_case:						Any         =   Features({"""question""": Value("""string"""						), """context""": Value("""string"""						)}						)
          snake_case:						Tuple         =   Features(
              {
                  """answers""": Sequence(
                      {
                          """text""": Value("""string"""						),
                          """answer_start""": Value("""int32"""						),
                      }						)
              }						)
          snake_case:						Tuple         =   {
              """context_column""": """input_input_context""",
              """question_column""": """input_question""",
              """answers_column""": """input_answers""",
          }
          snake_case:						Optional[Any]         =   QuestionAnsweringExtractive.from_dict(__lowerCamelCase						)
          self.assertEqual("""question-answering-extractive"""  ,		task.task						)
          self.assertEqual(__lowerCamelCase  ,		task.input_schema						)
          self.assertEqual(__lowerCamelCase  ,		task.label_schema						)





class 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				Tuple:


          '''simple docstring'''







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






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


          '''simple docstring'''







          snake_case:						List[Any]         =   Features({"""text""": Value("""string"""						)}						)
          snake_case:						Dict         =   Features({"""summary""": Value("""string"""						)}						)
          snake_case:						Tuple         =   {"""text_column""": """input_text""", """summary_column""": """input_summary"""}
          snake_case:						List[str]         =   Summarization.from_dict(__lowerCamelCase						)
          self.assertEqual("""summarization"""  ,		task.task						)
          self.assertEqual(__lowerCamelCase  ,		task.input_schema						)
          self.assertEqual(__lowerCamelCase  ,		task.label_schema						)





class 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				Dict:


          '''simple docstring'''







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






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


          '''simple docstring'''







          snake_case:						Union[str, Any]         =   Features({"""audio""": Audio()}						)
          snake_case:						Union[str, Any]         =   Features({"""transcription""": Value("""string"""						)}						)
          snake_case:						Any         =   {
              """audio_column""": """input_audio""",
              """transcription_column""": """input_transcription""",
          }
          snake_case:						str         =   AutomaticSpeechRecognition.from_dict(__lowerCamelCase						)
          self.assertEqual("""automatic-speech-recognition"""  ,		task.task						)
          self.assertEqual(__lowerCamelCase  ,		task.input_schema						)
          self.assertEqual(__lowerCamelCase  ,		task.label_schema						)





class 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				int:


          '''simple docstring'''







          snake_case:						Union[str, Any]         =   sorted(["""pos""", """neg"""]						)






      def 			lowerCAmelCase_   (      self						)     ->				Dict:


          '''simple docstring'''







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






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


          '''simple docstring'''







          snake_case:						Optional[Any]         =   Features({"""audio""": Audio()}						)
          snake_case:						int         =   Features({"""labels""": ClassLabel}						)
          snake_case:						int         =   {
              """audio_column""": """input_image""",
              """label_column""": """input_label""",
          }
          snake_case:						Optional[Any]         =   AudioClassification.from_dict(__lowerCamelCase						)
          self.assertEqual("""audio-classification"""  ,		task.task						)
          self.assertEqual(__lowerCamelCase  ,		task.input_schema						)
          self.assertEqual(__lowerCamelCase  ,		task.label_schema						)






      def 			lowerCAmelCase_   (      self						)     ->				str:


          '''simple docstring'''







          snake_case:						List[str]         =   AudioClassification(audio_column="""input_audio"""  ,		label_column="""input_label"""						)
          self.assertEqual(task.label_schema["""labels"""]  ,		__lowerCamelCase						)
          snake_case:						int         =   task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels						)}						)						)
          self.assertEqual(task.label_schema["""labels"""]  ,		ClassLabel(names=self.labels						)						)





class 				lowerCamelCase			(							__snake_case					):






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


          '''simple docstring'''







          snake_case:						Dict         =   sorted(["""pos""", """neg"""]						)






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


          '''simple docstring'''







          snake_case:						Optional[Any]         =   ImageClassification(image_column="""input_image"""  ,		label_column="""input_label"""						)
          self.assertDictEqual({"""input_image""": """image""", """input_label""": """labels"""}  ,		task.column_mapping						)






      def 			lowerCAmelCase_   (      self						)     ->				int:


          '''simple docstring'''







          snake_case:						Dict         =   Features({"""image""": Image()}						)
          snake_case:						str         =   Features({"""labels""": ClassLabel}						)
          snake_case:						List[str]         =   {
              """image_column""": """input_image""",
              """label_column""": """input_label""",
          }
          snake_case:						Any         =   ImageClassification.from_dict(__lowerCamelCase						)
          self.assertEqual("""image-classification"""  ,		task.task						)
          self.assertEqual(__lowerCamelCase  ,		task.input_schema						)
          self.assertEqual(__lowerCamelCase  ,		task.label_schema						)






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


          '''simple docstring'''







          snake_case:						Union[str, Any]         =   ImageClassification(image_column="""input_image"""  ,		label_column="""input_label"""						)
          self.assertEqual(task.label_schema["""labels"""]  ,		__lowerCamelCase						)
          snake_case:						str         =   task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels						)}						)						)
          self.assertEqual(task.label_schema["""labels"""]  ,		ClassLabel(names=self.labels						)						)





class 				lowerCamelCase			(							__snake_case					):






      def 			lowerCAmelCase_   (      self						)     ->				str:


          '''simple docstring'''







          snake_case:						List[str]         =   DatasetInfo(task_templates=QuestionAnsweringExtractive()						)
          snake_case:						int         =   Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}  ,		info=__lowerCamelCase						)
          assert isinstance(dataset.info.task_templates  ,		__lowerCamelCase						)
          assert len(dataset.info.task_templates						) == 1

          def keep_task(__lowerCamelCase						):
              return x

          def dont_keep_task(__lowerCamelCase						):
              snake_case:						Union[str, Any]         =   deepcopy(__lowerCamelCase						)
              snake_case:						int         =   0
              return out

          snake_case:						int         =   dataset.map(__lowerCamelCase						)
          assert mapped_dataset.info.task_templates == dataset.info.task_templates
          # reload from cache
          snake_case:						Optional[Any]         =   dataset.map(__lowerCamelCase						)
          assert mapped_dataset.info.task_templates == dataset.info.task_templates

          snake_case:						Optional[int]         =   dataset.map(__lowerCamelCase						)
          assert mapped_dataset.info.task_templates == []
          # reload from cache
          snake_case:						Union[str, Any]         =   dataset.map(__lowerCamelCase						)
          assert mapped_dataset.info.task_templates == []






      def 			lowerCAmelCase_   (      self						)     ->				int:


          '''simple docstring'''







          snake_case:						Any         =   Features({"""text""": Value("""string"""						), """label""": ClassLabel(names=("""pos""", """neg""")						)}						)
          snake_case:						Optional[int]         =   TextClassification(text_column="""text"""  ,		label_column="""label"""						)
          snake_case:						str         =   DatasetInfo(features=__lowerCamelCase  ,		task_templates=__lowerCamelCase						)
          snake_case:						Optional[Any]         =   Dataset.from_dict({"""text""": ["""A sentence."""], """label""": ["""pos"""]}  ,		info=__lowerCamelCase						)

          def process(__lowerCamelCase						):
              return example

          snake_case:						Optional[Any]         =   dataset.remove_columns("""label"""						)
          snake_case:						Tuple         =   modified_dataset.map(__lowerCamelCase						)
          assert mapped_dataset.info.task_templates == []


