Ë
    Q^(hœ  ã                   ó‚   — d dl Z d dlZd dlmZmZmZmZmZ d dlm	Z	m
Z
mZmZmZmZmZ d dlmZ ddlmZ  G d„ de«      Zy)	é    N)ÚIteratorÚListÚOptionalÚUnionÚTuple)Ú
AddedTokenÚRegexÚ	TokenizerÚdecodersÚnormalizersÚpre_tokenizersÚtrainers)ÚUnigramé   )ÚBaseTokenizerc                   óD  ‡ — e Zd ZdZ	 	 	 ddeeeeef         dede	fˆ fd„Z
	 	 	 	 	 ddeeee   f   dede	d	eeeeef         d
eee      dee   fd„Z	 	 	 	 	 	 ddeee   eee      f   dede	d	eeeeef         d
eee      dee   dee   fd„Zedefd„«       Zˆ xZS )ÚSentencePieceUnigramTokenizerzzSentencePiece Unigram Tokenizer

    Represents the Unigram algorithm, with the pretokenization used by SentencePiece
    ÚvocabÚreplacementÚadd_prefix_spacec           	      ó¾  •— |�t        t        |«      «      }nt        t        «       «      }t        j                  t        j                  «       t        j
                  «       t        j                  t        d«      d«      g«      |_        |rdnd}t        j                  ||¬«      |_        t        j                  ||¬«      |_        d||dœ}t        ‰| �=  ||«       y )Nú {2,}ú ÚalwaysÚnever©r   Úprepend_schemeÚSentencePieceUnigram)Úmodelr   r   )r
   r   r   ÚSequenceÚNmtÚNFKCÚReplacer	   Ú
normalizerr   Ú	MetaspaceÚpre_tokenizerr   ÚdecoderÚsuperÚ__init__)Úselfr   r   r   Ú	tokenizerr   Ú
parametersÚ	__class__s          €ún/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/tokenizers/implementations/sentencepiece_unigram.pyr)   z&SentencePieceUnigramTokenizer.__init__   s¾   ø€ ð Ðä!¤'¨%£.Ó1‰Iä!¤'£)Ó,ˆIä*×3Ñ3Ü�_‰_Ó¤× 0Ñ 0Ó 2´K×4GÑ4GÌÈgËÐX[Ó4\Ð]ó 
ˆ	Ôñ &6™¸7ˆÜ"0×":Ñ":À{ÐcqÔ"rˆ	ÔÜ$×.Ñ.¸;ÐWeÔfˆ	Ôð ,Ø&Ø 0ñ
ˆ
ô 	‰Ñ˜ JÕ/ó    ÚfilesÚ
vocab_sizeÚshow_progressÚspecial_tokensÚinitial_alphabetÚ	unk_tokenc                 ó¨   — |€g }|€g }t        j                  |||||¬«      }t        |t        «      r|g}| j                  j                  ||¬«       y)aÁ  
        Train the model using the given files

        Args:
            files (:obj:`List[str]`):
                A list of path to the files that we should use for training
            vocab_size (:obj:`int`):
                The size of the final vocabulary, including all tokens and alphabet.
            show_progress (:obj:`bool`):
                Whether to show progress bars while training.
            special_tokens (:obj:`List[Union[str, AddedToken]]`, `optional`):
                A list of special tokens the model should know of.
            initial_alphabet (:obj:`List[str]`, `optional`):
                A list of characters to include in the initial alphabet, even
                if not seen in the training dataset.
                If the strings contain more than one character, only the first one
                is kept.
            unk_token (:obj:`str`, `optional`):
                The unknown token to be used by the model.
        N©r1   r3   r2   r4   r5   )Útrainer)r   ÚUnigramTrainerÚ
isinstanceÚstrÚ
_tokenizerÚtrain)r*   r0   r1   r2   r3   r4   r5   r8   s           r.   r=   z#SentencePieceUnigramTokenizer.train,   sd   € ð< Ð!ØˆNàÐ#Ø!Ðä×)Ñ)Ø!Ø)Ø'Ø-Øô
ˆô �eœSÔ!Ø�GˆEØ�‰×Ñ˜e¨WÐÕ5r/   ÚiteratorÚlengthc                 ó„   — |€g }|€g }t        j                  |||||¬«      }| j                  j                  |||¬«       y)a�  
        Train the model using the given iterator

        Args:
            iterator (:obj:`Union[Iterator[str], Iterator[Iterator[str]]]`):
                Any iterator over strings or list of strings
            vocab_size (:obj:`int`):
                The size of the final vocabulary, including all tokens and alphabet.
            show_progress (:obj:`bool`):
                Whether to show progress bars while training.
            special_tokens (:obj:`List[Union[str, AddedToken]]`, `optional`):
                A list of special tokens the model should know of.
            initial_alphabet (:obj:`List[str]`, `optional`):
                A list of characters to include in the initial alphabet, even
                if not seen in the training dataset.
                If the strings contain more than one character, only the first one
                is kept.
            unk_token (:obj:`str`, `optional`):
                The unknown token to be used by the model.
            length (:obj:`int`, `optional`):
                The total number of sequences in the iterator. This is used to
                provide meaningful progress tracking
        Nr7   )r8   r?   )r   r9   r<   Útrain_from_iterator)	r*   r>   r1   r2   r3   r4   r5   r?   r8   s	            r.   rA   z1SentencePieceUnigramTokenizer.train_from_iterator\   s]   € ðD Ð!ØˆNàÐ#Ø!Ðä×)Ñ)Ø!Ø)Ø'Ø-Øô
ˆð 	�‰×+Ñ+ØØØð 	,õ 	
r/   Úfilenamec                 óR  — 	 dd l }|j                  j                  d«       dd l}|j                  «       }|j                  t        | d«      j                  «       «       |j                  j                  }|j                  D �cg c]  }|j                  |j                  f‘Œ }}|j                  j                  }|j                  j                   }|j                  j"                  }	|dk7  rt	        d«      ‚d}
d}t%        t'        |||	«      «      }|rMt)        j*                  t)        j,                  |«      t)        j.                  t1        d	«      d
«      g«      |_        n8t)        j*                  t)        j.                  t1        d	«      d
«      g«      |_        |rdnd}t5        j6                  |
|¬«      |_        t;        j6                  |
|¬«      |_        ddi}t?        j@                  tB        ||«      }t?        jD                  |||«       |S # t        $ r t	        d«      ‚w xY wc c}w )Nr   ú.a\  You don't seem to have the required protobuf file, in order to use this function you need to run `pip install protobuf` and `wget https://raw.githubusercontent.com/google/sentencepiece/master/python/src/sentencepiece/sentencepiece_model_pb2.py` for us to be able to read the intrinsics of your spm_file. `pip install sentencepiece` is not required.Úrbr   z]You're trying to run a `Unigram` model but you're file was trained with a different algorithmõ   â–�Tr   r   r   r   r   r   r   )#ÚsysÚpathÚappendÚsentencepiece_model_pb2Ú	ExceptionÚ
ModelProtoÚParseFromStringÚopenÚreadÚnormalizer_specÚprecompiled_charsmapÚpiecesÚpieceÚscoreÚtrainer_specÚunk_idÚ
model_typeÚbyte_fallbackr
   r   r   r    ÚPrecompiledr#   r	   r$   r   r%   r&   r   r'   r   Ú__new__r   r)   )rB   rG   r   ÚmrQ   rS   r   rV   rW   rX   r   r   r+   r   r,   Úobjs                   r.   Úfrom_spmz&SentencePieceUnigramTokenizer.from_spm’   sê  € ð		Ûà�H‰H�O‰O˜CÔ ã3ð ×ÑÓˆØ	×Ñœ$˜x¨Ó.×3Ñ3Ó5Ô6à ×0Ñ0×EÑEÐØ9:¿¹ÖB°�%—+‘+˜uŸ{™{Ò+ÐBˆÐBØ—‘×&Ñ&ˆØ—^‘^×.Ñ.ˆ
ØŸ™×4Ñ4ˆØ˜Š?ÜØoóð ð ˆØÐäœg e¨V°]ÓCÓDˆ	áÜ#.×#7Ñ#7ä×+Ñ+Ð,@ÓAÜ×'Ñ'¬¨g«¸Ó<ðó$ˆIÕ ô $/×#7Ñ#7¼×9LÑ9LÌUÐSZË^Ð]`Ó9aÐ8bÓ#cˆIÔ Ù%5™¸7ˆÜ"0×":Ñ":À{ÐcqÔ"rˆ	ÔÜ$×.Ñ.¸;ÐWeÔfˆ	Ôð Ð+ð
ˆ
ô ×#Ñ#Ô$AÀ9ÈjÓYˆÜ×Ñ˜s I¨zÔ:Øˆ
øôU ò 	Üð oóð ð	üò Cs   ‚#H ÂH$ÈH!)NrF   T)é@  TNNN)r^   TNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r;   ÚfloatÚboolr)   r   Úintr   r=   r   rA   Ústaticmethodr]   Ú__classcell__)r-   s   @r.   r   r      sy  ø„ ñð 48Ø Ø!%ñ	0à˜˜U 3¨ :Ñ.Ñ/Ñ0ð0ð ð0ð õ	0ð< Ø"ØAEØ04Ø#'ñ.6à�S˜$˜s™)�^Ñ$ð.6ð ð.6ð ð	.6ð
 !  e¨C°¨OÑ&<Ñ!=Ñ>ð.6ð # 4¨¡9Ñ-ð.6ð ˜C‘=ó.6ðf Ø"ØAEØ04Ø#'Ø $ñ4
à˜ ™ x°¸±Ñ'>Ð>Ñ?ð4
ð ð4
ð ð	4
ð
 !  e¨C°¨OÑ&<Ñ!=Ñ>ð4
ð # 4¨¡9Ñ-ð4
ð ˜C‘=ð4
ð ˜‘ó4
ðl ð1˜3ò 1ó ô1r/   r   )ÚjsonÚosÚtypingr   r   r   r   r   Ú
tokenizersr   r	   r
   r   r   r   r   Útokenizers.modelsr   Úbase_tokenizerr   r   © r/   r.   ú<module>ro      s.   ðÛ Û 	ß 9Õ 9ç d× dÑ dÝ %å )ôy Mõ yr/   