o
    5ti                     @   sZ  zd dl mZ d dl mZ d dl mZ dZW n ey!   dZY nw d dlm	Z	m
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZ eddeddeddeddeddeddeddeddeddeddd
Zde
e  fddZ!de de	fddZd#de defd!d"Z"d S )$    )SUPPORTED_TASKS)TASK_ALIASES)
check_taskTF)DictList   )AudioClassificationEvaluator)#AutomaticSpeechRecognitionEvaluator)	Evaluator)ImageClassificationEvaluator)QuestionAnsweringEvaluator)SummarizationEvaluatorText2TextGenerationEvaluatorTranslationEvaluator)TextClassificationEvaluator)TextGenerationEvaluator)TokenClassificationEvaluatoraccuracy)implementationdefault_metric_namesquadseqeval
word_countbleurougewer)
ztext-classificationzimage-classificationzquestion-answeringztoken-classificationztext-generationztext2text-generationsummarizationtranslationzautomatic-speech-recognitionzaudio-classificationreturnc                   C   s   t t S )z3
    Returns a list of supported task strings.
    )listSUPPORTED_EVALUATOR_TASKSkeys r"   r"   O/home/ubuntu/.local/lib/python3.10/site-packages/evaluate/evaluator/__init__.pyget_supported_tasksR   s   r$   taskc                 C   sh   | t v rt |  } t| std|  dt  d| t v r(| t v r(t|  S td|  dt  d)a  
    Checks an incoming task string, to validate it's correct and returns the default Evaluator class and default metric
    name. It first performs a check to validata that the string is a valid `Pipeline` task, then it checks if it's a
    valid `Evaluator` task. `Evaluator` tasks are a substet of `Pipeline` tasks.
    Args:
        task (`str`):
            The task defining which evaluator will be returned. Currently accepted tasks are:
            - `"image-classification"`
            - `"question-answering"`
            - `"text-classification"` (alias `"sentiment-analysis"` available)
            - `"token-classification"`
    Returns:
        task_defaults: `dict`, contains the implementasion class of a give Evaluator and the default metric name.
    zUnknown task z, available tasks are: .)r   check_pipeline_taskKeyErrorr$   r    r!   SUPPORTED_PIPELINE_TASKS)r%   r"   r"   r#   r   Y   s   r   Nc                 C   s0   t stdt| }|d }|d }|| |dS )a  
    Utility factory method to build an [`Evaluator`].
    Evaluators encapsulate a task and a default metric name. They leverage `pipeline` functionality from `transformers`
    to simplify the evaluation of multiple combinations of models, datasets and metrics for a given task.
    Args:
        task (`str`):
            The task defining which evaluator will be returned. Currently accepted tasks are:
            - `"image-classification"`: will return a [`ImageClassificationEvaluator`].
            - `"question-answering"`: will return a [`QuestionAnsweringEvaluator`].
            - `"text-classification"` (alias `"sentiment-analysis"` available): will return a [`TextClassificationEvaluator`].
            - `"token-classification"`: will return a [`TokenClassificationEvaluator`].
    Returns:
        [`Evaluator`]: An evaluator suitable for the task.
    Examples:
    ```python
    >>> from evaluate import evaluator
    >>> # Sentiment analysis evaluator
    >>> evaluator("sentiment-analysis")
    ```zeIf you want to use the `Evaluator` you need `transformers`. Run `pip install evaluate[transformers]`.r   r   )r%   r   )TRANSFORMERS_AVAILABLEImportErrorr   )r%   targeted_taskevaluator_classr   r"   r"   r#   	evaluatorq   s   r.   )N)#transformers.pipelinesr   r)   r   r   r'   r*   r+   typingr   r   audio_classificationr   automatic_speech_recognitionr	   baser
   image_classificationr   question_answeringr   text2text_generationr   r   r   text_classificationr   text_generationr   token_classificationr   r    strr$   r.   r"   r"   r"   r#   <module>   sh   ,