Ë
    ýÿæií  ã                   óœ   — 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sd	gZ G d
„ de«      Zy)é    )ÚSequence)ÚAnyÚListÚOptionalÚUnion)ÚTensorÚstack)ÚLiteral)Ú_eed_computeÚ_eed_update)ÚMetric)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzExtendedEditDistance.plotc                   ó>  ‡ — 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„Zdeeee   f   deeeee   f      ddfd„Zdeeeeef   f   fd„Z	 ddeeeee   f      dee   defd„Zˆ x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Úlanguage©ÚenÚjaÚreturn_sentence_level_scoreÚalphaÚrhoÚdeletionÚ	insertionÚkwargsÚreturnNc                 ób  •— t        ‰
| �  d
i |¤Ž |dvrt        d|› �«      ‚|| _        || _        t        g d¢||||g«      D ]:  \  }}	t        |	t        «      rt        |	t        «      sŒ'|	dk  sŒ-t        d|› d�«      ‚ || _        || _	        || _
        || _        | j                  dg d¬	«       y )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__s             €új/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/torchmetrics/text/eed.pyr*   zExtendedEditDistance.__init__F   sÇ   ø€ ô 	‰ÑÑ"˜6Ò"à˜<Ñ'ÜÐ^Ð_gÐ^hÐiÓjÐjØ-5ˆŒØ+FˆÔ(ô "%Ò%NÐQVÐX[Ð]eÐgpÐPqÖ!rÑˆJ˜Ü˜e¤UÔ+´
¸5Ä%Õ0HÈUÐUVËYÜ  ;¨z¨lÐ:cÐ!dÓeÐeð "sð ˆŒ
ØˆŒØ ˆŒØ"ˆŒà�‰�~ r¸%ˆÕ@ó    ÚpredsÚtargetc           
      óª   — t        ||| j                  | j                  | j                  | j                  | j
                  | j                  «      | _        y)z*Update state with predictions and targets.N)r   r   r   r    r!   r"   r   )r0   r6   r7   s      r4   ÚupdatezExtendedEditDistance.updatec   sC   € ô (ØØØ�M‰MØ�J‰JØ�H‰HØ�M‰MØ�N‰NØ×Ñó	
ˆÕr5   c                 óv   — t        | j                  «      }| j                  r|t        | j                  «      fS |S )z'Calculate extended edit distance score.)r   r   r   r	   )r0   Úaverages     r4   ÚcomputezExtendedEditDistance.computet   s6   € ä˜t×0Ñ0Ó1ˆà×+Ò+ØœE $×"3Ñ"3Ó4Ð4Ð4Øˆr5   ÚvalÚaxc                 ó&   — | j                  ||«      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)r0   r=   r>   s      r4   ÚplotzExtendedEditDistance.plot|   s   € ðT �z‰z˜#˜rÓ"Ð"r5   )r   Fg       @g333333Ó?gš™™™™™É?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   rA   Ú__classcell__)r3   s   @r4   r   r      s`  ø… ñð@ #Ð�dÓ"Ø#Ð�tÓ#Ø#Ð�tÓ#Ø!Ð�eÓ!Ø!Ð�eÓ!à�v‘,Óð )-Ø,1ØØØØñAà˜*Ñ%ðAð &*ðAð ð	Að
 ðAð ðAð ðAð ðAð 
õAð:
à�S˜( 3™-Ð'Ñ(ð
ð ˜˜s H¨S¡MÐ1Ñ2Ñ3ð
ð 
ó	
ð"˜˜v u¨V°V¨^Ñ'<Ð<Ñ=ó ð _cñ*#Ø˜E &¨(°6Ñ*:Ð":Ñ;Ñ<ð*#ØIQÐRZÑI[ð*#à	÷*#r5   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(   r5   r4   Ú<module>rT      s<   ðõ %ß -Ó -ç Ý %ç FÝ &Ý @ß @áØ3Ð4ÐôI#˜6õ I#r5   