




"""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": [515]},
}



@pytest.mark.parametrize(
    "task_cls"    ,       [
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]    ,       )
def 					UpperCamelCase__       (						lowercase__					:       int				):
		snake_case						:  Any        =			task_cls()
		snake_case						:  str        =			asdict(lowercase__				)
		snake_case						:  Union[str, Any]        =			task_template_from_dict(lowercase__				)
		assert task == reloaded
class      lowerCamelCase__      :


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[Any]        =			LanguageModeling(text_column="input_text"							)
					assert {"input_text": "text"} == task.column_mapping



			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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







class      lowerCamelCase__      (					lowerCamelCase_     ):


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					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 							lowerCamelCase_			(       self							):



					"""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						:  Dict        =			Features({"labels": ClassLabel}							)
					snake_case						:  str        =			{"text_column": "input_text", "label_column": "input_labels"}
					snake_case						:  Optional[int]        =			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 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  str        =			TextClassification(text_column="input_text"			,	label_column="input_label"							)
					self.assertEqual(task.label_schema["labels"]			,	SCREAMING_SNAKE_CASE							)
					snake_case						:  Optional[int]        =			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 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					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 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  int        =			Features({"question": Value("string"							), "context": Value("string"							)}							)
					snake_case						:  Union[str, Any]        =			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						:  Dict        =			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      lowerCamelCase__      (					lowerCamelCase_     ):


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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



			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[Any]        =			Features({"text": Value("string"							)}							)
					snake_case						:  Optional[Any]        =			Features({"summary": Value("string"							)}							)
					snake_case						:  str        =			{"text_column": "input_text", "summary_column": "input_summary"}
					snake_case						:  int        =			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      lowerCamelCase__      (					lowerCamelCase_     ):


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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



			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  str        =			Features({"audio": Audio()}							)
					snake_case						:  str        =			Features({"transcription": Value("string"							)}							)
					snake_case						:  Dict        =			{
					    "audio_column": "input_audio",
					    "transcription_column": "input_transcription",
					}
					snake_case						:  List[Any]        =			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      lowerCamelCase__      (					lowerCamelCase_     ):


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Any        =			Features({"audio": Audio()}							)
					snake_case						:  int        =			Features({"labels": ClassLabel}							)
					snake_case						:  Optional[int]        =			{
					    "audio_column": "input_image",
					    "label_column": "input_label",
					}
					snake_case						:  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 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Any        =			AudioClassification(audio_column="input_audio"			,	label_column="input_label"							)
					self.assertEqual(task.label_schema["labels"]			,	SCREAMING_SNAKE_CASE							)
					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__      (					lowerCamelCase_     ):


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Union[str, Any]        =			Features({"image": Image()}							)
					snake_case						:  str        =			Features({"labels": ClassLabel}							)
					snake_case						:  Dict        =			{
					    "image_column": "input_image",
					    "label_column": "input_label",
					}
					snake_case						:  int        =			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 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Union[str, Any]        =			ImageClassification(image_column="input_image"			,	label_column="input_label"							)
					self.assertEqual(task.label_schema["labels"]			,	SCREAMING_SNAKE_CASE							)
					snake_case						:  Dict        =			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 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Optional[Any]        =			DatasetInfo(task_templates=QuestionAnsweringExtractive()							)
					snake_case						:  str        =			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							):
							return x

					def dont_keep_task(SCREAMING_SNAKE_CASE							):
							snake_case						:  int        =			deepcopy(SCREAMING_SNAKE_CASE							)
							snake_case						:  Any        =			0
							return out

					snake_case						:  Dict        =			dataset.map(SCREAMING_SNAKE_CASE							)
					assert mapped_dataset.info.task_templates == dataset.info.task_templates
					# reload from cache
					snake_case						:  List[str]        =			dataset.map(SCREAMING_SNAKE_CASE							)
					assert mapped_dataset.info.task_templates == dataset.info.task_templates

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



			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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

					def process(SCREAMING_SNAKE_CASE							):
							return example

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







"""simple docstring"""

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__A							=     {
    "configuration_flava": [
        "FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "FlavaConfig",
        "FlavaImageCodebookConfig",
        "FlavaImageConfig",
        "FlavaMultimodalConfig",
        "FlavaTextConfig",
    ],
}

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__A							=     ["FlavaFeatureExtractor"]
							__A							=     ["FlavaImageProcessor"]
							__A							=     ["FlavaProcessor"]

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__A							=     [
							    "FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "FlavaForPreTraining",
							    "FlavaImageCodebook",
							    "FlavaImageModel",
							    "FlavaModel",
							    "FlavaMultimodalModel",
							    "FlavaPreTrainedModel",
							    "FlavaTextModel",
							]

if TYPE_CHECKING:
							from .configuration_flava import (
							    FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    FlavaConfig,
							    FlavaImageCodebookConfig,
							    FlavaImageConfig,
							    FlavaMultimodalConfig,
							    FlavaTextConfig,
							)

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .feature_extraction_flava import FlavaFeatureExtractor
														from .image_processing_flava import FlavaImageProcessor
														from .processing_flava import FlavaProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flava import (
														    FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    FlavaForPreTraining,
														    FlavaImageCodebook,
														    FlavaImageModel,
														    FlavaModel,
														    FlavaMultimodalModel,
														    FlavaPreTrainedModel,
														    FlavaTextModel,
														)

else:
							import sys

							__A							=     _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

