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


_lowercase											=			{
    '''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  _snake_case			(						snake_case__				:       List[Any]       ):
	A  				=				task_cls()
	A  				=				asdict(snake_case__       )
	A  				=				task_template_from_dict(snake_case__       )
	assert task == reloaded







class 			lowerCAmelCase_			:



						'''simple docstring'''


						def   _SCREAMING_SNAKE_CASE (	self       : str )       ->				Optional[Any]:
							A  				=				LanguageModeling(text_column='input_text' )
							assert {"input_text": "text"} == task.column_mapping




						def   _SCREAMING_SNAKE_CASE (	self       : Union[str, Any] )       ->				Tuple:
							A  				=				Features({'text': Value('string' )} )
							A  				=				{'text_column': 'input_text'}
							A  				=				LanguageModeling.from_dict(A_ )
							assert "language-modeling" == task.task
							assert input_schema == task.input_schema







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						def   _SCREAMING_SNAKE_CASE (	self       : int )       ->				Union[str, Any]:
							A  				=				sorted(['pos', 'neg'] )


						def   _SCREAMING_SNAKE_CASE (	self       : Any )       ->				Optional[Any]:
							A  				=				TextClassification(text_column='input_text'					,label_column='input_label' )
							self.assertDictEqual({'input_text': 'text', 'input_label': 'labels'}					,task.column_mapping )


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




						def   _SCREAMING_SNAKE_CASE (	self       : List[str] )       ->				Any:
							A  				=				TextClassification(text_column='input_text'					,label_column='input_label' )
							self.assertEqual(task.label_schema['labels']					,A_ )
							A  				=				task.align_with_features(Features({'input_label': ClassLabel(names=self.labels )} ) )
							self.assertEqual(task.label_schema['labels']					,ClassLabel(names=self.labels ) )







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


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







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						def   _SCREAMING_SNAKE_CASE (	self       : Optional[int] )       ->				int:
							A  				=				Summarization(text_column='input_text'					,summary_column='input_summary' )
							self.assertDictEqual({'input_text': 'text', 'input_summary': 'summary'}					,task.column_mapping )




						def   _SCREAMING_SNAKE_CASE (	self       : int )       ->				Optional[Any]:
							A  				=				Features({'text': Value('string' )} )
							A  				=				Features({'summary': Value('string' )} )
							A  				=				{'text_column': 'input_text', 'summary_column': 'input_summary'}
							A  				=				Summarization.from_dict(A_ )
							self.assertEqual('summarization'					,task.task )
							self.assertEqual(A_					,task.input_schema )
							self.assertEqual(A_					,task.label_schema )







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						def   _SCREAMING_SNAKE_CASE (	self       : int )       ->				Optional[int]:
							A  				=				AutomaticSpeechRecognition(audio_column='input_audio'					,transcription_column='input_transcription' )
							self.assertDictEqual({'input_audio': 'audio', 'input_transcription': 'transcription'}					,task.column_mapping )




						def   _SCREAMING_SNAKE_CASE (	self       : Optional[Any] )       ->				Optional[int]:
							A  				=				Features({'audio': Audio()} )
							A  				=				Features({'transcription': Value('string' )} )
							A  				=				{
							    'audio_column': 'input_audio',
							    'transcription_column': 'input_transcription',
							}
							A  				=				AutomaticSpeechRecognition.from_dict(A_ )
							self.assertEqual('automatic-speech-recognition'					,task.task )
							self.assertEqual(A_					,task.input_schema )
							self.assertEqual(A_					,task.label_schema )







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						def   _SCREAMING_SNAKE_CASE (	self       : int )       ->				str:
							A  				=				sorted(['pos', 'neg'] )


						def   _SCREAMING_SNAKE_CASE (	self       : Dict )       ->				Union[str, Any]:
							A  				=				AudioClassification(audio_column='input_audio'					,label_column='input_label' )
							self.assertDictEqual({'input_audio': 'audio', 'input_label': 'labels'}					,task.column_mapping )


						def   _SCREAMING_SNAKE_CASE (	self       : Optional[Any] )       ->				Optional[Any]:
							A  				=				Features({'audio': Audio()} )
							A  				=				Features({'labels': ClassLabel} )
							A  				=				{
							    'audio_column': 'input_image',
							    'label_column': 'input_label',
							}
							A  				=				AudioClassification.from_dict(A_ )
							self.assertEqual('audio-classification'					,task.task )
							self.assertEqual(A_					,task.input_schema )
							self.assertEqual(A_					,task.label_schema )




						def   _SCREAMING_SNAKE_CASE (	self       : Any )       ->				Optional[Any]:
							A  				=				AudioClassification(audio_column='input_audio'					,label_column='input_label' )
							self.assertEqual(task.label_schema['labels']					,A_ )
							A  				=				task.align_with_features(Features({'input_label': ClassLabel(names=self.labels )} ) )
							self.assertEqual(task.label_schema['labels']					,ClassLabel(names=self.labels ) )







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						def   _SCREAMING_SNAKE_CASE (	self       : int )       ->				str:
							A  				=				sorted(['pos', 'neg'] )


						def   _SCREAMING_SNAKE_CASE (	self       : int )       ->				List[str]:
							A  				=				ImageClassification(image_column='input_image'					,label_column='input_label' )
							self.assertDictEqual({'input_image': 'image', 'input_label': 'labels'}					,task.column_mapping )


						def   _SCREAMING_SNAKE_CASE (	self       : Tuple )       ->				Union[str, Any]:
							A  				=				Features({'image': Image()} )
							A  				=				Features({'labels': ClassLabel} )
							A  				=				{
							    'image_column': 'input_image',
							    'label_column': 'input_label',
							}
							A  				=				ImageClassification.from_dict(A_ )
							self.assertEqual('image-classification'					,task.task )
							self.assertEqual(A_					,task.input_schema )
							self.assertEqual(A_					,task.label_schema )




						def   _SCREAMING_SNAKE_CASE (	self       : Tuple )       ->				Optional[int]:
							A  				=				ImageClassification(image_column='input_image'					,label_column='input_label' )
							self.assertEqual(task.label_schema['labels']					,A_ )
							A  				=				task.align_with_features(Features({'input_label': ClassLabel(names=self.labels )} ) )
							self.assertEqual(task.label_schema['labels']					,ClassLabel(names=self.labels ) )







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						def   _SCREAMING_SNAKE_CASE (	self       : int )       ->				List[Any]:
							A  				=				DatasetInfo(task_templates=QuestionAnsweringExtractive() )
							A  				=				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_       : Optional[int] ):
								return x

							def dont_keep_task(A_       : int ):
								A  				=				deepcopy(A_ )
								A  				=				0
								return out

							A  				=				dataset.map(A_ )
							assert mapped_dataset.info.task_templates == dataset.info.task_templates
							# reload from cache
							A  				=				dataset.map(A_ )
							assert mapped_dataset.info.task_templates == dataset.info.task_templates

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




						def   _SCREAMING_SNAKE_CASE (	self       : Optional[int] )       ->				Optional[Any]:
							A  				=				Features({'text': Value('string' ), 'label': ClassLabel(names=('pos', 'neg') )} )
							A  				=				TextClassification(text_column='text'					,label_column='label' )
							A  				=				DatasetInfo(features=A_					,task_templates=A_ )
							A  				=				Dataset.from_dict({'text': ['A sentence.'], 'label': ['pos']}					,info=A_ )

							def process(A_       : List[str] ):
								return example

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

"""simple docstring"""


from typing import Callable, Optional, Union

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


_lowercase											=			logging.get_logger(__name__)

_lowercase											=			{
    '''microsoft/prophetnet-large-uncased''': (
        '''https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json'''
    ),
}







class 			lowerCAmelCase_			( _lowercase      ):



						'''simple docstring'''


						_lowerCamelCase:      int =      '''prophetnet'''
						_lowerCamelCase:      Optional[Any] =      ['''past_key_values''']
						_lowerCamelCase:      Dict =      {
						    '''num_attention_heads''': '''num_encoder_attention_heads''',
						}


						def __init__(	self       : Tuple					,A_       : Optional[float] = 0.1					,A_       : Optional[Union[str, Callable]] = "gelu"					,A_       : Optional[int] = 3_0522					,A_       : Optional[int] = 1024					,A_       : Optional[int] = 4096					,A_       : Optional[int] = 12					,A_       : Optional[int] = 16					,A_       : Optional[int] = 4096					,A_       : Optional[int] = 12					,A_       : Optional[int] = 16					,A_       : Optional[float] = 0.1					,A_       : Optional[float] = 0.1					,A_       : Optional[int] = 512					,A_       : Optional[float] = 0.02					,A_       : Optional[bool] = True					,A_       : Optional[bool] = True					,A_       : Optional[int] = 0					,A_       : Optional[int] = 2					,A_       : Optional[int] = 32					,A_       : Optional[int] = 128					,A_       : Optional[bool] = False					,A_       : Optional[float] = 0.0					,A_       : Optional[bool] = True					,A_       : Optional[int] = 0					,A_       : Optional[int] = 1					,A_       : Optional[int] = 2					,**A_       : Tuple					,)       ->				Any:
							A  				=				vocab_size
							A  				=				hidden_size
							A  				=				encoder_ffn_dim
							A  				=				num_encoder_layers
							A  				=				num_encoder_attention_heads
							A  				=				decoder_ffn_dim
							A  				=				num_decoder_layers
							A  				=				num_decoder_attention_heads
							A  				=				max_position_embeddings
							A  				=				init_std  # Normal(0, this parameter)
							A  				=				activation_function

							# parameters for prophetnet
							A  				=				ngram
							A  				=				num_buckets
							A  				=				relative_max_distance
							A  				=				disable_ngram_loss
							A  				=				eps

							# 3 Types of Dropout
							A  				=				attention_dropout
							A  				=				activation_dropout
							A  				=				dropout

							A  				=				use_cache

							super().__init__(
							    pad_token_id=A_					,bos_token_id=A_					,eos_token_id=A_					,is_encoder_decoder=A_					,add_cross_attention=A_					,decoder_start_token_id=A_					,**A_					,)


						@property
						def   _SCREAMING_SNAKE_CASE (	self       : List[Any] )       ->				int:
							return self.num_encoder_layers + self.num_decoder_layers




						@num_hidden_layers.setter
						def   _SCREAMING_SNAKE_CASE (	self       : int					,A_       : Any )       ->				int:
							raise NotImplementedError(
							    'This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'
							    ' `num_decoder_layers`.' )