§
    ~ŠtjÎ  ã                   óŠ   — 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dS )	é    N)ÚIteratorÚListÚOptionalÚUnionÚTuple)Ú
AddedTokenÚRegexÚ	TokenizerÚdecodersÚnormalizersÚpre_tokenizersÚtrainers)ÚUnigramé   )ÚBaseTokenizerc                   óÎ  ‡ — 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
    Nõ   â–�TÚ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          ¦   «                              ||¦  «         d S )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/html/CA-Chatbot/venv/lib/python3.11/site-packages/tokenizers/implementations/sentencepiece_unigram.pyr*   z&SentencePieceUnigramTokenizer.__init__   sð   ø€ ð Ðå!¥'¨%¡.¤.Ñ1Ô1ˆIˆIå!¥'¡)¤)Ñ,Ô,ˆIå*Ô3ÝŒ_ÑÔ¥Ô 0Ñ 2Ô 2µKÔ4GÍÈgÉÌÐX[Ñ4\Ô4\Ð]ñ 
ô  
ˆ	Ôð &6ÐB˜˜¸7ˆÝ"0Ô":À{ÐcqÐ"rÑ"rÔ"rˆ	ÔÝ$Ô.¸;ÐWeÐfÑfÔfˆ	Ôð ,Ø&Ø 0ð
ð 
ˆ
õ 	‰Œ×Ò˜ JÑ/Ô/Ð/Ð/Ð/ó    é@  ÚfilesÚ
vocab_sizeÚshow_progressÚspecial_tokensÚinitial_alphabetÚ	unk_tokenc                 ó°   — |€g }|€g }t          j        |||||¬¦  «        }t          |t          ¦  «        r|g}| j                             ||¬¦  «         dS )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©r3   r5   r4   r6   r7   )Útrainer)r   ÚUnigramTrainerÚ
isinstanceÚstrÚ
_tokenizerÚtrain)r+   r2   r3   r4   r5   r6   r7   r:   s           r/   r?   z#SentencePieceUnigramTokenizer.train,   s}   € ð< Ð!ØˆNàÐ#Ø!ÐåÔ)Ø!Ø)Ø'Ø-Øð
ñ 
ô 
ˆõ �e�SÑ!Ô!ð 	Ø�GˆEØŒ×Ò˜e¨WÐÑ5Ô5Ð5Ð5Ð5r0   ÚiteratorÚlengthc                 ó‚   — |€g }|€g }t          j        |||||¬¦  «        }| j                             |||¬¦  «         dS )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
        Nr9   )r:   rA   )r   r;   r>   Útrain_from_iterator)	r+   r@   r3   r4   r5   r6   r7   rA   r:   s	            r/   rC   z1SentencePieceUnigramTokenizer.train_from_iterator\   sv   € ðD Ð!ØˆNàÐ#Ø!ÐåÔ)Ø!Ø)Ø'Ø-Øð
ñ 
ô 
ˆð 	Œ×+Ò+ØØØð 	,ñ 	
ô 	
ð 	
ð 	
ð 	
r0   Úfilenamec                 ó   — 	 dd l }|j                             d¦  «         dd l}n# t          $ r t	          d¦  «        ‚w xY w|                     ¦   «         }|                     t          | d¦  «                             ¦   «         ¦  «         |j	        j
        }d„ |j        D ¦   «         }|j        j        }|j        j        }|j        j        }|dk    rt	          d¦  «        ‚d}	d	}
t!          t#          |||¦  «        ¦  «        }|rNt%          j        t%          j        |¦  «        t%          j        t-          d
¦  «        d¦  «        g¦  «        |_        n:t%          j        t%          j        t-          d
¦  «        d¦  «        g¦  «        |_        |
rdnd}t1          j        |	|¬¦  «        |_        t7          j        |	|¬¦  «        |_        ddi}t;          j        t>          ||¦  «        }t;          j         |||¦  «         |S )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.Úrbc                 ó*   — g | ]}|j         |j        f‘ŒS © )ÚpieceÚscore)Ú.0rJ   s     r/   ú
<listcomp>z:SentencePieceUnigramTokenizer.from_spm.<locals>.<listcomp>£   s!   € ÐBÐBÐB°�%”+˜uœ{Ð+ÐBÐBÐBr0   r   z]You're trying to run a `Unigram` model but you're file was trained with a different algorithmr   Tr   r   r   r   r   r    r   )!ÚsysÚpathÚappendÚsentencepiece_model_pb2Ú	ExceptionÚ
ModelProtoÚParseFromStringÚopenÚreadÚnormalizer_specÚprecompiled_charsmapÚpiecesÚtrainer_specÚunk_idÚ
model_typeÚbyte_fallbackr
   r   r   r!   ÚPrecompiledr$   r	   r%   r   r&   r'   r   r(   r   Ú__new__r   r*   )rD   rN   r    ÚmrX   r   r[   r\   r]   r   r   r,   r   r-   Úobjs                  r/   Úfrom_spmz&SentencePieceUnigramTokenizer.from_spm’   s  € ð		ØˆJˆJˆJàŒH�OŠO˜CÑ Ô Ð à3Ð3Ð3Ð3Ð3øÝð 	ð 	ð 	Ýð oñô ð ð	øøøð
 ×ÒÑÔˆØ	×Ò�$˜x¨Ñ.Ô.×3Ò3Ñ5Ô5Ñ6Ô6Ð6à Ô0ÔEÐØBÐB¸¼ÐBÑBÔBˆØ”Ô&ˆØ”^Ô.ˆ
ØœÔ4ˆØ˜Š?ˆ?ÝØoñô ð ð ˆØÐå�g e¨V°]ÑCÔCÑDÔDˆ	àð 	dÝ#.Ô#7åÔ+Ð,@ÑAÔAÝÔ'­¨g©¬¸Ñ<Ô<ðñ$ô $ˆIÔ Ð õ $/Ô#7½Ô9LÍUÐSZÉ^Ì^Ð]`Ñ9aÔ9aÐ8bÑ#cÔ#cˆIÔ Ø%5ÐB˜˜¸7ˆÝ"0Ô":À{ÐcqÐ"rÑ"rÔ"rˆ	ÔÝ$Ô.¸;ÐWeÐfÑfÔfˆ	Ôð Ð+ð
ˆ
õ Ô#Õ$AÀ9ÈjÑYÔYˆÝÔ˜s I¨zÑ:Ô:Ð:Øˆ
s   ‚"% ¥?)Nr   T)r1   TNNN)r1   TNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r=   ÚfloatÚboolr*   r   Úintr   r?   r   rC   Ústaticmethodrb   Ú__classcell__)r.   s   @r/   r   r      sì  ø€ € € € € ðð ð 48Ø Ø!%ð	0ð 0à˜˜U 3¨ :Ô.Ô/Ô0ð0ð ð0ð ð	0ð 0ð 0ð 0ð 0ð 0ð< Ø"ØAEØ04Ø#'ð.6ð .6à�S˜$˜sœ)�^Ô$ð.6ð ð.6ð ð	.6ð
 !  e¨C°¨OÔ&<Ô!=Ô>ð.6ð # 4¨¤9Ô-ð.6ð ˜C”=ð.6ð .6ð .6ð .6ðf Ø"ØAEØ04Ø#'Ø $ð4
ð 4
à˜ œ x°¸´Ô'>Ð>Ô?ð4
ð ð4
ð ð	4
ð
 !  e¨C°¨OÔ&<Ô!=Ô>ð4
ð # 4¨¤9Ô-ð4
ð ˜C”=ð4
ð ˜”ð4
ð 4
ð 4
ð 4
ðl ð1˜3ð 1ð 1ð 1ñ „\ð1ð 1ð 1ð 1ð 1r0   r   )ÚjsonÚosÚtypingr   r   r   r   r   Ú
tokenizersr   r	   r
   r   r   r   r   Útokenizers.modelsr   Úbase_tokenizerr   r   rI   r0   r/   ú<module>rr      sÙ   ðØ €€€Ø 	€	€	€	Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9à dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dØ %Ð %Ð %Ð %Ð %Ð %à )Ð )Ð )Ð )Ð )Ð )ðyð yð yð yð y Mñ yô yð yð yð yr0   