§
    ’©ºjm  ã                   ó¤   — d dl mZ d dlmZmZmZmZ d dlZd dlmZ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mZ esd	gZ G d
„ de¦  «        ZdS )é    )ÚSequence)ÚAnyÚListÚOptionalÚUnionN)ÚTensorÚtensor)Ú_ter_computeÚ_ter_updateÚ_TercomTokenizer)ÚMetric)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzTranslationEditRate.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d
<   eed<   dZeee                  ed<   	 	 	 	 	 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 ) ÚTranslationEditRateau  Calculate Translation edit rate (`TER`_)  of machine translated text with one or more references.

    This implementation follows the one from `SacreBleu_ter`_, which is a
    near-exact reimplementation of the Tercom algorithm, produces identical results on all "sane" outputs.

    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:

    - ``ter`` (:class:`~torch.Tensor`): if ``return_sentence_level_score=True`` return a corpus-level translation
      edit rate with a list of sentence-level translation_edit_rate, else return a corpus-level translation edit rate

    Args:
        normalize: An indication whether a general tokenization to be applied.
        no_punctuation: An indication whteher a punctuation to be removed from the sentences.
        lowercase: An indication whether to enable case-insensitivity.
        asian_support: An indication whether asian characters to be processed.
        return_sentence_level_score: An indication whether a sentence-level TER to be returned.
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Example:
        >>> from torchmetrics.text import TranslationEditRate
        >>> preds = ['the cat is on the mat']
        >>> target = [['there is a cat on the mat', 'a cat is on the mat']]
        >>> ter = TranslationEditRate()
        >>> ter(preds, target)
        tensor(0.1538)

    FÚis_differentiableÚhigher_is_betterÚfull_state_updateç        Úplot_lower_boundg      ð?Úplot_upper_boundÚtotal_num_editsÚtotal_tgt_lenNÚsentence_terTÚ	normalizeÚno_punctuationÚ	lowercaseÚasian_supportÚreturn_sentence_level_scoreÚkwargsÚreturnc                 óŒ  •—  t          ¦   «         j        di |¤Ž t          |t          ¦  «        st	          d|› d�¦  «        ‚t          |t          ¦  «        st	          d|› d�¦  «        ‚t          |t          ¦  «        st	          d|› d�¦  «        ‚t          |t          ¦  «        st	          d|› d�¦  «        ‚t          ||||¦  «        | _        || _        |                      dt          d¦  «        d¬	¦  «         |                      d
t          d¦  «        d¬	¦  «         | j        r|                      dg d¬	¦  «         d S d S )Nz<Expected argument `normalize` to be of type boolean but got ú.zAExpected argument `no_punctuation` to be of type boolean but got z<Expected argument `lowercase` to be of type boolean but got z@Expected argument `asian_support` to be of type boolean but got r   r   Úsum)Údist_reduce_fxr   r   Úcat© )
ÚsuperÚ__init__Ú
isinstanceÚboolÚ
ValueErrorr   Ú	tokenizerr    Ú	add_stater	   )Úselfr   r   r   r   r    r!   Ú	__class__s          €úe/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/text/ter.pyr*   zTranslationEditRate.__init__J   sk  ø€ ð 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ý˜)¥TÑ*Ô*ð 	jÝÐhÐ\eÐhÐhÐhÑiÔiÐiÝ˜.­$Ñ/Ô/ð 	tÝÐrÐaoÐrÐrÐrÑsÔsÐsÝ˜)¥TÑ*Ô*ð 	jÝÐhÐ\eÐhÐhÐhÑiÔiÐiÝ˜-­Ñ.Ô.ð 	rÝÐpÐ`mÐpÐpÐpÑqÔqÐqå)¨)°^ÀYÐP]Ñ^Ô^ˆŒØ+FˆÔ(à�ŠÐ(­&°©+¬+ÀeˆÑLÔLÐLØ�Š�­¨s©¬ÀEˆÑJÔJÐJØÔ+ð 	EØ�NŠN˜>¨2¸eˆNÑDÔDÐDÐDÐDð	Eð 	Eó    ÚpredsÚtargetc                 ó|   — t          ||| j        | j        | j        | j        ¦  «        \  | _        | _        | _        dS )z*Update state with predictions and targets.N)r   r.   r   r   r   )r0   r4   r5   s      r2   ÚupdatezTranslationEditRate.updatee   sF   € åFQØØØŒNØÔ ØÔØÔñG
ô G
ÑCˆÔ˜dÔ0°$Ô2CÐ2CÐ2Cr3   c                 ó~   — t          | j        | j        ¦  «        }| j        �|t	          j        | j        ¦  «        fS |S )z)Calculate the translate error rate (TER).)r
   r   r   r   Útorchr'   )r0   Úters     r2   ÚcomputezTranslationEditRate.computep   s=   € å˜4Ô/°Ô1CÑDÔDˆØÔÐ(Ø�œ	 $Ô"3Ñ4Ô4Ð4Ð4Øˆ
r3   Ú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 TranslationEditRate
            >>> metric = TranslationEditRate()
            >>> preds = ['the cat is on the mat']
            >>> target = [['there is a cat on the mat', 'a cat is on the mat']]
            >>> metric.update(preds, target)
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> from torchmetrics.text import TranslationEditRate
            >>> metric = TranslationEditRate()
            >>> preds = ['the cat is on the mat']
            >>> target = [['there is a cat on the mat', 'a cat is on the mat']]
            >>> values = [ ]
            >>> for _ in range(10):
            ...     values.append(metric(preds, target))
            >>> fig_, ax_ = metric.plot(values)

        )Ú_plot)r0   r<   r=   s      r2   ÚplotzTranslationEditRate.plotw   s   € ðT �zŠz˜#˜rÑ"Ô"Ð"r3   )FFTFF)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r,   Ú__annotations__r   r   r   Úfloatr   r   r   r   r   r   r*   r   Ústrr   r7   Útupler;   r   r   r@   Ú__classcell__)r1   s   @r2   r   r      s  ø€ € € € € € ðð ðB $Ð�tÐ#Ð#Ñ#Ø"Ð�dÐ"Ð"Ñ"Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!Ø!Ð�eÐ!Ð!Ñ!àÐÐÑØÐÐÑØ+/€L�(˜4 œ<Ô(Ð/Ð/Ñ/ð  Ø$ØØ#Ø,1ðEð EàðEð ðEð ð	Eð
 ðEð &*ðEð ðEð 
ðEð Eð Eð Eð Eð Eð6	
˜E # x°¤}Ð"4Ô5ð 	
¸xÈÈcÐS[Ð\_ÔS`ÐN`ÔHaÔ?bð 	
Ðgkð 	
ð 	
ð 	
ð 	
ð˜˜v u¨V°V¨^Ô'<Ð<Ô=ð ð ð ð ð _cð*#ð *#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð*#ØIQÐRZÔI[ð*#à	ð*#ð *#ð *#ð *#ð *#ð *#ð *#ð *#r3   r   )Úcollections.abcr   Útypingr   r   r   r   r9   r   r	   Ú torchmetrics.functional.text.terr
   r   r   Útorchmetrics.metricr   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r(   r3   r2   ú<module>rQ      s  ðð %Ð $Ð $Ð $Ð $Ð $Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -à €€€Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XØ &Ð &Ð &Ð &Ð &Ð &Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð 4Ø2Ð3ÐðC#ð C#ð C#ð C#ð C#˜&ñ C#ô C#ð C#ð C#ð C#r3   