Ë
    T^(hf>  ã                   óÖ   — 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é   )ÚNllbTokenizerzsentencepiece.bpe.modelztokenizer.json)Ú
vocab_fileÚtokenizer_file)ÊÚace_ArabÚace_LatnÚacm_ArabÚacq_ArabÚaeb_ArabÚafr_LatnÚajp_ArabÚaka_LatnÚamh_EthiÚapc_ArabÚarb_ArabÚars_ArabÚary_ArabÚarz_ArabÚasm_BengÚast_LatnÚawa_DevaÚayr_LatnÚazb_ArabÚazj_LatnÚbak_CyrlÚbam_LatnÚban_LatnÚbel_CyrlÚbem_LatnÚben_BengÚbho_DevaÚbjn_ArabÚbjn_LatnÚbod_TibtÚbos_LatnÚbug_LatnÚbul_CyrlÚcat_LatnÚceb_LatnÚces_LatnÚcjk_LatnÚckb_ArabÚcrh_LatnÚcym_LatnÚdan_LatnÚdeu_LatnÚdik_LatnÚdyu_LatnÚdzo_TibtÚell_GrekÚeng_LatnÚepo_LatnÚest_LatnÚeus_LatnÚewe_LatnÚfao_LatnÚpes_ArabÚfij_LatnÚfin_LatnÚfon_LatnÚfra_LatnÚfur_LatnÚfuv_LatnÚgla_LatnÚgle_LatnÚglg_LatnÚgrn_LatnÚguj_GujrÚhat_LatnÚhau_LatnÚheb_HebrÚhin_DevaÚhne_DevaÚhrv_LatnÚhun_LatnÚhye_ArmnÚibo_LatnÚilo_LatnÚind_LatnÚisl_LatnÚita_LatnÚjav_LatnÚjpn_JpanÚkab_LatnÚkac_LatnÚkam_LatnÚkan_KndaÚkas_ArabÚkas_DevaÚkat_GeorÚknc_ArabÚknc_LatnÚkaz_CyrlÚkbp_LatnÚkea_LatnÚkhm_KhmrÚkik_LatnÚkin_LatnÚkir_CyrlÚkmb_LatnÚkon_LatnÚkor_HangÚkmr_LatnÚlao_LaooÚlvs_LatnÚlij_LatnÚlim_LatnÚlin_LatnÚlit_LatnÚlmo_LatnÚltg_LatnÚltz_LatnÚlua_LatnÚlug_LatnÚluo_LatnÚlus_LatnÚmag_DevaÚmai_DevaÚmal_MlymÚmar_DevaÚmin_LatnÚmkd_CyrlÚplt_LatnÚmlt_LatnÚmni_BengÚkhk_CyrlÚmos_LatnÚmri_LatnÚzsm_LatnÚmya_MymrÚnld_LatnÚnno_LatnÚnob_LatnÚnpi_DevaÚnso_LatnÚnus_LatnÚnya_LatnÚoci_LatnÚgaz_LatnÚory_OryaÚpag_LatnÚpan_GuruÚpap_LatnÚpol_LatnÚpor_LatnÚprs_ArabÚpbt_ArabÚquy_LatnÚron_LatnÚrun_LatnÚrus_CyrlÚsag_LatnÚsan_DevaÚsat_BengÚscn_LatnÚshn_MymrÚsin_SinhÚslk_LatnÚslv_LatnÚsmo_LatnÚsna_LatnÚsnd_ArabÚsom_LatnÚsot_LatnÚspa_LatnÚals_LatnÚsrd_LatnÚsrp_CyrlÚssw_LatnÚsun_LatnÚswe_LatnÚswh_LatnÚszl_LatnÚtam_TamlÚtat_CyrlÚtel_TeluÚtgk_CyrlÚtgl_LatnÚtha_ThaiÚtir_EthiÚtaq_LatnÚtaq_TfngÚtpi_LatnÚtsn_LatnÚtso_LatnÚtuk_LatnÚtum_LatnÚtur_LatnÚtwi_LatnÚtzm_TfngÚuig_ArabÚukr_CyrlÚumb_LatnÚurd_ArabÚuzn_LatnÚvec_LatnÚvie_LatnÚwar_LatnÚwol_LatnÚxho_LatnÚydd_HebrÚyor_LatnÚyue_HantÚzho_HansÚzho_HantÚzul_Latnc                   óÒ  ‡ — 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 )$ÚNllbTokenizerFasta¹  
    Construct a "fast" NLLB 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 NllbTokenizerFast

    >>> tokenizer = NllbTokenizerFast.from_pretrained(
    ...     "facebook/nllb-200-distilled-600M", src_lang="eng_Latn", tgt_lang="fra_Latn"
    ... )
    >>> example_english_phrase = " UN Chief Says There Is No Military Solution in Syria"
    >>> expected_translation_french = "Le chef de l'ONU affirme qu'il n'y a pas de solution militaire en Syrie."
    >>> inputs = tokenizer(example_english_phrase, text_target=expected_translation_french, return_tensors="pt")
    ```

    Args:
        vocab_file (`str`):
            Path to the vocabulary file.
        bos_token (`str`, *optional*, defaults to `"<s>"`):
            The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.

            <Tip>

            When building a sequence using special tokens, this is not the token that is used for the beginning of
            sequence. The token used is the `cls_token`.

            </Tip>

        eos_token (`str`, *optional*, defaults to `"</s>"`):
            The end of sequence token.

            <Tip>

            When building a sequence using special tokens, this is not the token that is used for the end of sequence.
            The token used is the `sep_token`.

            </Tip>

        sep_token (`str`, *optional*, defaults to `"</s>"`):
            The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
            sequence classification or for a text and a question for question answering. It is also used as the last
            token of a sequence built with special tokens.
        cls_token (`str`, *optional*, defaults to `"<s>"`):
            The classifier token which is used when doing sequence classification (classification of the whole sequence
            instead of per-token classification). It is the first token of the sequence when built with special tokens.
        unk_token (`str`, *optional*, defaults to `"<unk>"`):
            The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
            token instead.
        pad_token (`str`, *optional*, defaults to `"<pad>"`):
            The token used for padding, for example when batching sequences of different lengths.
        mask_token (`str`, *optional*, defaults to `"<mask>"`):
            The token used for masking values. This is the token used when training this model with masked language
            modeling. This is the token which the model will try to predict.
        tokenizer_file (`str`, *optional*):
            The path to a tokenizer file to use instead of the vocab file.
        src_lang (`str`, *optional*):
            The language to use as source language for translation.
        tgt_lang (`str`, *optional*):
            The language to use as target language for translation.
    Ú	input_idsÚattention_maskÚprefix_tokensÚsuffix_tokensNc                 óH  •— |€t         }|| _        t        |	t        «      rt	        |	ddd¬«      n|	}	|| _        t        ‰| �  d|||||||||
||	||dœ|¤Ž |
�|
nd| _        | j                  | j                  «      | _
        || _        | j                  | j                  «       y )NT)Ú
normalizedÚlstripÚspecial)r   r   Ú	bos_tokenÚ	eos_tokenÚ	sep_tokenÚ	cls_tokenÚ	unk_tokenÚ	pad_tokenÚsrc_langÚtgt_langÚ
mask_tokenÚadditional_special_tokensÚlegacy_behaviourr@   © )ÚFAIRSEQ_LANGUAGE_CODESr   Ú
isinstanceÚstrr	   rð   ÚsuperÚ__init__Ú	_src_langÚconvert_tokens_to_idsÚcur_lang_coderí   Úset_src_lang_special_tokens)Úselfr   r   ræ   rç   rè   ré   rê   rë   rî   rì   rí   rï   rð   ÚkwargsÚ	__class__s                  €úm/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/nllb/tokenization_nllb_fast.pyrö   zNllbTokenizerFast.__init__w   sÉ   ø€ ð" %Ð,Ü(>Ð%à$ˆŒô ˜*¤cÔ*ô �z¨d¸4ÈÕNàð 	ð
 !1ˆÔÜ‰Ñð 	
Ø!Ø)ØØØØØØØØØ!Ø&?Ø-ñ	
ð ò	
ð" &.Ð%9™¸zˆŒØ!×7Ñ7¸¿¹ÓGˆÔØ ˆŒØ×(Ñ(¨¯©Õ8ó    Úreturnc                 óp   — | j                   r)t        j                  j                  | j                   «      S dS )NF)r   ÚosÚpathÚisfile©rû   s    rþ   Úcan_save_slow_tokenizerz)NllbTokenizerFast.can_save_slow_tokenizer©   s$   € à26·/²/Œr�w‰w�~‰~˜dŸo™oÓ.ÐLÀuÐLrÿ   c                 ó   — | j                   S ©N)r÷   r  s    rþ   rì   zNllbTokenizerFast.src_lang­   s   € à�~‰~Ðrÿ   Únew_src_langc                 óH   — || _         | j                  | j                   «       y r  )r÷   rú   )rû   r	  s     rþ   rì   zNllbTokenizerFast.src_lang±   s   € à%ˆŒØ×(Ñ(¨¯©Õ8rÿ   Ú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 NLLB 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à   rá   )rû   r  r  s      rþ   Ú build_inputs_with_special_tokensz2NllbTokenizerFast.build_inputs_with_special_tokens¶   sG   € ð0 ÐØ×%Ñ%¨Ñ3°d×6HÑ6HÑHÐHà×!Ñ! KÑ/°+Ñ=À×@RÑ@RÑRÐRrÿ   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. nllb 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)rû   r  r  ÚsepÚclss        rþ   Ú$create_token_type_ids_from_sequencesz6NllbTokenizerFast.create_token_type_ids_from_sequencesÓ   sm   € ð$ × Ñ Ð!ˆØ× Ñ Ð!ˆàÐÜ�s˜[Ñ(¨3Ñ.Ó/°1°#Ñ5Ð5Ü�3˜Ñ$ sÑ*¨SÑ0°;Ñ>ÀÑDÓEÈÈÑKÐKrÿ   Ú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_tokensr  Úforced_bos_token_id)Ú
ValueErrorrì   rø   )rû   Ú
raw_inputsr  rì   rí   Úextra_kwargsÚinputsÚtgt_lang_ids           rþ   Ú_build_translation_inputsz+NllbTokenizerFast._build_translation_inputsì   sY   € ð Ð˜xÐ/ÜÐ`ÓaÐaØ ˆŒÙ�jÐi°TÈ.ÑiÐ\hÑiˆØ×0Ñ0°Ó:ˆØ(3ˆÐ$Ñ%Øˆrÿ   Ú	src_textsÚ	tgt_textsc                 óB   •— || _         || _        t        ‰| �  ||fi |¤ŽS r  )rì   rí   rõ   Úprepare_seq2seq_batch)rû   r   rì   r!  rí   rü   rý   s         €rþ   r#  z'NllbTokenizerFast.prepare_seq2seq_batchø   s*   ø€ ð !ˆŒØ ˆŒÜ‰wÑ,¨Y¸	ÑLÀVÑLÐLrÿ   c                 ó8   — | j                  | j                  «      S r  )rú   rì   r  s    rþ   Ú_switch_to_input_modez'NllbTokenizerFast._switch_to_input_mode  ó   € Ø×/Ñ/°·±Ó>Ð>rÿ   c                 ó8   — | j                  | j                  «      S r  )Úset_tgt_lang_special_tokensrí   r  s    rþ   Ú_switch_to_target_modez(NllbTokenizerFast._switch_to_target_mode  r&  rÿ   c                 ó  — | j                  |«      | _        | j                  r%g | _        | j                  | j                  g| _        n$| j                  g| _        | 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.
        - In legacy mode: No prefix and suffix=[eos, src_lang_code].
        - In default mode: Prefix=[src_lang_code], suffix = [eos]
        ú$Aú$B©ÚsingleÚpairÚspecial_tokensN©rø   rù   rð   rà   Úeos_token_idrá   Úconvert_ids_to_tokensr   ÚTemplateProcessingÚlistÚzipÚ
_tokenizerÚpost_processor)rû   rì   Úprefix_tokens_strÚsuffix_tokens_strs       rþ   rú   z-NllbTokenizerFast.set_src_lang_special_tokens
  sò   € ð
 "×7Ñ7¸ÓAˆÔà× Ò Ø!#ˆDÔØ"&×"3Ñ"3°T×5GÑ5GÐ!HˆDÕà"&×"4Ñ"4Ð!5ˆDÔØ"&×"3Ñ"3Ð!4ˆ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ô*
ˆ�‰Õ&rÿ   Úlangc                 ó  — | j                  |«      | _        | j                  r%g | _        | j                  | j                  g| _        n$| j                  g| _        | 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 target lang setting.
        - In legacy mode: No prefix and suffix=[eos, tgt_lang_code].
        - In default mode: Prefix=[tgt_lang_code], suffix = [eos]
        r+  r,  r-  Nr1  )rû   r;  r9  r:  s       rþ   r(  z-NllbTokenizerFast.set_tgt_lang_special_tokens!  sò   € ð
 "×7Ñ7¸Ó=ˆÔØ× Ò Ø!#ˆDÔØ"&×"3Ñ"3°T×5GÑ5GÐ!HˆDÕà"&×"4Ñ"4Ð!5ˆDÔØ"&×"3Ñ"3Ð!4ˆ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ô*
ˆ�‰Õ&rÿ   Ú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   )r  r  r  r  ÚisdirÚloggerÚerrorÚjoinÚVOCAB_FILES_NAMESÚabspathr   r   )rû   r=  r>  Úout_vocab_files       rþ   Úsave_vocabularyz!NllbTokenizerFast.save_vocabulary7  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àÐ Ð rÿ   )NNú<s>ú</s>rK  rJ  z<unk>z<pad>z<mask>NNNFr  )r@   NrJ   )r   N)"Ú__name__Ú
__module__Ú__qualname__Ú__doc__rF  Úvocab_files_namesÚmodel_input_namesr   Úslow_tokenizer_classrà   r   ÚintÚ__annotations__rá   rö   ÚpropertyÚboolr  rô   rì   Úsetterr   r  r  r  r
   r#  r%  r)  rú   r(  r   rI  Ú__classcell__)rý   s   @rþ   rÝ   rÝ   *   s  ø… ñCðJ *ÐØ$Ð&6Ð7ÐØ(Ðà!€M�4˜‘9Ó!Ø!€M�4˜‘9Ó!ð ØØØØØØØØØØØ"&Øõ09ðd ð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÷ !rÿ   rÝ   )r  Úshutilr   Útypingr   r   r   Ú
tokenizersr   Útokenization_utilsr	   r
   Útokenization_utils_fastr   Úutilsr   r   Útokenization_nllbr   Ú
get_loggerrL  rC  rF  rò   rÝ   Ú__all__rñ   rÿ   rþ   ú<module>rb     st   ðó  
Ý ß (Ñ (å !ç ;Ý >ß 8ñ ÔÞ0à€Mð 
ˆ×	Ñ	˜HÓ	%€ð $=ÐP`ÑaÐ ò R&Ð ô^!Ð/ô ^!ðB	 Ð
�rÿ   