§
    ’©ºjí  ã                   ó¤   — 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dS )é    )Ú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Úenç       @ç333333Ó?çš™™™™™É?Úlanguage©r   ÚjaÚreturn_sentence_level_scoreÚalphaÚrhoÚdeletionÚ	insertionÚkwargsÚreturnNc                 ó¨  •—  t          ¦   «         j        d
i |¤Ž |dvrt          d|› �¦  «        ‚|| _        || _        t          g d¢||||g¦  «        D ]H\  }}	t          |	t          ¦  «        rt          |	t          ¦  «        r|	dk     rt          d|› d�¦  «        ‚ŒI|| _        || _	        || _
        || _        |                      dg 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__s             €úe/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/text/eed.pyr-   zExtendedEditDistance.__init__F   s  ø€ ð 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"à˜<Ð'Ð'ÝÐiÐ_gÐiÐiÑjÔjÐjØ-5ˆŒØ+FˆÔ(õ "%Ð%NÐ%NÐ%NÐQVÐX[Ð]eÐgpÐPqÑ!rÔ!rð 	fð 	fÑˆJ˜Ý˜e¥UÑ+Ô+ð fµ
¸5Å%Ñ0HÔ0Hð fÈUÐUVÊYÈYÝ Ð!d¨zÐ!dÐ!dÐ!dÑeÔeÐeøàˆŒ
ØˆŒØ ˆŒØ"ˆŒà�Š�~ r¸%ˆÑ@Ô@Ð@Ð@Ð@ó    ÚpredsÚtargetc           
      óx   — t          ||| j        | j        | j        | j        | j        | j        ¦  «        | _        dS )z*Update state with predictions and targets.N)r   r   r"   r#   r$   r%   r   )r3   r9   r:   s      r7   ÚupdatezExtendedEditDistance.updatec   sA   € õ (ØØØŒMØŒJØŒHØŒMØŒNØÔñ	
ô 	
ˆÔÐÐr8   c                 óh   — t          | j        ¦  «        }| j        r|t          | j        ¦  «        fS |S )z'Calculate extended edit distance score.)r   r   r!   r	   )r3   Úaverages     r7   ÚcomputezExtendedEditDistance.computet   s8   € å˜tÔ0Ñ1Ô1ˆàÔ+ð 	5Ø�E $Ô"3Ñ4Ô4Ð4Ð4Øˆr8   ÚvalÚaxc                 ó.   — |                       ||¦  «        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)r3   r@   rA   s      r7   ÚplotzExtendedEditDistance.plot|   s   € ðT �zŠz˜#˜rÑ"Ô"Ð"r8   )r   Fr   r   r   r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   r1   r   r   r   r
   r   r-   r   Ústrr   r<   Útupler?   r   r   r   rD   Ú__classcell__)r6   s   @r7   r   r      sý  ø€ € € € € € ðð ð@ #Ð�dÐ"Ð"Ñ"Ø#Ð�tÐ#Ð#Ñ#Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!Ø!Ð�eÐ!Ð!Ñ!à�v”,ÐÐÑð )-Ø,1ØØØØðAð Aà˜*Ô%ðAð &*ðAð ð	Að
 ðAð ð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[ð*#à	ð*#ð *#ð *#ð *#ð *#ð *#ð *#ð *#r8   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+   r8   r7   ú<module>rW      s
  ðð %Ð $Ð $Ð $Ð $Ð $Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -à Ð Ð Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ &Ð &Ð &Ð &Ð &Ð &Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð 5Ø3Ð4ÐðI#ð I#ð I#ð I#ð I#˜6ñ I#ô I#ð I#ð I#ð I#r8   