





'''simple docstring'''


import unittest

import numpy as np
import timeout_decorator  # noqa

from transformers import OPTConfig, is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, slow

from ...generation.test_flax_utils import FlaxGenerationTesterMixin
from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor


if is_flax_available():
 import os

 # The slow tests are often failing with OOM error on GPU
 # This makes JAX allocate exactly what is needed on demand, and deallocate memory that is no longer needed
 # but will be slower as stated here https://jax.readthedocs.io/en/latest/gpu_memory_allocation.html
 lowerCAmelCase      							='''platform'''

 import jax
 import jax.numpy as jnp

 from transformers import FlaxOPTForCausalLM, FlaxOPTModel, GPTaTokenizer
def 							UpperCAmelCase_						(		__lowerCamelCase      :      Any			,__lowerCamelCase      :      str			,__lowerCamelCase      :      Any=None			,__lowerCamelCase      :      Any=None				):
   if attention_mask is None:
      lowercase_    :Tuple					    =				np.where(input_ids != config.pad_token_id			,1			,0				)
   return {
       "input_ids": input_ids,
       "attention_mask": attention_mask,
   }
@require_flax
class    a_     :





     def __init__(				self	:      Dict			,   lowercase	:      int			,   lowercase	:      Union[str, Any]=13			,   lowercase	:      Tuple=7			,   lowercase	:      List[str]=True			,   lowercase	:      Any=False			,   lowercase	:      Optional[Any]=99			,   lowercase	:      Tuple=16			,   lowercase	:      Dict=2			,   lowercase	:      List[str]=4			,   lowercase	:      str=4			,   lowercase	:      List[Any]="gelu"			,   lowercase	:      List[Any]=0.1			,   lowercase	:      str=0.1			,   lowercase	:      Union[str, Any]=20			,   lowercase	:      Tuple=2			,   lowercase	:      Tuple=1			,   lowercase	:      Optional[Any]=0			,   lowercase	:      Optional[Any]=16			,   lowercase	:      Any=16			,   lowercase	:      Tuple=0.02			,   ):





        """simple docstring"""




        lowercase_    :List[Any]					    =				parent
        lowercase_    :int					    =				batch_size
        lowercase_    :Dict					    =				seq_length
        lowercase_    :Optional[int]					    =				is_training
        lowercase_    :int					    =				use_labels
        lowercase_    :Union[str, Any]					    =				vocab_size
        lowercase_    :Any					    =				hidden_size
        lowercase_    :int					    =				num_hidden_layers
        lowercase_    :Optional[Any]					    =				num_attention_heads
        lowercase_    :int					    =				intermediate_size
        lowercase_    :Optional[Any]					    =				hidden_act
        lowercase_    :Union[str, Any]					    =				hidden_dropout_prob
        lowercase_    :List[str]					    =				attention_probs_dropout_prob
        lowercase_    :str					    =				max_position_embeddings
        lowercase_    :Optional[int]					    =				eos_token_id
        lowercase_    :Union[str, Any]					    =				pad_token_id
        lowercase_    :Union[str, Any]					    =				bos_token_id
        lowercase_    :Optional[Any]					    =				embed_dim
        lowercase_    :Optional[Any]					    =				word_embed_proj_dim
        lowercase_    :str					    =				initializer_range
        lowercase_    :Dict					    =				False





     def 							lowercase__   (				self	:      Optional[int]		):





        """simple docstring"""




        lowercase_    :Optional[Any]					    =				np.clip(ids_tensor([self.batch_size, self.seq_length - 1]			,   self.vocab_size		)			,   3			,   self.vocab_size		)
        lowercase_    :Dict					    =				np.concatenate((input_ids, 2 * np.ones((self.batch_size, 1)			,   dtype=np.intaa		))			,   -1		)

        lowercase_    :Optional[int]					    =				OPTConfig(
            vocab_size=self.vocab_size			,   hidden_size=self.hidden_size			,   num_hidden_layers=self.num_hidden_layers			,   num_attention_heads=self.num_attention_heads			,   ffn_dim=self.intermediate_size			,   dropout=self.hidden_dropout_prob			,   attention_dropout=self.attention_probs_dropout_prob			,   max_position_embeddings=self.max_position_embeddings			,   eos_token_id=self.eos_token_id			,   bos_token_id=self.bos_token_id			,   pad_token_id=self.pad_token_id			,   embed_dim=self.embed_dim			,   is_encoder_decoder=lowercase			,   word_embed_proj_dim=self.word_embed_proj_dim			,   initializer_range=self.initializer_range			,   use_cache=lowercase			,   )
        lowercase_    :Optional[Any]					    =				prepare_opt_inputs_dict(lowercase			,   lowercase		)
        return config, inputs_dict





     def 							lowercase__   (				self	:      Tuple		):





        """simple docstring"""




        lowercase_    :Any					    =				self.prepare_config_and_inputs()
        return config, inputs_dict





     def 							lowercase__   (				self	:      Any			,   lowercase	:      Tuple			,   lowercase	:      Optional[int]			,   lowercase	:      Tuple		):





        """simple docstring"""




        lowercase_    :str					    =				20
        lowercase_    :Union[str, Any]					    =				model_class_name(lowercase		)

        lowercase_    :Tuple					    =				inputs_dict["input_ids"]
        lowercase_    :Optional[Any]					    =				inputs_dict["attention_mask"]

        lowercase_    :Union[str, Any]					    =				model.init_cache(input_ids.shape[0]			,   lowercase		)
        lowercase_    :Union[str, Any]					    =				jnp.ones((input_ids.shape[0], max_length)			,   dtype="i4"		)

        lowercase_    :Dict					    =				jnp.broadcast_to(
            jnp.arange(input_ids.shape[-1] - 1		)[None, :]			,   (input_ids.shape[0], input_ids.shape[-1] - 1)			,   )
        lowercase_    :Union[str, Any]					    =				model(
            input_ids[:, :-1]			,   attention_mask=lowercase			,   past_key_values=lowercase			,   position_ids=lowercase			,   )

        lowercase_    :Dict					    =				jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]			,   dtype="i4"		)
        lowercase_    :List[str]					    =				model(
            input_ids[:, -1:]			,   attention_mask=lowercase			,   past_key_values=outputs_cache.past_key_values			,   position_ids=lowercase			,   )

        lowercase_    :Optional[int]					    =				model(lowercase		)

        lowercase_    :Optional[int]					    =				np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])		)		)
        self.parent.assertTrue(diff < 1e-3			,   msg=F'Max diff is {diff}'		)







     def 							lowercase__   (				self	:      str			,   lowercase	:      Dict			,   lowercase	:      str			,   lowercase	:      Dict		):





        """simple docstring"""




        lowercase_    :Optional[Any]					    =				20
        lowercase_    :List[Any]					    =				model_class_name(lowercase		)

        lowercase_    :Tuple					    =				(
            inputs_dict["input_ids"],
            inputs_dict["attention_mask"],
        )

        lowercase_    :List[str]					    =				jnp.concatenate(
            [
                attention_mask,
                jnp.zeros((attention_mask.shape[0], max_length - attention_mask.shape[1])		),
            ]			,   axis=-1			,   )

        lowercase_    :List[Any]					    =				model.init_cache(input_ids.shape[0]			,   lowercase		)
        lowercase_    :str					    =				jnp.broadcast_to(
            jnp.arange(input_ids.shape[-1] - 1		)[None, :]			,   (input_ids.shape[0], input_ids.shape[-1] - 1)			,   )

        lowercase_    :List[str]					    =				model(
            input_ids[:, :-1]			,   attention_mask=lowercase			,   past_key_values=lowercase			,   position_ids=lowercase			,   )
        lowercase_    :str					    =				jnp.array(input_ids.shape[0] * [[input_ids.shape[-1] - 1]]			,   dtype="i4"		)
        lowercase_    :int					    =				model(
            input_ids[:, -1:]			,   past_key_values=outputs_cache.past_key_values			,   attention_mask=lowercase			,   position_ids=lowercase			,   )

        lowercase_    :str					    =				model(lowercase			,   attention_mask=lowercase		)

        lowercase_    :Tuple					    =				np.max(np.abs((outputs_cache_next[0][:, -1, :5] - outputs[0][:, -1, :5])		)		)
        self.parent.assertTrue(diff < 1e-3			,   msg=F'Max diff is {diff}'		)







@require_flax
class    a_     (       _lowerCAmelCase			,		unittest.TestCase			,		_lowerCAmelCase							):
     __A  				=    (FlaxOPTModel, FlaxOPTForCausalLM) if is_flax_available() else ()
     __A  				=    () if is_flax_available() else ()





     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :List[Any]					    =				FlaxOPTModelTester(self		)





     def 							lowercase__   (				self	:      int		):





        """simple docstring"""




        lowercase_    :List[Any]					    =				self.model_tester.prepare_config_and_inputs()
        for model_class in self.all_model_classes:
           self.model_tester.check_use_cache_forward(lowercase			,   lowercase			,   lowercase		)





     def 							lowercase__   (				self	:      List[str]		):





        """simple docstring"""




        lowercase_    :Tuple					    =				self.model_tester.prepare_config_and_inputs()
        for model_class in self.all_model_classes:
           self.model_tester.check_use_cache_forward_with_attn_mask(lowercase			,   lowercase			,   lowercase		)







     @slow
     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        for model_class_name in self.all_model_classes:
           lowercase_    :Union[str, Any]					    =				model_class_name.from_pretrained("facebook/opt-125m"		)
           lowercase_    :List[str]					    =				np.ones((1, 1)		) * model.config.eos_token_id
           lowercase_    :Optional[Any]					    =				model(lowercase		)
           self.assertIsNotNone(lowercase		)







@require_sentencepiece
@require_flax
class    a_     (       unittest.TestCase							):





     @slow
     def 							lowercase__   (				self	:      List[str]		):





        """simple docstring"""




        lowercase_    :List[str]					    =				FlaxOPTModel.from_pretrained("facebook/opt-350m"		)
        lowercase_    :Any					    =				jnp.array([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]		)
        lowercase_    :List[Any]					    =				model(input_ids=lowercase		).last_hidden_state
        lowercase_    :List[str]					    =				(1, 11, 512)
        self.assertEqual(output.shape			,   lowercase		)
        lowercase_    :Any					    =				jnp.array(
            [[-0.28_67, -1.92_56, -0.30_62], [-1.27_11, -0.13_37, -0.18_97], [0.41_09, 0.11_87, -1.31_42]]		)
        self.assertTrue(jnp.allclose(output[:, :3, :3]			,   lowercase			,   atol=4e-2		)		)







@require_flax
@slow
class    a_     (       unittest.TestCase							):





     def 							lowercase__   (				self	:      List[str]		):





        """simple docstring"""




        super().setUp()
        lowercase_    :str					    =				"facebook/opt-350m"







     def 							lowercase__   (				self	:      Tuple		):





        """simple docstring"""




        lowercase_    :List[str]					    =				FlaxOPTForCausalLM.from_pretrained(self.path_model		)
        lowercase_    :Tuple					    =				GPTaTokenizer.from_pretrained(self.path_model		)

        lowercase_    :Optional[Any]					    =				[
            "Today is a beautiful day and I want to",
            "In the city of",
            "Paris is the capital of France and",
            "Computers and mobile phones have taken",
        ]
        # verify that prompt without BOS token is identical to Metaseq -> add_special_tokens=False
        lowercase_    :int					    =				tokenizer(lowercase			,   return_tensors="jax"			,   padding=lowercase			,   add_special_tokens=lowercase		)
        lowercase_    :str					    =				model(inputs.input_ids			,   attention_mask=inputs.attention_mask		)[0].mean(axis=-1		)
        lowercase_    :Optional[int]					    =				jnp.array(
            [
                [1.38_51, -13.89_23, -10.52_29, -10.75_33, -0.23_09, -10.23_84, -0.53_65, -9.09_47, -5.16_70],
                [-4.70_73, -10.62_76, -3.94_15, -21.52_42, -0.28_22, -0.28_22, -0.28_22, -0.28_22, -0.28_22],
                [0.62_47, -3.42_29, -8.91_79, -1.42_97, -14.16_50, 1.41_46, -9.02_18, -0.27_03, -0.27_03],
                [6.47_83, -1.99_13, -10.79_26, -2.33_36, 1.50_92, -0.99_74, -6.82_13, 1.34_77, 1.34_77],
            ]		)
        self.assertTrue(jnp.allclose(lowercase			,   lowercase			,   atol=4e-2		)		)

        lowercase_    :Any					    =				jax.jit(lowercase		)
        lowercase_    :Any					    =				model(inputs.input_ids			,   attention_mask=inputs.attention_mask		)[0].mean(axis=-1		)
        self.assertTrue(jnp.allclose(lowercase			,   lowercase			,   atol=4e-2		)		)







@require_flax
@slow
class    a_     (       unittest.TestCase							):





     @property
     def 							lowercase__   (				self	:      Optional[int]		):





        """simple docstring"""




        return [
            "Today is a beautiful day and I want",
            "In the city of",
            "Paris is the capital of France and",
            "Computers and mobile phones have taken",
        ]





     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




        lowercase_    :List[str]					    =				"facebook/opt-125m"

        lowercase_    :Dict					    =				[
            "Today is a beautiful day and I want to",
            "In the city of New York, the city",
            "Paris is the capital of France and the capital",
            "Computers and mobile phones have taken over the",
        ]

        lowercase_    :Any					    =				[]

        lowercase_    :int					    =				FlaxOPTForCausalLM.from_pretrained(lowercase		)
        lowercase_    :Optional[Any]					    =				GPTaTokenizer.from_pretrained(lowercase		)

        for prompt in self.prompts:
           lowercase_    :List[Any]					    =				tokenizer(lowercase			,   return_tensors="jax"		).input_ids

           lowercase_    :List[Any]					    =				model.generate(lowercase			,   max_length=10		)
           lowercase_    :Optional[int]					    =				generated_ids[0]

           lowercase_    :Any					    =				tokenizer.batch_decode(lowercase			,   skip_special_tokens=lowercase		)
           predicted_outputs += generated_string

        self.assertListEqual(lowercase			,   lowercase		)





     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :Optional[Any]					    =				"facebook/opt-350m"

        lowercase_    :Union[str, Any]					    =				[
            "Today is a beautiful day and I want to",
            "In the city of San Francisco, the city",
            "Paris is the capital of France and the capital",
            "Computers and mobile phones have taken over the",
        ]

        lowercase_    :Dict					    =				[]
        lowercase_    :List[Any]					    =				FlaxOPTForCausalLM.from_pretrained(lowercase		)
        lowercase_    :Dict					    =				GPTaTokenizer.from_pretrained(lowercase		)

        for prompt in self.prompts:
           lowercase_    :List[Any]					    =				tokenizer(lowercase			,   return_tensors="jax"		).input_ids

           lowercase_    :Dict					    =				model.generate(lowercase			,   max_length=10		)
           lowercase_    :Tuple					    =				generated_ids[0]

           lowercase_    :Dict					    =				tokenizer.batch_decode(lowercase			,   skip_special_tokens=lowercase		)
           predicted_outputs += generated_string

        self.assertListEqual(lowercase			,   lowercase		)





     def 							lowercase__   (				self	:      List[Any]		):





        """simple docstring"""




        lowercase_    :int					    =				"facebook/opt-125m"
        lowercase_    :int					    =				[
            "Today is a beautiful day and I want to thank",
            "In the city of Rome Canaver Canaver Canaver Canaver",
        ]
        lowercase_    :Optional[int]					    =				FlaxOPTForCausalLM.from_pretrained(lowercase		)
        lowercase_    :List[str]					    =				GPTaTokenizer.from_pretrained(lowercase		)
        lowercase_    :int					    =				tokenizer(
            [
                "Today is a beautiful day and I want to",
                "In the city of",
            ]			,   return_tensors="jax"			,   padding=lowercase			,   )

        lowercase_    :Dict					    =				jax.jit(model.generate		)

        lowercase_    :Optional[int]					    =				jit_generate(inputs["input_ids"]			,   attention_mask=inputs["attention_mask"]		).sequences

        lowercase_    :Union[str, Any]					    =				tokenizer.batch_decode(lowercase			,   skip_special_tokens=lowercase		)

        self.assertIsNotNone(lowercase			,   lowercase		)







     def 							lowercase__   (				self	:      Optional[int]		):





        """simple docstring"""




        lowercase_    :int					    =				"facebook/opt-350m"

        lowercase_    :str					    =				GPTaTokenizer.from_pretrained(lowercase		)
        lowercase_    :Optional[Any]					    =				FlaxOPTForCausalLM.from_pretrained(lowercase		)

        lowercase_    :int					    =				"left"

        # use different length sentences to test batching
        lowercase_    :Optional[int]					    =				[
            "Hello, my dog is a little",
            "Today, I",
        ]

        lowercase_    :Tuple					    =				tokenizer(lowercase			,   return_tensors="jax"			,   padding=lowercase		)
        lowercase_    :Any					    =				inputs["input_ids"]

        lowercase_    :str					    =				model.generate(input_ids=lowercase			,   attention_mask=inputs["attention_mask"]			,   trace=lowercase		)

        lowercase_    :Dict					    =				tokenizer(sentences[0]			,   return_tensors="jax"		).input_ids
        lowercase_    :List[Any]					    =				model.generate(input_ids=lowercase		)

        lowercase_    :str					    =				inputs_non_padded.shape[-1] - inputs["attention_mask"][-1].sum()
        lowercase_    :Optional[int]					    =				tokenizer(sentences[1]			,   return_tensors="jax"		).input_ids
        lowercase_    :List[Any]					    =				model.generate(input_ids=lowercase			,   max_length=model.config.max_length - num_paddings		)

        lowercase_    :str					    =				tokenizer.batch_decode(outputs[0]			,   skip_special_tokens=lowercase		)
        lowercase_    :Dict					    =				tokenizer.decode(output_non_padded[0][0]			,   skip_special_tokens=lowercase		)
        lowercase_    :int					    =				tokenizer.decode(output_padded[0][0]			,   skip_special_tokens=lowercase		)

        lowercase_    :Any					    =				[
            "Hello, my dog is a little bit of a dork.\nI'm a little bit",
            "Today, I was in the middle of a conversation with a friend about the",
        ]
        self.assertListEqual(lowercase			,   lowercase		)
        self.assertListEqual(lowercase			,   [non_padded_sentence, padded_sentence]		)









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


lowerCAmelCase      :  Tuple      							={
    '''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_						(		__lowerCamelCase      :      str				):
   lowercase_    :str					    =				task_cls()
   lowercase_    :Tuple					    =				asdict(__lowerCamelCase				)
   lowercase_    :Dict					    =				task_template_from_dict(__lowerCamelCase				)
   assert task == reloaded
class    a_     :





     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :Optional[int]					    =				LanguageModeling(text_column="input_text"		)
        assert {"input_text": "text"} == task.column_mapping







     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




        lowercase_    :Tuple					    =				Features({"text": Value("string"		)}		)
        lowercase_    :List[Any]					    =				{"text_column": "input_text"}
        lowercase_    :List[str]					    =				LanguageModeling.from_dict(lowercase		)
        assert "language-modeling" == task.task
        assert input_schema == task.input_schema







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Tuple		):





        """simple docstring"""




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





     def 							lowercase__   (				self	:      int		):





        """simple docstring"""




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





     def 							lowercase__   (				self	:      List[Any]		):





        """simple docstring"""




        lowercase_    :Union[str, Any]					    =				Features({"text": Value("string"		)}		)
        # Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
        lowercase_    :Any					    =				Features({"labels": ClassLabel}		)
        lowercase_    :str					    =				{"text_column": "input_text", "label_column": "input_labels"}
        lowercase_    :Optional[int]					    =				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		):





        """simple docstring"""




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







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      List[str]		):





        """simple docstring"""




        lowercase_    :int					    =				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	:      Any		):





        """simple docstring"""




        lowercase_    :Dict					    =				Features({"question": Value("string"		), "context": Value("string"		)}		)
        lowercase_    :List[Any]					    =				Features(
            {
                "answers": Sequence(
                    {
                        "text": Value("string"		),
                        "answer_start": Value("int32"		),
                    }		)
            }		)
        lowercase_    :int					    =				{
            "context_column": "input_input_context",
            "question_column": "input_question",
            "answers_column": "input_answers",
        }
        lowercase_    :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_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




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







     def 							lowercase__   (				self	:      Union[str, Any]		):





        """simple docstring"""




        lowercase_    :int					    =				Features({"text": Value("string"		)}		)
        lowercase_    :str					    =				Features({"summary": Value("string"		)}		)
        lowercase_    :Tuple					    =				{"text_column": "input_text", "summary_column": "input_summary"}
        lowercase_    :Optional[int]					    =				Summarization.from_dict(lowercase		)
        self.assertEqual("summarization"			,   task.task		)
        self.assertEqual(lowercase			,   task.input_schema		)
        self.assertEqual(lowercase			,   task.label_schema		)







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




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







     def 							lowercase__   (				self	:      Optional[int]		):





        """simple docstring"""




        lowercase_    :Union[str, Any]					    =				Features({"audio": Audio()}		)
        lowercase_    :str					    =				Features({"transcription": Value("string"		)}		)
        lowercase_    :Dict					    =				{
            "audio_column": "input_audio",
            "transcription_column": "input_transcription",
        }
        lowercase_    :Tuple					    =				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_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      int		):





        """simple docstring"""




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





     def 							lowercase__   (				self	:      List[str]		):





        """simple docstring"""




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





     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :int					    =				Features({"audio": Audio()}		)
        lowercase_    :Tuple					    =				Features({"labels": ClassLabel}		)
        lowercase_    :List[str]					    =				{
            "audio_column": "input_image",
            "label_column": "input_label",
        }
        lowercase_    :List[Any]					    =				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	:      Union[str, Any]		):





        """simple docstring"""




        lowercase_    :Dict					    =				AudioClassification(audio_column="input_audio"			,   label_column="input_label"		)
        self.assertEqual(task.label_schema["labels"]			,   lowercase		)
        lowercase_    :List[Any]					    =				task.align_with_features(Features({"input_label": ClassLabel(names=self.labels		)}		)		)
        self.assertEqual(task.label_schema["labels"]			,   ClassLabel(names=self.labels		)		)







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Union[str, Any]		):





        """simple docstring"""




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





     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




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





     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :Dict					    =				Features({"image": Image()}		)
        lowercase_    :str					    =				Features({"labels": ClassLabel}		)
        lowercase_    :Optional[Any]					    =				{
            "image_column": "input_image",
            "label_column": "input_label",
        }
        lowercase_    :str					    =				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	:      List[Any]		):





        """simple docstring"""




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







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Tuple		):





        """simple docstring"""




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

        def dont_keep_task(lowercase	:      Any		):
           lowercase_    :Optional[Any]					    =				deepcopy(lowercase		)
           lowercase_    :Dict					    =				0
           return out

        lowercase_    :List[str]					    =				dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == dataset.info.task_templates
        # reload from cache
        lowercase_    :List[Any]					    =				dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == dataset.info.task_templates

        lowercase_    :str					    =				dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == []
        # reload from cache
        lowercase_    :Union[str, Any]					    =				dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == []







     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




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

        def process(lowercase	:      Dict		):
           return example

        lowercase_    :Tuple					    =				dataset.remove_columns("label"		)
        lowercase_    :Optional[int]					    =				modified_dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == []


