o
    ©ôjí  ã                   @   s–   d dl mZ d dlmZmZmZmZ d dlmZm	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZ d dlmZmZ esAd	gZG d
d„ deƒZdS )é    )ÚSequence)ÚAnyÚListÚOptionalÚUnion)ÚTensorÚstack)ÚLiteral)Ú_eed_computeÚ_eed_update)ÚMetric)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEúExtendedEditDistance.plotc                       s  e Zd ZU dZdZeed< dZeed< dZeed< dZ	e
ed< dZe
ed	< ee ed
< 						d%ded dede
de
de
de
deddf‡ fdd„Zdeeee f deeeee f  ddfdd„Zdeeeeef f fdd „Z	d&d!eeeee f  d"ee defd#d$„Z‡  ZS )'ÚExtendedEditDistanceaÜ  Compute extended edit distance score (`ExtendedEditDistance`_) for strings or list of strings.

    The metric utilises the Levenshtein distance and extends it by adding a jump operation.

    As input to ``forward`` and ``update`` the metric accepts the following input:

    - ``preds`` (:class:`~Sequence`): An iterable of hypothesis corpus
    - ``target`` (:class:`~Sequence`): An iterable of iterables of reference corpus

    As output of ``forward`` and ``compute`` the metric returns the following output:

    - ``eed`` (:class:`~torch.Tensor`): A tensor with the extended edit distance score

    Args:
        language: Language used in sentences. Only supports English (en) and Japanese (ja) for now.
        return_sentence_level_score: An indication of whether sentence-level EED score is to be returned
        alpha: optimal jump penalty, penalty for jumps between characters
        rho: coverage cost, penalty for repetition of characters
        deletion: penalty for deletion of character
        insertion: penalty for insertion or substitution of character
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Example:
        >>> from torchmetrics.text import ExtendedEditDistance
        >>> preds = ["this is the prediction", "here is an other sample"]
        >>> target = ["this is the reference", "here is another one"]
        >>> eed = ExtendedEditDistance()
        >>> eed(preds=preds, target=target)
        tensor(0.3078)

    FÚhigher_is_betterÚis_differentiableÚfull_state_updateg        Úplot_lower_boundç      ð?Úplot_upper_boundÚsentence_eedÚenç       @ç333333Ó?çš™™™™™É?Úlanguage©r   ÚjaÚreturn_sentence_level_scoreÚalphaÚrhoÚdeletionÚ	insertionÚkwargsÚreturnNc           
         s¬   t ƒ jd
i |¤Ž |dvrtd|› �ƒ‚|| _|| _tg d¢||||gƒD ]\}}	t|	tƒr7t|	tƒr?|	dk r?td|› d�ƒ‚q%|| _|| _	|| _
|| _| jdg dd	� d S )Nr   z?Expected argument `language` to either be `en` or `ja` but got )r!   r"   r#   r$   r   zParameter `z)` is expected to be a non-negative float.r   Úcat)Údist_reduce_fx© )ÚsuperÚ__init__Ú
ValueErrorr   r    ÚzipÚ
isinstanceÚfloatr!   r"   r#   r$   Ú	add_state)
Úselfr   r    r!   r"   r#   r$   r%   Ú
param_nameÚparam©Ú	__class__r)   úh/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torchmetrics/text/eed.pyr+   F   s   
€zExtendedEditDistance.__init__ÚpredsÚtargetc              	   C   s(   t ||| j| j| j| j| j| jƒ| _dS )z*Update state with predictions and targets.N)r   r   r!   r"   r#   r$   r   )r1   r7   r8   r)   r)   r6   Úupdatec   s   
øzExtendedEditDistance.updatec                 C   s"   t | jƒ}| jr|t| jƒfS |S )z'Calculate extended edit distance score.)r
   r   r    r   )r1   Úaverager)   r)   r6   Úcomputet   s   
zExtendedEditDistance.computeÚvalÚaxc                 C   s   |   ||¡S )aè  Plot a single or multiple values from the metric.

        Args:
            val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
                If no value is provided, will automatically call `metric.compute` and plot that result.
            ax: An matplotlib axis object. If provided will add plot to that axis

        Returns:
            Figure and Axes object

        Raises:
            ModuleNotFoundError:
                If `matplotlib` is not installed

        .. plot::
            :scale: 75

            >>> # Example plotting a single value
            >>> from torchmetrics.text import ExtendedEditDistance
            >>> metric = ExtendedEditDistance()
            >>> preds = ["this is the prediction", "there is an other sample"]
            >>> target = ["this is the reference", "there is another one"]
            >>> metric.update(preds, target)
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> from torchmetrics.text import ExtendedEditDistance
            >>> metric = ExtendedEditDistance()
            >>> preds = ["this is the prediction", "there is an other sample"]
            >>> target = ["this is the reference", "there is another one"]
            >>> values = [ ]
            >>> for _ in range(10):
            ...     values.append(metric(preds, target))
            >>> fig_, ax_ = metric.plot(values)

        )Ú_plot)r1   r<   r=   r)   r)   r6   Úplot|   s   *r   )r   Fr   r   r   r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   r/   r   r   r   r	   r   r+   r   Ústrr   r9   Útupler;   r   r   r   r?   Ú__classcell__r)   r)   r4   r6   r      s^   
  ùþýüûúùø	÷þý
ü	ÿÿÿþr   N)Úcollections.abcr   Útypingr   r   r   r   Útorchr   r   Útyping_extensionsr	   Ú torchmetrics.functional.text.eedr
   r   Útorchmetrics.metricr   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r)   r)   r)   r6   Ú<module>   s   