code: 
  """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
  
  
  __magic_name__		       =				{
      '''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     __lowerCamelCase	(		UpperCamelCase__      ):
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  	_UpperCAmelCase =						task_cls()
  	_UpperCAmelCase =						asdict(UpperCamelCase__      )
  	_UpperCAmelCase =						task_template_from_dict(UpperCamelCase__      )
  	assert task == reloaded
  
  
  class    _lowerCAmelCase						:
  
  
  
  							def       _a   (      self   )							->							Dict:
  								_UpperCAmelCase =						LanguageModeling(text_column="input_text"   )
  								assert {"input_text": "text"} == task.column_mapping
  
  
  
  							def       _a   (      self   )							->							Union[str, Any]:
  								_UpperCAmelCase =						Features({"text": Value("string"   )}   )
  								_UpperCAmelCase =						{"text_column": "input_text"}
  								_UpperCAmelCase =						LanguageModeling.from_dict(a_   )
  								assert "language-modeling" == task.task
  								assert input_schema == task.input_schema
  
  
  
  
  
  class    _lowerCAmelCase						(						lowerCamelCase						):
  
  
  
  							def       _a   (      self   )							->							Union[str, Any]:
  								_UpperCAmelCase =						sorted(["pos", "neg"]   )
  
  
  
  							def       _a   (      self   )							->							Any:
  								_UpperCAmelCase =						TextClassification(text_column="input_text" ,						label_column="input_label"   )
  								self.assertDictEqual({"input_text": "text", "input_label": "labels"} ,						task.column_mapping   )
  
  
  
  							def       _a   (      self   )							->							Tuple:
  								_UpperCAmelCase =						Features({"text": Value("string"   )}   )
  								# Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
  								_UpperCAmelCase =						Features({"labels": ClassLabel}   )
  								_UpperCAmelCase =						{"text_column": "input_text", "label_column": "input_labels"}
  								_UpperCAmelCase =						TextClassification.from_dict(a_   )
  								self.assertEqual("text-classification" ,						task.task   )
  								self.assertEqual(a_ ,						task.input_schema   )
  								self.assertEqual(a_ ,						task.label_schema   )
  
  
  
  							def       _a   (      self   )							->							int:
  								_UpperCAmelCase =						TextClassification(text_column="input_text" ,						label_column="input_label"   )
  								self.assertEqual(task.label_schema["labels"] ,						a_   )
  								_UpperCAmelCase =						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       _a   (      self   )							->							str:
  								_UpperCAmelCase =						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       _a   (      self   )							->							Optional[int]:
  								_UpperCAmelCase =						Features({"question": Value("string"   ), "context": Value("string"   )}   )
  								_UpperCAmelCase =						Features(
  								    {
  								        "answers": Sequence(
  								            {
  								                "text": Value("string"   ),
  								                "answer_start": Value("int32"   ),
  								            }   )
  								    }   )
  								_UpperCAmelCase =						{
  								    "context_column": "input_input_context",
  								    "question_column": "input_question",
  								    "answers_column": "input_answers",
  								}
  								_UpperCAmelCase =						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						(						lowerCamelCase						):
  
  
  
  							def       _a   (      self   )							->							Tuple:
  								_UpperCAmelCase =						Summarization(text_column="input_text" ,						summary_column="input_summary"   )
  								self.assertDictEqual({"input_text": "text", "input_summary": "summary"} ,						task.column_mapping   )
  
  
  
  							def       _a   (      self   )							->							Optional[int]:
  								_UpperCAmelCase =						Features({"text": Value("string"   )}   )
  								_UpperCAmelCase =						Features({"summary": Value("string"   )}   )
  								_UpperCAmelCase =						{"text_column": "input_text", "summary_column": "input_summary"}
  								_UpperCAmelCase =						Summarization.from_dict(a_   )
  								self.assertEqual("summarization" ,						task.task   )
  								self.assertEqual(a_ ,						task.input_schema   )
  								self.assertEqual(a_ ,						task.label_schema   )
  
  
  
  
  
  class    _lowerCAmelCase						(						lowerCamelCase						):
  
  
  
  							def       _a   (      self   )							->							int:
  								_UpperCAmelCase =						AutomaticSpeechRecognition(audio_column="input_audio" ,						transcription_column="input_transcription"   )
  								self.assertDictEqual({"input_audio": "audio", "input_transcription": "transcription"} ,						task.column_mapping   )
  
  
  
  							def       _a   (      self   )							->							Optional[Any]:
  								_UpperCAmelCase =						Features({"audio": Audio()}   )
  								_UpperCAmelCase =						Features({"transcription": Value("string"   )}   )
  								_UpperCAmelCase =						{
  								    "audio_column": "input_audio",
  								    "transcription_column": "input_transcription",
  								}
  								_UpperCAmelCase =						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						(						lowerCamelCase						):
  
  
  
  							def       _a   (      self   )							->							Union[str, Any]:
  								_UpperCAmelCase =						sorted(["pos", "neg"]   )
  
  
  
  							def       _a   (      self   )							->							str:
  								_UpperCAmelCase =						AudioClassification(audio_column="input_audio" ,						label_column="input_label"   )
  								self.assertDictEqual({"input_audio": "audio", "input_label": "labels"} ,						task.column_mapping   )
  
  
  
  							def       _a   (      self   )							->							Union[str, Any]:
  								_UpperCAmelCase =						Features({"audio": Audio()}   )
  								_UpperCAmelCase =						Features({"labels": ClassLabel}   )
  								_UpperCAmelCase =						{
  								    "audio_column": "input_image",
  								    "label_column": "input_label",
  								}
  								_UpperCAmelCase =						AudioClassification.from_dict(a_   )
  								self.assertEqual("audio-classification" ,						task.task   )
  								self.assertEqual(a_ ,						task.input_schema   )
  								self.assertEqual(a_ ,						task.label_schema   )
  
  
  
  							def       _a   (      self   )							->							List[Any]:
  								_UpperCAmelCase =						AudioClassification(audio_column="input_audio" ,						label_column="input_label"   )
  								self.assertEqual(task.label_schema["labels"] ,						a_   )
  								_UpperCAmelCase =						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       _a   (      self   )							->							Union[str, Any]:
  								_UpperCAmelCase =						sorted(["pos", "neg"]   )
  
  
  
  							def       _a   (      self   )							->							Any:
  								_UpperCAmelCase =						ImageClassification(image_column="input_image" ,						label_column="input_label"   )
  								self.assertDictEqual({"input_image": "image", "input_label": "labels"} ,						task.column_mapping   )
  
  
  
  							def       _a   (      self   )							->							Any:
  								_UpperCAmelCase =						Features({"image": Image()}   )
  								_UpperCAmelCase =						Features({"labels": ClassLabel}   )
  								_UpperCAmelCase =						{
  								    "image_column": "input_image",
  								    "label_column": "input_label",
  								}
  								_UpperCAmelCase =						ImageClassification.from_dict(a_   )
  								self.assertEqual("image-classification" ,						task.task   )
  								self.assertEqual(a_ ,						task.input_schema   )
  								self.assertEqual(a_ ,						task.label_schema   )
  
  
  
  							def       _a   (      self   )							->							Optional[int]:
  								_UpperCAmelCase =						ImageClassification(image_column="input_image" ,						label_column="input_label"   )
  								self.assertEqual(task.label_schema["labels"] ,						a_   )
  								_UpperCAmelCase =						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       _a   (      self   )							->							Optional[Any]:
  								_UpperCAmelCase =						DatasetInfo(task_templates=QuestionAnsweringExtractive()   )
  								_UpperCAmelCase =						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_   ):
  									return x
  
  								def dont_keep_task(a_   ):
  									_UpperCAmelCase =						deepcopy(a_   )
  									_UpperCAmelCase =						0
  									return out
  
  								_UpperCAmelCase =						dataset.map(a_   )
  								assert mapped_dataset.info.task_templates == dataset.info.task_templates
  								# reload from cache
  								_UpperCAmelCase =						dataset.map(a_   )
  								assert mapped_dataset.info.task_templates == dataset.info.task_templates
  
  								_UpperCAmelCase =						dataset.map(a_   )
  								assert mapped_dataset.info.task_templates == []
  								# reload from cache
  								_UpperCAmelCase =						dataset.map(a_   )
  								assert mapped_dataset.info.task_templates == []
  
  
  
  							def       _a   (      self   )							->							Union[str, Any]:
  								_UpperCAmelCase =						Features({"text": Value("string"   ), "label": ClassLabel(names=("pos", "neg")   )}   )
  								_UpperCAmelCase =						TextClassification(text_column="text" ,						label_column="label"   )
  								_UpperCAmelCase =						DatasetInfo(features=a_ ,						task_templates=a_   )
  								_UpperCAmelCase =						Dataset.from_dict({"text": ["A sentence."], "label": ["pos"]} ,						info=a_   )
  
  								def process(a_   ):
  									return example
  
  								_UpperCAmelCase =						dataset.remove_columns("label"   )
  								_UpperCAmelCase =						modified_dataset.map(a_   )
  								assert mapped_dataset.info.task_templates == []
  
  
  
  
  
style_context: 
  """simple docstring"""
  import subprocess
  from typing import Union
  
  import numpy as np
  import requests
  
  from ..utils import add_end_docstrings, is_torch_available, is_torchaudio_available, logging
  from .base import PIPELINE_INIT_ARGS, Pipeline
  
  
  if is_torch_available():
  			from ..models.auto.modeling_auto import MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
  
  __magic_name__		       =				logging.get_logger(__name__)
  
  
  
  
  def     __lowerCamelCase  (		UpperCamelCase__				,     UpperCamelCase__      ):
  
  
  	"""simple docstring"""
  
  
  
  
  
  
  	_UpperCAmelCase =						f"{sampling_rate}"
  	_UpperCAmelCase =						"1"
  	_UpperCAmelCase =						"f32le"
  	_UpperCAmelCase =						[
  	    "ffmpeg",
  	    "-i",
  	    "pipe:0",
  	    "-ac",
  	    ac,
  	    "-ar",
  	    ar,
  	    "-f",
  	    format_for_conversion,
  	    "-hide_banner",
  	    "-loglevel",
  	    "quiet",
  	    "pipe:1",
  	]
  
  	try:
  		_UpperCAmelCase =						subprocess.Popen(UpperCamelCase__				,     stdin=subprocess.PIPE				,     stdout=subprocess.PIPE      )
  	except FileNotFoundError:
  		raise ValueError("ffmpeg was not found but is required to load audio files from filename"      )
  	_UpperCAmelCase =						ffmpeg_process.communicate(UpperCamelCase__      )
  	_UpperCAmelCase =						output_stream[0]
  
  	_UpperCAmelCase =						np.frombuffer(UpperCamelCase__				,     np.floataa      )
  	if audio.shape[0] == 0:
  		raise ValueError("Malformed soundfile"      )
  	return audio
  
  
  
  @add_end_docstrings(lowerCamelCase						)
  class    _lowerCAmelCase						(						lowerCamelCase						):
  
  
  
  							def __init__(      self ,						*a_ ,						**a_   )							->							Union[str, Any]:
  								# Default, might be overriden by the model.config.
  								_UpperCAmelCase =						5
  								super().__init__(*a_ ,						**a_   )
  
  								if self.framework != "pt":
  									raise ValueError(f"The {self.__class__} is only available in PyTorch."   )
  
  								self.check_model_type(a_   )
  
  
  
  							def __call__(      self ,						a_ ,						**a_ ,						)							->							int:
  								return super().__call__(a_ ,						**a_   )
  
  
  
  							def       _a   (      self ,						a_=None ,						**a_   )							->							Dict:
  								# No parameters on this pipeline right now
  								_UpperCAmelCase =						{}
  								if top_k is not None:
  									if top_k > self.model.config.num_labels:
  										_UpperCAmelCase =						self.model.config.num_labels
  									_UpperCAmelCase =						top_k
  								return {}, {}, postprocess_params
  
  
  
  							def       _a   (      self ,						a_   )							->							str:
  								if isinstance(a_ ,						a_   ):
  									if inputs.startswith("http://"   ) or inputs.startswith("https://"   ):
  										# We need to actually check for a real protocol, otherwise it's impossible to use a local file
  										# like http_huggingface_co.png
  										_UpperCAmelCase =						requests.get(a_   ).content
  									else:
  										with open(a_ ,						"rb"   ) as f:
  											_UpperCAmelCase =						f.read()
  
  								if isinstance(a_ ,						a_   ):
  									_UpperCAmelCase =						ffmpeg_read(a_ ,						self.feature_extractor.sampling_rate   )
  
  								if isinstance(a_ ,						a_   ):
  									# Accepting `"array"` which is the key defined in `datasets` for
  									# better integration
  									if not ("sampling_rate" in inputs and ("raw" in inputs or "array" in inputs)):
  										raise ValueError(
  										    "When passing a dictionary to AudioClassificationPipeline, the dict needs to contain a "
  										    "\"raw\" key containing the numpy array representing the audio and a \"sampling_rate\" key, "
  										    "containing the sampling_rate associated with that array"   )
  
  									_UpperCAmelCase =						inputs.pop("raw" ,						a_   )
  									if _inputs is None:
  										# Remove path which will not be used from `datasets`.
  										inputs.pop("path" ,						a_   )
  										_UpperCAmelCase =						inputs.pop("array" ,						a_   )
  									_UpperCAmelCase =						inputs.pop("sampling_rate"   )
  									_UpperCAmelCase =						_inputs
  									if in_sampling_rate != self.feature_extractor.sampling_rate:
  										import torch
  
  										if is_torchaudio_available():
  											from torchaudio import functional as F
  										else:
  											raise ImportError(
  											    "torchaudio is required to resample audio samples in AudioClassificationPipeline. "
  											    "The torchaudio package can be installed through: `pip install torchaudio`."   )
  
  										_UpperCAmelCase =						F.resample(
  										    torch.from_numpy(a_   ) ,						a_ ,						self.feature_extractor.sampling_rate   ).numpy()
  
  								if not isinstance(a_ ,						np.ndarray   ):
  									raise ValueError("We expect a numpy ndarray as input"   )
  								if len(inputs.shape   ) != 1:
  									raise ValueError("We expect a single channel audio input for AudioClassificationPipeline"   )
  
  								_UpperCAmelCase =						self.feature_extractor(
  								    a_ ,						sampling_rate=self.feature_extractor.sampling_rate ,						return_tensors="pt"   )
  								return processed
  
  
  
  							def       _a   (      self ,						a_   )							->							List[str]:
  								_UpperCAmelCase =						self.model(**a_   )
  								return model_outputs
  
  
  
  							def       _a   (      self ,						a_ ,						a_=5   )							->							int:
  								_UpperCAmelCase =						model_outputs.logits[0].softmax(-1   )
  								_UpperCAmelCase ,      _UpperCAmelCase =						probs.topk(a_   )
  
  								_UpperCAmelCase =						scores.tolist()
  								_UpperCAmelCase =						ids.tolist()
  
  								_UpperCAmelCase =						[{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(a_ ,						a_   )]
  
  								return labels
  
  
  
  
  