



"""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


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_1_5]},
}

@pytest.mark.parametrize(
    "task_cls"    ,		[
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]    ,		)
def    __SCREAMING_SNAKE_CASE		( lowerCamelCase_:       Tuple   ):
						"""simple docstring"""






						snake_case      : Tuple							=   task_cls()
						snake_case      : List[Any]							=   asdict(lowerCamelCase_   )
						snake_case      : Tuple							=   task_template_from_dict(lowerCamelCase_   )
						assert task == reloaded

class 			_a     :



			def 							__lowercase				( self       :							Tuple		)       ->				Any:
									snake_case      : List[str]							=   LanguageModeling(text_column="input_text"		)
									assert {"input_text": "text"} == task.column_mapping



			def 							__lowercase				( self       :							int		)       ->				Tuple:
									snake_case      : Optional[int]							=   Features({"text": Value("string"		)}		)
									snake_case      : int							=   {"text_column": "input_text"}
									snake_case      : Union[str, Any]							=   LanguageModeling.from_dict(_lowercase		)
									assert "language-modeling" == task.task
									assert input_schema == task.input_schema



class 			_a     (   SCREAMING_SNAKE_CASE__):



			def 							__lowercase				( self       :							List[Any]		)       ->				Any:
									snake_case      : Optional[Any]							=   sorted(["pos", "neg"]		)



			def 							__lowercase				( self       :							Dict		)       ->				Optional[int]:
									snake_case      : Optional[int]							=   TextClassification(text_column="input_text"      ,  label_column="input_label"		)
									self.assertDictEqual({"input_text": "text", "input_label": "labels"}      ,  task.column_mapping		)



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



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



class 			_a     (   SCREAMING_SNAKE_CASE__):



			def 							__lowercase				( self       :							Any		)       ->				Optional[Any]:
									snake_case      : str							=   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 							__lowercase				( self       :							List[str]		)       ->				Optional[int]:
									snake_case      : Optional[Any]							=   Features({"question": Value("string"		), "context": Value("string"		)}		)
									snake_case      : Dict							=   Features(
									    {
									        "answers": Sequence(
									            {
									                "text": Value("string"		),
									                "answer_start": Value("int32"		),
									            }		)
									    }		)
									snake_case      : List[Any]							=   {
									    "context_column": "input_input_context",
									    "question_column": "input_question",
									    "answers_column": "input_answers",
									}
									snake_case      : int							=   QuestionAnsweringExtractive.from_dict(_lowercase		)
									self.assertEqual("question-answering-extractive"      ,  task.task		)
									self.assertEqual(_lowercase      ,  task.input_schema		)
									self.assertEqual(_lowercase      ,  task.label_schema		)



class 			_a     (   SCREAMING_SNAKE_CASE__):



			def 							__lowercase				( self       :							List[Any]		)       ->				Dict:
									snake_case      : Optional[Any]							=   Summarization(text_column="input_text"      ,  summary_column="input_summary"		)
									self.assertDictEqual({"input_text": "text", "input_summary": "summary"}      ,  task.column_mapping		)



			def 							__lowercase				( self       :							Optional[Any]		)       ->				int:
									snake_case      : Dict							=   Features({"text": Value("string"		)}		)
									snake_case      : Dict							=   Features({"summary": Value("string"		)}		)
									snake_case      : Union[str, Any]							=   {"text_column": "input_text", "summary_column": "input_summary"}
									snake_case      : Dict							=   Summarization.from_dict(_lowercase		)
									self.assertEqual("summarization"      ,  task.task		)
									self.assertEqual(_lowercase      ,  task.input_schema		)
									self.assertEqual(_lowercase      ,  task.label_schema		)



class 			_a     (   SCREAMING_SNAKE_CASE__):



			def 							__lowercase				( self       :							List[str]		)       ->				List[str]:
									snake_case      : Tuple							=   AutomaticSpeechRecognition(audio_column="input_audio"      ,  transcription_column="input_transcription"		)
									self.assertDictEqual({"input_audio": "audio", "input_transcription": "transcription"}      ,  task.column_mapping		)



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



class 			_a     (   SCREAMING_SNAKE_CASE__):



			def 							__lowercase				( self       :							Dict		)       ->				List[Any]:
									snake_case      : List[Any]							=   sorted(["pos", "neg"]		)



			def 							__lowercase				( self       :							Optional[Any]		)       ->				Dict:
									snake_case      : Dict							=   AudioClassification(audio_column="input_audio"      ,  label_column="input_label"		)
									self.assertDictEqual({"input_audio": "audio", "input_label": "labels"}      ,  task.column_mapping		)



			def 							__lowercase				( self       :							Dict		)       ->				Any:
									snake_case      : List[str]							=   Features({"audio": Audio()}		)
									snake_case      : int							=   Features({"labels": ClassLabel}		)
									snake_case      : List[str]							=   {
									    "audio_column": "input_image",
									    "label_column": "input_label",
									}
									snake_case      : List[str]							=   AudioClassification.from_dict(_lowercase		)
									self.assertEqual("audio-classification"      ,  task.task		)
									self.assertEqual(_lowercase      ,  task.input_schema		)
									self.assertEqual(_lowercase      ,  task.label_schema		)



			def 							__lowercase				( self       :							Optional[Any]		)       ->				int:
									snake_case      : Tuple							=   AudioClassification(audio_column="input_audio"      ,  label_column="input_label"		)
									self.assertEqual(task.label_schema["labels"]      ,  _lowercase		)
									snake_case      : Tuple							=   task.align_with_features(Features({"input_label": ClassLabel(names=self.labels		)}		)		)
									self.assertEqual(task.label_schema["labels"]      ,  ClassLabel(names=self.labels		)		)



class 			_a     (   SCREAMING_SNAKE_CASE__):



			def 							__lowercase				( self       :							Any		)       ->				Tuple:
									snake_case      : Optional[int]							=   sorted(["pos", "neg"]		)



			def 							__lowercase				( self       :							Dict		)       ->				Union[str, Any]:
									snake_case      : Dict							=   ImageClassification(image_column="input_image"      ,  label_column="input_label"		)
									self.assertDictEqual({"input_image": "image", "input_label": "labels"}      ,  task.column_mapping		)



			def 							__lowercase				( self       :							Tuple		)       ->				int:
									snake_case      : List[Any]							=   Features({"image": Image()}		)
									snake_case      : Optional[int]							=   Features({"labels": ClassLabel}		)
									snake_case      : Union[str, Any]							=   {
									    "image_column": "input_image",
									    "label_column": "input_label",
									}
									snake_case      : Dict							=   ImageClassification.from_dict(_lowercase		)
									self.assertEqual("image-classification"      ,  task.task		)
									self.assertEqual(_lowercase      ,  task.input_schema		)
									self.assertEqual(_lowercase      ,  task.label_schema		)



			def 							__lowercase				( self       :							Tuple		)       ->				int:
									snake_case      : int							=   ImageClassification(image_column="input_image"      ,  label_column="input_label"		)
									self.assertEqual(task.label_schema["labels"]      ,  _lowercase		)
									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 			_a     (   SCREAMING_SNAKE_CASE__):



			def 							__lowercase				( self       :							Union[str, Any]		)       ->				int:
									snake_case      : List[str]							=   DatasetInfo(task_templates=QuestionAnsweringExtractive()		)
									snake_case      : str							=   Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}      ,  info=_lowercase		)
									assert isinstance(dataset.info.task_templates      ,  _lowercase		)
									assert len(dataset.info.task_templates		) == 1

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

									def dont_keep_task(_lowercase       :							List[str]		):
															snake_case      : List[Any]							=   deepcopy(_lowercase		)
															snake_case      : Dict							=   0
															return out

									snake_case      : str							=   dataset.map(_lowercase		)
									assert mapped_dataset.info.task_templates == dataset.info.task_templates
									# reload from cache
									snake_case      : Any							=   dataset.map(_lowercase		)
									assert mapped_dataset.info.task_templates == dataset.info.task_templates

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



			def 							__lowercase				( self       :							Optional[Any]		)       ->				List[Any]:
									snake_case      : List[str]							=   Features({"text": Value("string"		), "label": ClassLabel(names=("pos", "neg")		)}		)
									snake_case      : Optional[Any]							=   TextClassification(text_column="text"      ,  label_column="label"		)
									snake_case      : Dict							=   DatasetInfo(features=_lowercase      ,  task_templates=_lowercase		)
									snake_case      : Any							=   Dataset.from_dict({"text": ["A sentence."], "label": ["pos"]}      ,  info=_lowercase		)

									def process(_lowercase       :							Optional[Any]		):
															return example

									snake_case      : List[Any]							=   dataset.remove_columns("label"		)
									snake_case      : Any							=   modified_dataset.map(_lowercase		)
									assert mapped_dataset.info.task_templates == []








"""simple docstring"""







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


A    =	logging.get_logger(__name__)

A    =	{
    'uw-madison/yoso-4096': 'https://huggingface.co/uw-madison/yoso-4096/resolve/main/config.json',
    # See all YOSO models at https://huggingface.co/models?filter=yoso
}

class 			_a     (   SCREAMING_SNAKE_CASE__):
			__magic_name__    				=    """yoso"""



			def __init__( self       :							List[str]      ,  _lowercase       :							List[str]=50265      ,  _lowercase       :							List[str]=768      ,  _lowercase       :							Optional[int]=12      ,  _lowercase       :							str=12      ,  _lowercase       :							List[Any]=3072      ,  _lowercase       :							Dict="gelu"      ,  _lowercase       :							int=0.1      ,  _lowercase       :							Optional[Any]=0.1      ,  _lowercase       :							Dict=4096      ,  _lowercase       :							Optional[Any]=1      ,  _lowercase       :							Any=0.02      ,  _lowercase       :							Union[str, Any]=1E-12      ,  _lowercase       :							int="absolute"      ,  _lowercase       :							Any=True      ,  _lowercase       :							Dict=9      ,  _lowercase       :							int=64      ,  _lowercase       :							Any=None      ,  _lowercase       :							List[str]=True      ,  _lowercase       :							Optional[Any]=True      ,  _lowercase       :							Any=1      ,  _lowercase       :							int=0      ,  _lowercase       :							List[str]=2      ,  **_lowercase       :							List[Any]      ,  )       ->				Union[str, Any]:
									super().__init__(pad_token_id=_lowercase      ,  bos_token_id=_lowercase      ,  eos_token_id=_lowercase      ,  **_lowercase		)

									snake_case      : List[str]							=   vocab_size
									snake_case      : Tuple							=   max_position_embeddings
									snake_case      : Optional[Any]							=   hidden_size
									snake_case      : Tuple							=   num_hidden_layers
									snake_case      : Tuple							=   num_attention_heads
									snake_case      : Any							=   intermediate_size
									snake_case      : Union[str, Any]							=   hidden_act
									snake_case      : int							=   hidden_dropout_prob
									snake_case      : Dict							=   attention_probs_dropout_prob
									snake_case      : Any							=   initializer_range
									snake_case      : Optional[Any]							=   type_vocab_size
									snake_case      : List[str]							=   layer_norm_eps
									snake_case      : Dict							=   position_embedding_type
									snake_case      : Tuple							=   use_expectation
									snake_case      : Dict							=   hash_code_len
									snake_case      : Optional[Any]							=   num_hash
									snake_case      : List[str]							=   conv_window
									snake_case      : Optional[Any]							=   use_fast_hash
									snake_case      : Tuple							=   lsh_backward



