code: 
  
  
  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 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase				)    ->  Optional[int]:
  						_a     =			task_cls()
  						_a     =			asdict(_UpperCAmelCase				)
  						_a     =			task_template_from_dict(_UpperCAmelCase				)
  						assert task == reloaded
  
  
  
  
  class 					_UpperCamelCase :
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Any		):
  													_a     =			LanguageModeling(text_column='input_text'		)
  													assert {"input_text": "text"} == task.column_mapping
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Dict		):
  													_a     =			Features({'text': Value('string'		)}		)
  													_a     =			{'text_column': 'input_text'}
  													_a     =			LanguageModeling.from_dict(SCREAMING_SNAKE_CASE_		)
  													assert "language-modeling" == task.task
  													assert input_schema == task.input_schema
  
  
  
  
  class 					_UpperCamelCase (      lowerCamelCase__	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				int		):
  													_a     =			sorted(['pos', 'neg']		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Dict		):
  													_a     =			TextClassification(text_column='input_text'		,				label_column='input_label'		)
  													self.assertDictEqual({'input_text': 'text', 'input_label': 'labels'}		,				task.column_mapping		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				str		):
  													_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(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 		_UpperCAmelCase	(		self  :				Union[str, Any]		):
  													_a     =			TextClassification(text_column='input_text'		,				label_column='input_label'		)
  													self.assertEqual(task.label_schema['labels']		,				SCREAMING_SNAKE_CASE_		)
  													_a     =			task.align_with_features(Features({'input_label': ClassLabel(names=self.labels		)}		)		)
  													self.assertEqual(task.label_schema['labels']		,				ClassLabel(names=self.labels		)		)
  
  
  
  
  class 					_UpperCamelCase (      lowerCamelCase__	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				List[Any]		):
  													_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 		_UpperCAmelCase	(		self  :				List[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(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 					_UpperCamelCase (      lowerCamelCase__	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Any		):
  													_a     =			Summarization(text_column='input_text'		,				summary_column='input_summary'		)
  													self.assertDictEqual({'input_text': 'text', 'input_summary': 'summary'}		,				task.column_mapping		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Dict		):
  													_a     =			Features({'text': Value('string'		)}		)
  													_a     =			Features({'summary': Value('string'		)}		)
  													_a     =			{'text_column': 'input_text', 'summary_column': 'input_summary'}
  													_a     =			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 					_UpperCamelCase (      lowerCamelCase__	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Tuple		):
  													_a     =			AutomaticSpeechRecognition(audio_column='input_audio'		,				transcription_column='input_transcription'		)
  													self.assertDictEqual({'input_audio': 'audio', 'input_transcription': 'transcription'}		,				task.column_mapping		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Dict		):
  													_a     =			Features({'audio': Audio()}		)
  													_a     =			Features({'transcription': Value('string'		)}		)
  													_a     =			{
  													    'audio_column': 'input_audio',
  													    'transcription_column': 'input_transcription',
  													}
  													_a     =			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 					_UpperCamelCase (      lowerCamelCase__	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				List[str]		):
  													_a     =			sorted(['pos', 'neg']		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Tuple		):
  													_a     =			AudioClassification(audio_column='input_audio'		,				label_column='input_label'		)
  													self.assertDictEqual({'input_audio': 'audio', 'input_label': 'labels'}		,				task.column_mapping		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				List[str]		):
  													_a     =			Features({'audio': Audio()}		)
  													_a     =			Features({'labels': ClassLabel}		)
  													_a     =			{
  													    'audio_column': 'input_image',
  													    'label_column': 'input_label',
  													}
  													_a     =			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 		_UpperCAmelCase	(		self  :				str		):
  													_a     =			AudioClassification(audio_column='input_audio'		,				label_column='input_label'		)
  													self.assertEqual(task.label_schema['labels']		,				SCREAMING_SNAKE_CASE_		)
  													_a     =			task.align_with_features(Features({'input_label': ClassLabel(names=self.labels		)}		)		)
  													self.assertEqual(task.label_schema['labels']		,				ClassLabel(names=self.labels		)		)
  
  
  
  
  class 					_UpperCamelCase (      lowerCamelCase__	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Tuple		):
  													_a     =			sorted(['pos', 'neg']		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				List[Any]		):
  													_a     =			ImageClassification(image_column='input_image'		,				label_column='input_label'		)
  													self.assertDictEqual({'input_image': 'image', 'input_label': 'labels'}		,				task.column_mapping		)
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				List[str]		):
  													_a     =			Features({'image': Image()}		)
  													_a     =			Features({'labels': ClassLabel}		)
  													_a     =			{
  													    'image_column': 'input_image',
  													    'label_column': 'input_label',
  													}
  													_a     =			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 		_UpperCAmelCase	(		self  :				Dict		):
  													_a     =			ImageClassification(image_column='input_image'		,				label_column='input_label'		)
  													self.assertEqual(task.label_schema['labels']		,				SCREAMING_SNAKE_CASE_		)
  													_a     =			task.align_with_features(Features({'input_label': ClassLabel(names=self.labels		)}		)		)
  													self.assertEqual(task.label_schema['labels']		,				ClassLabel(names=self.labels		)		)
  
  
  
  
  class 					_UpperCamelCase (      lowerCamelCase__	):
  
  
  
  
  
  
  
  							'''simple docstring'''
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				Optional[Any]		):
  													_a     =			DatasetInfo(task_templates=QuestionAnsweringExtractive()		)
  													_a     =			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_  :				Any		):
  																			return x
  
  													def dont_keep_task(SCREAMING_SNAKE_CASE_  :				Any		):
  																			_a     =			deepcopy(SCREAMING_SNAKE_CASE_		)
  																			_a     =			0
  																			return out
  
  													_a     =			dataset.map(SCREAMING_SNAKE_CASE_		)
  													assert mapped_dataset.info.task_templates == dataset.info.task_templates
  													# reload from cache
  													_a     =			dataset.map(SCREAMING_SNAKE_CASE_		)
  													assert mapped_dataset.info.task_templates == dataset.info.task_templates
  
  													_a     =			dataset.map(SCREAMING_SNAKE_CASE_		)
  													assert mapped_dataset.info.task_templates == []
  													# reload from cache
  													_a     =			dataset.map(SCREAMING_SNAKE_CASE_		)
  													assert mapped_dataset.info.task_templates == []
  
  
  
  
  
  
  
  							def 		_UpperCAmelCase	(		self  :				str		):
  													_a     =			Features({'text': Value('string'		), 'label': ClassLabel(names=('pos', 'neg')		)}		)
  													_a     =			TextClassification(text_column='text'		,				label_column='label'		)
  													_a     =			DatasetInfo(features=SCREAMING_SNAKE_CASE_		,				task_templates=SCREAMING_SNAKE_CASE_		)
  													_a     =			Dataset.from_dict({'text': ['A sentence.'], 'label': ['pos']}		,				info=SCREAMING_SNAKE_CASE_		)
  
  													def process(SCREAMING_SNAKE_CASE_  :				int		):
  																			return example
  
  													_a     =			dataset.remove_columns('label'		)
  													_a     =			modified_dataset.map(SCREAMING_SNAKE_CASE_		)
  													assert mapped_dataset.info.task_templates == []
  
  
  
style_context: 
  
  
  import numpy as np
  import PIL
  import torch
  import torchvision.transforms as T
  import torchvision.transforms.functional as TF
  from PIL import Image
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase							,     _UpperCAmelCase=256				)    ->  Dict:
  						_a     =			min(img.size				)
  
  						if s < target_image_size:
  												raise ValueError(f"""min dim for image {s} < {target_image_size}"""				)
  
  						_a     =			target_image_size / s
  						_a     =			(round(r * img.size[1]				), round(r * img.size[0]				))
  						_a     =			TF.resize(_UpperCAmelCase							,     _UpperCAmelCase							,     interpolation=PIL.Image.LANCZOS				)
  						_a     =			TF.center_crop(_UpperCAmelCase							,     output_size=2 * [target_image_size]				)
  						_a     =			torch.unsqueeze(T.ToTensor()(_UpperCAmelCase				)							,     0				)
  						return img
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase				)    ->  List[Any]:
  						_a     =			2.0 * x - 1.0
  						return x
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase							,     _UpperCAmelCase=True							,     _UpperCAmelCase="RGB"				)    ->  Optional[Any]:
  						_a     =			x.detach().cpu()
  						if process:
  												_a     =			post_process_tensor(_UpperCAmelCase				)
  						_a     =			x.numpy()
  						if process:
  												_a     =			(255 * x).astype(np.uinta				)
  						_a     =			Image.fromarray(_UpperCAmelCase				)
  						if not x.mode == mode:
  												_a     =			x.convert(_UpperCAmelCase				)
  						return x
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase				)    ->  Optional[Any]:
  						_a     =			torch.clamp(_UpperCAmelCase							,     -1.0							,     1.0				)
  						_a     =			(x + 1.0) / 2.0
  						_a     =			x.permute(1							,     2							,     0				)
  						return x
  
  
  
  
  
  
  def 							SCREAMING_SNAKE_CASE					(  _UpperCAmelCase				)    ->  str:
  						_a     =			post_process_tensor(x.squeeze()				)
  						return x.permute(2							,     0							,     1				).unsqueeze(0				)
  
  
  