import colorsys
import io

import cva
import matplotlib as mpl
import matplotlib.colors as mplc
import matplotlib.figure as mplfigure
import numpy as np
import torch
from matplotlib.backends.backend_agg import FigureCanvasAgg

from utils import img_tensorize


UpperCAmelCase     						=			10_00




class 				__lowerCAmelCase					:



 '''simple docstring'''

 def __init__(     self    :						str    ,     lowerCamelCase    :						int    ,     lowerCamelCase    :						List[str]=1.2    ,     lowerCamelCase    :						Optional[Any]="g"    ,     lowerCamelCase    :						Dict=0.5    ,     lowerCamelCase    :						int="-"    ,     lowerCamelCase    :						List[Any]="test_out.jpg"    ,     lowerCamelCase    :						Optional[int]=True    ,     lowerCamelCase    :						Tuple=False    ,     lowerCamelCase    :						Dict=None    ,     lowerCamelCase    :						Optional[Any]=None    ,     lowerCamelCase    :						List[str]=0.7    ,     )	->							Any:
        if isinstance(lowerCamelCase    ,     torch.Tensor					):
               _UpperCamelCase       :    Tuple					  =					img.numpy().astype('np.uint8'					)
        if isinstance(lowerCamelCase    ,     lowerCamelCase					):
               _UpperCamelCase       :    Union[str, Any]					  =					img_tensorize(lowerCamelCase					)
        assert isinstance(lowerCamelCase    ,     np.ndarray					)

        _UpperCamelCase       :    Optional[int]					  =					img.shape[1], img.shape[0]
        _UpperCamelCase       :    List[Any]					  =					mplfigure.Figure(frameon=lowerCamelCase					)
        _UpperCamelCase       :    Optional[int]					  =					fig.get_dpi()
        _UpperCamelCase       :    Dict					  =					(width * scale + 1e-2) / dpi
        _UpperCamelCase       :    Union[str, Any]					  =					(height * scale + 1e-2) / dpi
        fig.set_size_inches(lowerCamelCase    ,     lowerCamelCase					)
        _UpperCamelCase       :    List[Any]					  =					fig.add_axes([0.0, 0.0, 1.0, 1.0]					)
        ax.axis('off'					)
        ax.set_xlim(0.0    ,     lowerCamelCase					)
        ax.set_ylim(lowerCamelCase					)

        _UpperCamelCase       :    Dict					  =					saveas
        _UpperCamelCase       :    Any					  =					rgb
        _UpperCamelCase       :    List[Any]					  =					pynb
        _UpperCamelCase       :    Optional[int]					  =					img
        _UpperCamelCase       :    Optional[int]					  =					edgecolor
        _UpperCamelCase       :    Tuple					  =					0.5
        _UpperCamelCase       :    str					  =					linestyle
        _UpperCamelCase       :    List[Any]					  =					int(np.sqrt(min(lowerCamelCase    ,     lowerCamelCase					)					) * scale // 3					)
        _UpperCamelCase       :    Union[str, Any]					  =					width
        _UpperCamelCase       :    Optional[int]					  =					height
        _UpperCamelCase       :    Optional[int]					  =					scale
        _UpperCamelCase       :    Dict					  =					fig
        _UpperCamelCase       :    Dict					  =					ax
        _UpperCamelCase       :    Optional[int]					  =					pad
        _UpperCamelCase       :    List[str]					  =					idaobj
        _UpperCamelCase       :    Union[str, Any]					  =					idaattr
        _UpperCamelCase       :    Tuple					  =					FigureCanvasAgg(lowerCamelCase					)

 def    __snake_case   (     self    :						List[Any]    ,     lowerCamelCase    :						Union[str, Any]    ,     lowerCamelCase    :						Union[str, Any]=None					)	->							Optional[Any]:
        if color is None:
               _UpperCamelCase       :    Tuple					  =					self.edgecolor
        (_UpperCamelCase)       :    int					  =					box
        _UpperCamelCase       :    Any					  =					xa - xa
        _UpperCamelCase       :    Tuple					  =					ya - ya
        self.ax.add_patch(
            mpl.patches.Rectangle(
                (xa, ya)    ,     lowerCamelCase    ,     lowerCamelCase    ,     fill=lowerCamelCase    ,     edgecolor=lowerCamelCase    ,     linewidth=self.font_size // 3    ,     alpha=self.alpha    ,     linestyle=self.linestyle    ,     )					)

 def    __snake_case   (     self    :						Tuple    ,     lowerCamelCase    :						Tuple    ,     lowerCamelCase    :						str=None    ,     lowerCamelCase    :						List[str]=None    ,     lowerCamelCase    :						Union[str, Any]=None    ,     lowerCamelCase    :						Union[str, Any]=None					)	->							Any:
        if len(boxes.shape					) > 2:
               _UpperCamelCase       :    Union[str, Any]					  =					boxes[0]
        if len(obj_ids.shape					) > 1:
               _UpperCamelCase       :    Dict					  =					obj_ids[0]
        if len(obj_scores.shape					) > 1:
               _UpperCamelCase       :    int					  =					obj_scores[0]
        if len(attr_ids.shape					) > 1:
               _UpperCamelCase       :    Dict					  =					attr_ids[0]
        if len(attr_scores.shape					) > 1:
               _UpperCamelCase       :    Dict					  =					attr_scores[0]
        if isinstance(lowerCamelCase    ,     torch.Tensor					):
               _UpperCamelCase       :    Optional[int]					  =					boxes.numpy()
        if isinstance(lowerCamelCase    ,     lowerCamelCase					):
               _UpperCamelCase       :    Dict					  =					np.array(lowerCamelCase					)
        assert isinstance(lowerCamelCase    ,     np.ndarray					)
        _UpperCamelCase       :    int					  =					np.prod(boxes[:, 2:] - boxes[:, :2]    ,     axis=1					)
        _UpperCamelCase       :    int					  =					np.argsort(-areas					).tolist()
        _UpperCamelCase       :    Union[str, Any]					  =					boxes[sorted_idxs] if boxes is not None else None
        _UpperCamelCase       :    List[str]					  =					obj_ids[sorted_idxs] if obj_ids is not None else None
        _UpperCamelCase       :    List[str]					  =					obj_scores[sorted_idxs] if obj_scores is not None else None
        _UpperCamelCase       :    str					  =					attr_ids[sorted_idxs] if attr_ids is not None else None
        _UpperCamelCase       :    Optional[int]					  =					attr_scores[sorted_idxs] if attr_scores is not None else None

        _UpperCamelCase       :    int					  =					[self._random_color(maximum=1					) for _ in range(len(lowerCamelCase					)					)]
        _UpperCamelCase       :    Dict					  =					[assigned_colors[idx] for idx in sorted_idxs]
        if obj_ids is not None:
               _UpperCamelCase       :    Optional[int]					  =					self._create_text_labels_attr(lowerCamelCase    ,     lowerCamelCase    ,     lowerCamelCase    ,     lowerCamelCase					)
               for i in range(len(lowerCamelCase					)					):
                      _UpperCamelCase       :    Any					  =					assigned_colors[i]
                      self.add_box(boxes[i]    ,     lowerCamelCase					)
                      self.draw_labels(labels[i]    ,     boxes[i]    ,     lowerCamelCase					)

 def    __snake_case   (     self    :						List[str]    ,     lowerCamelCase    :						Optional[Any]    ,     lowerCamelCase    :						Tuple    ,     lowerCamelCase    :						Optional[int]					)	->							List[Any]:
        _UpperCamelCase       :    List[Any]					  =					box
        _UpperCamelCase       :    Optional[Any]					  =					(xa, ya)
        _UpperCamelCase       :    Union[str, Any]					  =					(ya - ya) * (xa - xa)
        _UpperCamelCase       :    Union[str, Any]					  =					_SMALL_OBJ * self.scale
        if instance_area < small or ya - ya < 4_0 * self.scale:
               if ya >= self.height - 5:
                      _UpperCamelCase       :    str					  =					(xa, ya)
               else:
                      _UpperCamelCase       :    Union[str, Any]					  =					(xa, ya)

        _UpperCamelCase       :    Any					  =					(ya - ya) / np.sqrt(self.height * self.width					)
        _UpperCamelCase       :    List[Any]					  =					self._change_color_brightness(lowerCamelCase    ,     brightness_factor=0.7					)
        _UpperCamelCase       :    Any					  =					np.clip((height_ratio - 0.0_2) / 0.0_8 + 1    ,     1.2    ,     2					)
        font_size *= 0.7_5 * self.font_size

        self.draw_text(
            text=lowerCamelCase    ,     position=lowerCamelCase    ,     color=lowerCamelCase    ,     )

 def    __snake_case   (     self    :						Optional[Any]    ,     lowerCamelCase    :						int    ,     lowerCamelCase    :						Dict    ,     lowerCamelCase    :						Any="g"    ,     lowerCamelCase    :						List[str]="left"    ,     )	->							int:
        _UpperCamelCase       :    List[Any]					  =					0
        _UpperCamelCase       :    List[str]					  =					self.font_size
        _UpperCamelCase       :    int					  =					np.maximum(list(mplc.to_rgb(lowerCamelCase					)					)    ,     0.2					)
        _UpperCamelCase       :    Optional[int]					  =					max(0.8    ,     np.max(lowerCamelCase					)					)
        _UpperCamelCase       :    str					  =					{
            'facecolor': 'black',
            'alpha': self.alpha,
            'pad': self.pad,
            'edgecolor': 'none',
        }
        _UpperCamelCase       :    Tuple					  =					position
        self.ax.text(
            lowerCamelCase    ,     lowerCamelCase    ,     lowerCamelCase    ,     size=font_size * self.scale    ,     family='sans-serif'    ,     bbox=lowerCamelCase    ,     verticalalignment='top'    ,     horizontalalignment=lowerCamelCase    ,     color=lowerCamelCase    ,     zorder=1_0    ,     rotation=lowerCamelCase    ,     )

 def    __snake_case   (     self    :						Tuple    ,     lowerCamelCase    :						List[str]=None					)	->							str:
        if saveas is None:
               _UpperCamelCase       :    List[str]					  =					self.saveas
        if saveas.lower().endswith('.jpg'					) or saveas.lower().endswith('.png'					):
               cva.imwrite(
                   lowerCamelCase    ,     self._get_buffer()[:, :, ::-1]    ,     )
        else:
               self.fig.savefig(lowerCamelCase					)

 def    __snake_case   (     self    :						Tuple    ,     lowerCamelCase    :						List[Any]    ,     lowerCamelCase    :						int    ,     lowerCamelCase    :						str    ,     lowerCamelCase    :						Tuple					)	->							Dict:
        _UpperCamelCase       :    Any					  =					[self.idaobj[i] for i in classes]
        _UpperCamelCase       :    Any					  =					[self.idaattr[i] for i in attr_classes]
        _UpperCamelCase       :    Any					  =					[
            f"{label} {score:.2f} {attr} {attr_score:.2f}"
            for label, score, attr, attr_score in zip(lowerCamelCase    ,     lowerCamelCase    ,     lowerCamelCase    ,     lowerCamelCase					)
        ]
        return labels

 def    __snake_case   (     self    :						List[Any]    ,     lowerCamelCase    :						int    ,     lowerCamelCase    :						List[Any]					)	->							str:
        _UpperCamelCase       :    str					  =					[self.idaobj[i] for i in classes]
        if scores is not None:
               if labels is None:
                      _UpperCamelCase       :    Union[str, Any]					  =					['{:.0f}%'.format(s * 1_0_0					) for s in scores]
               else:
                      _UpperCamelCase       :    Optional[int]					  =					['{} {:.0f}%'.format(lowerCamelCase    ,     s * 1_0_0					) for li, s in zip(lowerCamelCase    ,     lowerCamelCase					)]
        return labels

 def    __snake_case   (     self    :						Any    ,     lowerCamelCase    :						Tuple=2_5_5					)	->							Any:
        _UpperCamelCase       :    Union[str, Any]					  =					np.random.randint(0    ,     len(_COLORS					)					)
        _UpperCamelCase       :    List[Any]					  =					_COLORS[idx] * maximum
        if not self.rgb:
               _UpperCamelCase       :    int					  =					ret[::-1]
        return ret

 def    __snake_case   (     self    :						Optional[int]					)	->							Dict:
        if not self.pynb:
               _UpperCamelCase       :    List[Any]					  =					self.canvas.print_to_buffer()
               if (width, height) != (self.width, self.height):
                      _UpperCamelCase       :    Optional[Any]					  =					cva.resize(self.img    ,     (width, height)					)
               else:
                      _UpperCamelCase       :    Optional[Any]					  =					self.img
        else:
               _UpperCamelCase       :    List[str]					  =					io.BytesIO()  # works for cairo backend
               self.canvas.print_rgba(lowerCamelCase					)
               _UpperCamelCase       :    Dict					  =					self.width, self.height
               _UpperCamelCase       :    List[str]					  =					buf.getvalue()
               _UpperCamelCase       :    List[Any]					  =					self.img

        _UpperCamelCase       :    List[Any]					  =					np.frombuffer(lowerCamelCase    ,     dtype='uint8'					)
        _UpperCamelCase       :    Optional[int]					  =					buffer.reshape(lowerCamelCase    ,     lowerCamelCase    ,     4					)
        _UpperCamelCase       :    List[Any]					  =					np.split(lowerCamelCase    ,     [3]    ,     axis=2					)

        try:
               import numexpr as ne  # fuse them with numexpr

               _UpperCamelCase       :    List[str]					  =					ne.evaluate('img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)'					)
        except ImportError:
               _UpperCamelCase       :    Optional[int]					  =					alpha.astype('float32'					) / 2_5_5.0
               _UpperCamelCase       :    Any					  =					img * (1 - alpha) + rgb * alpha

        return visualized_image.astype('uint8'					)

 def    __snake_case   (     self    :						Any    ,     lowerCamelCase    :						List[Any]    ,     lowerCamelCase    :						int					)	->							str:
        assert brightness_factor >= -1.0 and brightness_factor <= 1.0
        _UpperCamelCase       :    Optional[Any]					  =					mplc.to_rgb(lowerCamelCase					)
        _UpperCamelCase       :    int					  =					colorsys.rgb_to_hls(*mplc.to_rgb(lowerCamelCase					)					)
        _UpperCamelCase       :    str					  =					polygon_color[1] + (brightness_factor * polygon_color[1])
        _UpperCamelCase       :    Union[str, Any]					  =					0.0 if modified_lightness < 0.0 else modified_lightness
        _UpperCamelCase       :    Optional[Any]					  =					1.0 if modified_lightness > 1.0 else modified_lightness
        _UpperCamelCase       :    Tuple					  =					colorsys.hls_to_rgb(polygon_color[0]    ,     lowerCamelCase    ,     polygon_color[2]					)
        return modified_color





UpperCAmelCase     						=			(
    np.array(
        [
            0.000,
            0.447,
            0.741,
            0.850,
            0.325,
            0.098,
            0.929,
            0.694,
            0.125,
            0.494,
            0.184,
            0.556,
            0.466,
            0.674,
            0.188,
            0.301,
            0.745,
            0.933,
            0.635,
            0.078,
            0.184,
            0.300,
            0.300,
            0.300,
            0.600,
            0.600,
            0.600,
            1.000,
            0.000,
            0.000,
            1.000,
            0.500,
            0.000,
            0.749,
            0.749,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.333,
            0.333,
            0.000,
            0.333,
            0.667,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            0.333,
            0.000,
            0.667,
            0.667,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            1.000,
            0.000,
            0.000,
            0.333,
            0.500,
            0.000,
            0.667,
            0.500,
            0.000,
            1.000,
            0.500,
            0.333,
            0.000,
            0.500,
            0.333,
            0.333,
            0.500,
            0.333,
            0.667,
            0.500,
            0.333,
            1.000,
            0.500,
            0.667,
            0.000,
            0.500,
            0.667,
            0.333,
            0.500,
            0.667,
            0.667,
            0.500,
            0.667,
            1.000,
            0.500,
            1.000,
            0.000,
            0.500,
            1.000,
            0.333,
            0.500,
            1.000,
            0.667,
            0.500,
            1.000,
            1.000,
            0.500,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.333,
            0.333,
            1.000,
            0.333,
            0.667,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.667,
            0.333,
            1.000,
            0.667,
            0.667,
            1.000,
            0.667,
            1.000,
            1.000,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            1.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.143,
            0.143,
            0.143,
            0.857,
            0.857,
            0.857,
            1.000,
            1.000,
            1.000,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)




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


UpperCAmelCase     						=			{
    '''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			(       lowercase_:		Optional[int]			):
       _UpperCamelCase       :    int					  =					task_cls()
       _UpperCamelCase       :    List[Any]					  =					asdict(lowercase_			)
       _UpperCamelCase       :    Union[str, Any]					  =					task_template_from_dict(lowercase_			)
       assert task == reloaded




class 				__lowerCAmelCase					:



 '''simple docstring'''

 def    __snake_case   (     self    :						Dict					)	->							Any:
        _UpperCamelCase       :    List[Any]					  =					LanguageModeling(text_column='input_text'					)
        assert {"input_text": "text"} == task.column_mapping

 def    __snake_case   (     self    :						List[Any]					)	->							List[Any]:
        _UpperCamelCase       :    List[str]					  =					Features({'text': Value('string'					)}					)
        _UpperCamelCase       :    Optional[int]					  =					{'text_column': 'input_text'}
        _UpperCamelCase       :    Optional[Any]					  =					LanguageModeling.from_dict(lowerCamelCase					)
        assert "language-modeling" == task.task
        assert input_schema == task.input_schema







class 				__lowerCAmelCase					(    a_  ):



 '''simple docstring'''

 def    __snake_case   (     self    :						List[Any]					)	->							Union[str, Any]:
        _UpperCamelCase       :    Union[str, Any]					  =					sorted(['pos', 'neg']					)

 def    __snake_case   (     self    :						List[str]					)	->							Dict:
        _UpperCamelCase       :    List[str]					  =					TextClassification(text_column='input_text'    ,     label_column='input_label'					)
        self.assertDictEqual({'input_text': 'text', 'input_label': 'labels'}    ,     task.column_mapping					)

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

 def    __snake_case   (     self    :						str					)	->							Optional[int]:
        _UpperCamelCase       :    Any					  =					TextClassification(text_column='input_text'    ,     label_column='input_label'					)
        self.assertEqual(task.label_schema['labels']    ,     lowerCamelCase					)
        _UpperCamelCase       :    str					  =					task.align_with_features(Features({'input_label': ClassLabel(names=self.labels					)}					)					)
        self.assertEqual(task.label_schema['labels']    ,     ClassLabel(names=self.labels					)					)







class 				__lowerCAmelCase					(    a_  ):



 '''simple docstring'''

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







class 				__lowerCAmelCase					(    a_  ):



 '''simple docstring'''

 def    __snake_case   (     self    :						Optional[Any]					)	->							List[str]:
        _UpperCamelCase       :    List[str]					  =					Summarization(text_column='input_text'    ,     summary_column='input_summary'					)
        self.assertDictEqual({'input_text': 'text', 'input_summary': 'summary'}    ,     task.column_mapping					)

 def    __snake_case   (     self    :						int					)	->							Dict:
        _UpperCamelCase       :    Tuple					  =					Features({'text': Value('string'					)}					)
        _UpperCamelCase       :    List[Any]					  =					Features({'summary': Value('string'					)}					)
        _UpperCamelCase       :    Any					  =					{'text_column': 'input_text', 'summary_column': 'input_summary'}
        _UpperCamelCase       :    Any					  =					Summarization.from_dict(lowerCamelCase					)
        self.assertEqual('summarization'    ,     task.task					)
        self.assertEqual(lowerCamelCase    ,     task.input_schema					)
        self.assertEqual(lowerCamelCase    ,     task.label_schema					)







class 				__lowerCAmelCase					(    a_  ):



 '''simple docstring'''

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

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







class 				__lowerCAmelCase					(    a_  ):



 '''simple docstring'''

 def    __snake_case   (     self    :						Union[str, Any]					)	->							Dict:
        _UpperCamelCase       :    Dict					  =					sorted(['pos', 'neg']					)

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

 def    __snake_case   (     self    :						Tuple					)	->							Dict:
        _UpperCamelCase       :    List[str]					  =					Features({'audio': Audio()}					)
        _UpperCamelCase       :    Union[str, Any]					  =					Features({'labels': ClassLabel}					)
        _UpperCamelCase       :    Union[str, Any]					  =					{
            'audio_column': 'input_image',
            'label_column': 'input_label',
        }
        _UpperCamelCase       :    Tuple					  =					AudioClassification.from_dict(lowerCamelCase					)
        self.assertEqual('audio-classification'    ,     task.task					)
        self.assertEqual(lowerCamelCase    ,     task.input_schema					)
        self.assertEqual(lowerCamelCase    ,     task.label_schema					)

 def    __snake_case   (     self    :						Any					)	->							List[Any]:
        _UpperCamelCase       :    Any					  =					AudioClassification(audio_column='input_audio'    ,     label_column='input_label'					)
        self.assertEqual(task.label_schema['labels']    ,     lowerCamelCase					)
        _UpperCamelCase       :    Union[str, Any]					  =					task.align_with_features(Features({'input_label': ClassLabel(names=self.labels					)}					)					)
        self.assertEqual(task.label_schema['labels']    ,     ClassLabel(names=self.labels					)					)







class 				__lowerCAmelCase					(    a_  ):



 '''simple docstring'''

 def    __snake_case   (     self    :						int					)	->							str:
        _UpperCamelCase       :    Tuple					  =					sorted(['pos', 'neg']					)

 def    __snake_case   (     self    :						Optional[Any]					)	->							Any:
        _UpperCamelCase       :    str					  =					ImageClassification(image_column='input_image'    ,     label_column='input_label'					)
        self.assertDictEqual({'input_image': 'image', 'input_label': 'labels'}    ,     task.column_mapping					)

 def    __snake_case   (     self    :						int					)	->							Dict:
        _UpperCamelCase       :    Dict					  =					Features({'image': Image()}					)
        _UpperCamelCase       :    Tuple					  =					Features({'labels': ClassLabel}					)
        _UpperCamelCase       :    Optional[int]					  =					{
            'image_column': 'input_image',
            'label_column': 'input_label',
        }
        _UpperCamelCase       :    List[str]					  =					ImageClassification.from_dict(lowerCamelCase					)
        self.assertEqual('image-classification'    ,     task.task					)
        self.assertEqual(lowerCamelCase    ,     task.input_schema					)
        self.assertEqual(lowerCamelCase    ,     task.label_schema					)

 def    __snake_case   (     self    :						List[str]					)	->							Union[str, Any]:
        _UpperCamelCase       :    Any					  =					ImageClassification(image_column='input_image'    ,     label_column='input_label'					)
        self.assertEqual(task.label_schema['labels']    ,     lowerCamelCase					)
        _UpperCamelCase       :    Optional[Any]					  =					task.align_with_features(Features({'input_label': ClassLabel(names=self.labels					)}					)					)
        self.assertEqual(task.label_schema['labels']    ,     ClassLabel(names=self.labels					)					)







class 				__lowerCAmelCase					(    a_  ):



 '''simple docstring'''

 def    __snake_case   (     self    :						List[str]					)	->							Dict:
        _UpperCamelCase       :    List[str]					  =					DatasetInfo(task_templates=QuestionAnsweringExtractive()					)
        _UpperCamelCase       :    Tuple					  =					Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}    ,     info=lowerCamelCase					)
        assert isinstance(dataset.info.task_templates    ,     lowerCamelCase					)
        assert len(dataset.info.task_templates					) == 1

        def keep_task(lowerCamelCase    :						Dict					):
               return x

        def dont_keep_task(lowerCamelCase    :						List[Any]					):
               _UpperCamelCase       :    Union[str, Any]					  =					deepcopy(lowerCamelCase					)
               _UpperCamelCase       :    List[str]					  =					0
               return out

        _UpperCamelCase       :    Any					  =					dataset.map(lowerCamelCase					)
        assert mapped_dataset.info.task_templates == dataset.info.task_templates
        # reload from cache
        _UpperCamelCase       :    Any					  =					dataset.map(lowerCamelCase					)
        assert mapped_dataset.info.task_templates == dataset.info.task_templates

        _UpperCamelCase       :    int					  =					dataset.map(lowerCamelCase					)
        assert mapped_dataset.info.task_templates == []
        # reload from cache
        _UpperCamelCase       :    int					  =					dataset.map(lowerCamelCase					)
        assert mapped_dataset.info.task_templates == []

 def    __snake_case   (     self    :						Union[str, Any]					)	->							Any:
        _UpperCamelCase       :    List[str]					  =					Features({'text': Value('string'					), 'label': ClassLabel(names=('pos', 'neg')					)}					)
        _UpperCamelCase       :    List[str]					  =					TextClassification(text_column='text'    ,     label_column='label'					)
        _UpperCamelCase       :    List[str]					  =					DatasetInfo(features=lowerCamelCase    ,     task_templates=lowerCamelCase					)
        _UpperCamelCase       :    Any					  =					Dataset.from_dict({'text': ['A sentence.'], 'label': ['pos']}    ,     info=lowerCamelCase					)

        def process(lowerCamelCase    :						Any					):
               return example

        _UpperCamelCase       :    Dict					  =					dataset.remove_columns('label'					)
        _UpperCamelCase       :    Union[str, Any]					  =					modified_dataset.map(lowerCamelCase					)
        assert mapped_dataset.info.task_templates == []



