Ë
    T^(h+  ã                   óÖ   — d dl 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
mZ ddlmZ ddlmZmZ  e«       rd	d
lmZ ndZ ej&                  e«      ZdddœZg d¢Z G d„ de«      ZdgZy)é    N)Úcopyfile)ÚListÚOptionalÚTuple)Ú
processorsé   )Ú
AddedTokenÚBatchEncoding)ÚPreTrainedTokenizerFast)Úis_sentencepiece_availableÚloggingé   )ÚMBartTokenizerzsentencepiece.bpe.modelztokenizer.json)Ú
vocab_fileÚtokenizer_file)Úar_ARÚcs_CZÚde_DEÚen_XXÚes_XXÚet_EEÚfi_FIÚfr_XXÚgu_INÚhi_INÚit_ITÚja_XXÚkk_KZÚko_KRÚlt_LTÚlv_LVÚmy_MMÚne_NPÚnl_XXÚro_ROÚru_RUÚsi_LKÚtr_TRÚvi_VNÚzh_CNc                   óÐ  ‡ — e Zd ZU dZeZddgZeZg Z	e
e   ed<   g Ze
e   ed<   	 	 	 	 	 	 	 	 	 	 	 	 d ˆ fd„	Zedefd	„«       Zedefd
„«       Zej(                  deddfd„«       Z	 d!de
e   dee
e      de
e   fd„Z	 d!de
e   dee
e      de
e   fd„Zdedee   dee   fd„Z	 	 	 d"de
e   dedee
e      dedef
ˆ fd„Zd„ Zd„ Zd#d„Zdeddfd„Zd!dedee   dee   fd„Z ˆ xZ!S )$ÚMBartTokenizerFastuO  
    Construct a "fast" MBART tokenizer (backed by HuggingFace's *tokenizers* library). Based on
    [BPE](https://huggingface.co/docs/tokenizers/python/latest/components.html?highlight=BPE#models).

    This tokenizer inherits from [`PreTrainedTokenizerFast`] which contains most of the main methods. Users should
    refer to this superclass for more information regarding those methods.

    The tokenization method is `<tokens> <eos> <language code>` for source language documents, and `<language code>
    <tokens> <eos>` for target language documents.

    Examples:

    ```python
    >>> from transformers import MBartTokenizerFast

    >>> tokenizer = MBartTokenizerFast.from_pretrained(
    ...     "facebook/mbart-large-en-ro", src_lang="en_XX", tgt_lang="ro_RO"
    ... )
    >>> example_english_phrase = " UN Chief Says There Is No Military Solution in Syria"
    >>> expected_translation_romanian = "Åžeful ONU declarÄƒ cÄƒ nu existÄƒ o soluÅ£ie militarÄƒ Ã®n Siria"
    >>> inputs = tokenizer(example_english_phrase, text_target=expected_translation_romanian, return_tensors="pt")
    ```Ú	input_idsÚattention_maskÚprefix_tokensÚsuffix_tokensNc                 ó   •— t        |	t        «      rt        |	dd¬«      n|	}	t        j	                  «       }|�$|j                  |D �cg c]	  }||vsŒ|‘Œ c}«       t        ‰| �  d|||||||||	|
||dœ|¤Ž || _        t        D �ci c]  }|| j                  |«      “Œ c}| _
        |
�|
nd| _        | j                  | j                  «      | _        || _        | j                  | j                  «       y c c}w c c}w )NTF)ÚlstripÚrstrip)r   r   Ú	bos_tokenÚ	eos_tokenÚ	sep_tokenÚ	cls_tokenÚ	unk_tokenÚ	pad_tokenÚ
mask_tokenÚsrc_langÚtgt_langÚadditional_special_tokensr   © )Ú
isinstanceÚstrr	   ÚFAIRSEQ_LANGUAGE_CODESÚcopyÚextendÚsuperÚ__init__r   Úconvert_tokens_to_idsÚlang_code_to_idÚ	_src_langÚcur_lang_coder<   Úset_src_lang_special_tokens)Úselfr   r   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   ÚkwargsÚ_additional_special_tokensÚtÚ	lang_codeÚ	__class__s                    €úo/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/mbart/tokenization_mbart_fast.pyrE   zMBartTokenizerFast.__init__I   s  ø€ ô" KUÐU_ÔadÔJe”Z 
°4ÀÕFÐkuˆ
ä%;×%@Ñ%@Ó%BÐ"à$Ð0à&×-Ñ-Ø5Ö]�q¸ÐB\Ò9\’Ò]ôô 	‰Ñð 	
Ø!Ø)ØØØØØØØ!ØØØ&@ñ	
ð ò	
ð  %ˆŒäNdö 
ØAJˆI�t×1Ñ1°)Ó<Ñ<ò 
ˆÔð &.Ð%9™¸wˆŒØ!×7Ñ7¸¿¹ÓGˆÔØ ˆŒØ×(Ñ(¨¯©Õ8ùò7 ^ùò( 
s   Á	C6ÁC6ÂC;Úreturnc                 óp   — | j                   r)t        j                  j                  | j                   «      S dS )NF)r   ÚosÚpathÚisfile©rK   s    rQ   Úcan_save_slow_tokenizerz*MBartTokenizerFast.can_save_slow_tokenizer~   s$   € à26·/²/Œr�w‰w�~‰~˜dŸo™oÓ.ÐLÀuÐLó    c                 ó   — | j                   S ©N)rH   rW   s    rQ   r;   zMBartTokenizerFast.src_lang‚   s   € à�~‰~ÐrY   Únew_src_langc                 óH   — || _         | j                  | j                   «       y r[   )rH   rJ   )rK   r\   s     rQ   r;   zMBartTokenizerFast.src_lang†   s   € à%ˆŒØ×(Ñ(¨¯©Õ8rY   Útoken_ids_0Útoken_ids_1c                 ó|   — |€| j                   |z   | j                  z   S | j                   |z   |z   | j                  z   S )aš  
        Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
        adding special tokens. The special tokens depend on calling set_lang.

        An MBART sequence has the following format, where `X` represents the sequence:

        - `input_ids` (for encoder) `X [eos, src_lang_code]`
        - `decoder_input_ids`: (for decoder) `X [eos, tgt_lang_code]`

        BOS is never used. Pairs of sequences are not the expected use case, but they will be handled without a
        separator.

        Args:
            token_ids_0 (`List[int]`):
                List of IDs to which the special tokens will be added.
            token_ids_1 (`List[int]`, *optional*):
                Optional second list of IDs for sequence pairs.

        Returns:
            `List[int]`: list of [input IDs](../glossary#input-ids) with the appropriate special tokens.
        )r/   r0   )rK   r^   r_   s      rQ   Ú build_inputs_with_special_tokensz3MBartTokenizerFast.build_inputs_with_special_tokens‹   sG   € ð0 ÐØ×%Ñ%¨Ñ3°d×6HÑ6HÑHÐHà×!Ñ! KÑ/°+Ñ=À×@RÑ@RÑRÐRrY   c                 ó    — | j                   g}| j                  g}|€t        ||z   |z   «      dgz  S t        ||z   |z   |z   |z   |z   «      dgz  S )aË  
        Create a mask from the two sequences passed to be used in a sequence-pair classification task. mBART does not
        make use of token type ids, therefore a list of zeros is returned.

        Args:
            token_ids_0 (`List[int]`):
                List of IDs.
            token_ids_1 (`List[int]`, *optional*):
                Optional second list of IDs for sequence pairs.

        Returns:
            `List[int]`: List of zeros.

        r   )Úsep_token_idÚcls_token_idÚlen)rK   r^   r_   ÚsepÚclss        rQ   Ú$create_token_type_ids_from_sequencesz7MBartTokenizerFast.create_token_type_ids_from_sequences¨   sm   € ð$ × Ñ Ð!ˆØ× Ñ Ð!ˆàÐÜ�s˜[Ñ(¨3Ñ.Ó/°1°#Ñ5Ð5Ü�3˜Ñ$ sÑ*¨SÑ0°;Ñ>ÀÑDÓEÈÈÑKÐKrY   Úreturn_tensorsr;   r<   c                 óv   — |�|€t        d«      ‚|| _         | |fd|dœ|¤Ž}| j                  |«      }||d<   |S )zIUsed by translation pipeline, to prepare inputs for the generate functionzATranslation requires a `src_lang` and a `tgt_lang` for this modelT)Úadd_special_tokensri   Úforced_bos_token_id)Ú
ValueErrorr;   rF   )rK   Ú
raw_inputsri   r;   r<   Úextra_kwargsÚinputsÚtgt_lang_ids           rQ   Ú_build_translation_inputsz,MBartTokenizerFast._build_translation_inputsÁ   sY   € ð Ð˜xÐ/ÜÐ`ÓaÐaØ ˆŒÙ�jÐi°TÈ.ÑiÐ\hÑiˆØ×0Ñ0°Ó:ˆØ(3ˆÐ$Ñ%ØˆrY   Ú	src_textsÚ	tgt_textsc                 óB   •— || _         || _        t        ‰| �  ||fi |¤ŽS r[   )r;   r<   rD   Úprepare_seq2seq_batch)rK   rs   r;   rt   r<   rL   rP   s         €rQ   rv   z(MBartTokenizerFast.prepare_seq2seq_batchÍ   s*   ø€ ð !ˆŒØ ˆŒÜ‰wÑ,¨Y¸	ÑLÀVÑLÐLrY   c                 ó8   — | j                  | j                  «      S r[   )rJ   r;   rW   s    rQ   Ú_switch_to_input_modez(MBartTokenizerFast._switch_to_input_modeÙ   ó   € Ø×/Ñ/°·±Ó>Ð>rY   c                 ó8   — | j                  | j                  «      S r[   )Úset_tgt_lang_special_tokensr<   rW   s    rQ   Ú_switch_to_target_modez)MBartTokenizerFast._switch_to_target_modeÜ   ry   rY   c                 óª  — | j                  |«      | _        g | _        | j                  | j                  g| _        | j                  | j                  «      }| j                  | j                  «      }t        j                  |dgz   |z   |ddgz   |z   t        t        ||z   | j                  | j                  z   «      «      ¬«      | j                  _        y)z_Reset the special tokens to the source lang setting. No prefix and suffix=[eos, src_lang_code].ú$Aú$B©ÚsingleÚpairÚspecial_tokensN©rF   rI   r/   Úeos_token_idr0   Úconvert_ids_to_tokensr   ÚTemplateProcessingÚlistÚzipÚ
_tokenizerÚpost_processor)rK   r;   Úprefix_tokens_strÚsuffix_tokens_strs       rQ   rJ   z.MBartTokenizerFast.set_src_lang_special_tokensß   sÅ   € à!×7Ñ7¸ÓAˆÔØˆÔØ"×/Ñ/°×1CÑ1CÐDˆÔà ×6Ñ6°t×7IÑ7IÓJÐØ ×6Ñ6°t×7IÑ7IÓJÐä)3×)FÑ)FØ$¨ vÑ-Ð0AÑAØ" d¨D \Ñ1Ð4EÑEÜ¤Ð$5Ð8IÑ$IÈ4×K]ÑK]Ð`d×`rÑ`rÑKrÓ sÓtô*
ˆ�‰Õ&rY   Úlangc                 óª  — | j                  |«      | _        g | _        | j                  | j                  g| _        | j                  | j                  «      }| j                  | j                  «      }t        j                  |dgz   |z   |ddgz   |z   t        t        ||z   | j                  | j                  z   «      «      ¬«      | j                  _        y)zcReset the special tokens to the target language setting. No prefix and suffix=[eos, tgt_lang_code].r~   r   r€   Nr„   )rK   rŽ   rŒ   r�   s       rQ   r{   z.MBartTokenizerFast.set_tgt_lang_special_tokensî   sÅ   € à!×7Ñ7¸Ó=ˆÔØˆÔØ"×/Ñ/°×1CÑ1CÐDˆÔà ×6Ñ6°t×7IÑ7IÓJÐØ ×6Ñ6°t×7IÑ7IÓJÐä)3×)FÑ)FØ$¨ vÑ-Ð0AÑAØ" d¨D \Ñ1Ð4EÑEÜ¤Ð$5Ð8IÑ$IÈ4×K]ÑK]Ð`d×`rÑ`rÑKrÓ sÓtô*
ˆ�‰Õ&rY   Úsave_directoryÚfilename_prefixc                 óÈ  — | j                   st        d«      ‚t        j                  j	                  |«      st
        j                  d|› d�«       y t        j                  j                  ||r|dz   ndt        d   z   «      }t        j                  j                  | j                  «      t        j                  j                  |«      k7  rt        | j                  |«       |fS )NzhYour fast tokenizer does not have the necessary information to save the vocabulary for a slow tokenizer.zVocabulary path (z) should be a directory.ú-Ú r   )rX   rm   rT   rU   ÚisdirÚloggerÚerrorÚjoinÚVOCAB_FILES_NAMESÚabspathr   r   )rK   r�   r‘   Úout_vocab_files       rQ   Úsave_vocabularyz"MBartTokenizerFast.save_vocabularyý   sµ   € Ø×+Ò+Üðóð ô
 �w‰w�}‰}˜^Ô,Ü�L‰LÐ,¨^Ð,<Ð<TÐUÔVØÜŸ™Ÿ™Ø±o˜_¨sÒ2È2ÔQbÐcoÑQpÑpó
ˆô �7‰7�?‰?˜4Ÿ?™?Ó+¬r¯w©w¯©¸~Ó/NÒNÜ�T—_‘_ nÔ5àÐ Ð rY   )NNú<s>ú</s>rž   r�   z<unk>z<pad>z<mask>NNNr[   )r   Nr%   )rR   N)"Ú__name__Ú
__module__Ú__qualname__Ú__doc__r™   Úvocab_files_namesÚmodel_input_namesr   Úslow_tokenizer_classr/   r   ÚintÚ__annotations__r0   rE   ÚpropertyÚboolrX   r@   r;   Úsetterr   ra   rh   rr   r
   rv   rx   r|   rJ   r{   r   rœ   Ú__classcell__)rP   s   @rQ   r,   r,   *   sü  ø… ñð. *ÐØ$Ð&6Ð7ÐØ)Ðà!€M�4˜‘9Ó!Ø!€M�4˜‘9Ó!ð ØØØØØØØØØØØ"&õ39ðj ðM¨ò Mó ðMð ð˜#ò ó ðð ‡_�_ð9 Sð 9¨Tò 9ó ð9ð
 JNñSØ ™9ðSØ3;¸DÀ¹IÑ3FðSà	ˆc‰óSð< JNñLØ ™9ðLØ3;¸DÀ¹IÑ3FðLà	ˆc‰óLð2
Ø*-ð
Ø9AÀ#¹ð
ØRZÐ[^ÑR_ó
ð  Ø)-Øñ
Mà˜‘9ð
Mð ð
Mð ˜D ™IÑ&ð	
Mð
 ð
Mð 
õ
Mò?ò?ó
ð
°ð 
¸ó 
ñ!¨cð !ÀHÈSÁMð !Ð]bÐcfÑ]g÷ !rY   r,   )rT   Úshutilr   Útypingr   r   r   Ú
tokenizersr   Útokenization_utilsr	   r
   Útokenization_utils_fastr   Úutilsr   r   Útokenization_mbartr   Ú
get_loggerrŸ   r–   r™   rA   r,   Ú__all__r>   rY   rQ   ú<module>rµ      st   ðó  
Ý ß (Ñ (å !ç ;Ý >ß 8ñ ÔÞ2à€Nð 
ˆ×	Ñ	˜HÓ	%€ð $=ÐP`ÑaÐ ò {Ð ôd!Ð0ô d!ðN  Ð
 �rY   