
    fThW                         S r SSKrSSKrSSKrSSKJrJrJr  SSKJ	r	J
r
JrJrJr  SSKJr  \R                   " \5      rSS0rS	 rS
 r " S S\
5      r " S S5      r " S S5      rS/rg)zTokenization classes for MPNet.    N)ListOptionalTuple   )
AddedTokenPreTrainedTokenizer_is_control_is_punctuation_is_whitespace)logging
vocab_filez	vocab.txtc                     [         R                  " 5       n[        U SSS9 nUR                  5       nSSS5        [	        W5       H  u  pEUR                  S5      nXAU'   M     U$ ! , (       d  f       N9= f)z*Loads a vocabulary file into a dictionary.rutf-8encodingN
)collectionsOrderedDictopen	readlines	enumeraterstrip)r   vocabreadertokensindextokens         d/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/mpnet/tokenization_mpnet.py
load_vocabr        sg    ##%E	j#	0F!!# 
1!&)T"e * L 
1	0s   A%%
A3c                 X    U R                  5       n U (       d  / $ U R                  5       nU$ )z@Runs basic whitespace cleaning and splitting on a piece of text.)stripsplit)textr   s     r   whitespace_tokenizer%   +   s%    ::<D	ZZ\FM    c            
       `  ^  \ rS rSrSr\rSS/r             SU 4S jjr\	S 5       r
\	S 5       rS rS	 rS
 rS rS r SS\\   S\\\      S\\   4S jjr SS\\   S\\\      S\S\\   4U 4S jjjr SS\\   S\\\      S\\   4S jjrSS\S\\   S\\   4S jjrSrU =r$ )MPNetTokenizer4   a  

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

Args:
    vocab_file (`str`):
        Path to the vocabulary file.
    do_lower_case (`bool`, *optional*, defaults to `True`):
        Whether or not to lowercase the input when tokenizing.
    do_basic_tokenize (`bool`, *optional*, defaults to `True`):
        Whether or not to do basic tokenization before WordPiece.
    never_split (`Iterable`, *optional*):
        Collection of tokens which will never be split during tokenization. Only has an effect when
        `do_basic_tokenize=True`
    bos_token (`str`, *optional*, defaults to `"<s>"`):
        The beginning of sequence token that was used during pre-training. 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.
    tokenize_chinese_chars (`bool`, *optional*, defaults to `True`):
        Whether or not to tokenize Chinese characters.

        This should likely be deactivated for Japanese (see this
        [issue](https://github.com/huggingface/transformers/issues/328)).
    strip_accents (`bool`, *optional*):
        Whether or not to strip all accents. If this option is not specified, then it will be determined by the
        value for `lowercase` (as in the original BERT).
    clean_up_tokenization_spaces (`bool`, *optional*, defaults to `True`):
        Whether or not to cleanup spaces after decoding, cleanup consists in removing potential artifacts like
        extra spaces.
	input_idsattention_maskc                   > [        U[        5      (       a
  [        USS9OUn[        U[        5      (       a
  [        USS9OUn[        U[        5      (       a
  [        USS9OUn[        U[        5      (       a
  [        USS9OUn[        U	[        5      (       a
  [        U	SS9OU	n	[        U
[        5      (       a
  [        U
SS9OU
n
[        U[        5      (       a  [        USSS9OUn[        R                  R                  U5      (       d  [        SU S35      e[        U5      U l        [        R                  " U R                  R                  5        VVs/ s H
  u  nnUU4PM     snn5      U l        X0l        U(       a  [        UUUUS9U l        [!        U R                  [        U	5      S9U l        [$        TU ]L  " S	UUUUUU	UUU
UUUUS.UD6  g s  snnf )
NT)special)lstripr-   z&Can't find a vocabulary file at path 'z'. To load the vocabulary from a Google pretrained model use `tokenizer = AutoTokenizer.from_pretrained(PRETRAINED_MODEL_NAME)`)do_lower_casenever_splittokenize_chinese_charsstrip_accents)r   	unk_token)r/   do_basic_tokenizer0   	bos_token	eos_tokenr3   	sep_token	cls_token	pad_token
mask_tokenr1   r2   clean_up_tokenization_spaces )
isinstancestrr   ospathisfile
ValueErrorr    r   r   r   itemsids_to_tokensr4   BasicTokenizerbasic_tokenizerWordpieceTokenizerwordpiece_tokenizersuper__init__)selfr   r/   r4   r0   r5   r6   r7   r8   r3   r9   r:   r1   r2   r;   kwargstokids	__class__s                     r   rJ   MPNetTokenizer.__init__w   s   $ <FiQT;U;UJy$7[d	;EiQT;U;UJy$7[d	;EiQT;U;UJy$7[d	;EiQT;U;UJy$7[d	;EiQT;U;UJy$7[d	;EiQT;U;UJy$7[d	 KUU_adJeJeZ
4Fku
ww~~j))8 E` `   
+
(44QUQ[Q[QaQaQc5dQcXS#sCjQc5de!2#1+''=+	$D  $6DJJRUV_R`#a  	
'/#!#9')E	
 	
 6es   G
c                 .    U R                   R                  $ N)rF   r/   rK   s    r   r/   MPNetTokenizer.do_lower_case   s    ##111r&   c                 ,    [        U R                  5      $ rR   )lenr   rS   s    r   
vocab_sizeMPNetTokenizer.vocab_size   s    4::r&   c                 p    U R                   R                  5       nUR                  U R                  5        U$ rR   )added_tokens_encodercopyupdater   )rK   r   s     r   	get_vocabMPNetTokenizer.get_vocab   s+    ))..0TZZ r&   c                 L   / nU R                   (       au  U R                  R                  XR                  S9 HL  nX0R                  R                  ;   a  UR                  U5        M/  X R                  R                  U5      -  nMN     U$ U R                  R                  U5      nU$ )N)r0   )r4   rF   tokenizeall_special_tokensr0   appendrH   )rK   r$   split_tokensr   s       r   	_tokenizeMPNetTokenizer._tokenize   s    !!--66tI`I`6a00<<< ''. $<$<$E$Ee$LLL b   33<<TBLr&   c                 ~    U R                   R                  XR                   R                  U R                  5      5      $ )z0Converts a token (str) in an id using the vocab.)r   getr3   )rK   r   s     r   _convert_token_to_id#MPNetTokenizer._convert_token_to_id   s&    zz~~eZZ^^DNN%CDDr&   c                 L    U R                   R                  XR                  5      $ )z=Converts an index (integer) in a token (str) using the vocab.)rD   rg   r3   )rK   r   s     r   _convert_id_to_token#MPNetTokenizer._convert_id_to_token   s    !!%%e^^<<r&   c                 d    SR                  U5      R                  SS5      R                  5       nU$ )z:Converts a sequence of tokens (string) in a single string. z ## )joinreplacer"   )rK   r   
out_strings      r   convert_tokens_to_string'MPNetTokenizer.convert_tokens_to_string   s,    XXf%--eR8>>@
r&   token_ids_0token_ids_1returnc                     Uc  U R                   /U-   U R                  /-   $ U R                   /nU R                  /nX1-   U-   U-   U-   U-   $ )a3  
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A MPNet sequence has the following format:

- single sequence: `<s> X </s>`
- pair of sequences: `<s> A </s></s> B </s>`

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.
)cls_token_idsep_token_id)rK   ru   rv   clsseps        r    build_inputs_with_special_tokens/MPNetTokenizer.build_inputs_with_special_tokens   se    & %%&48I8I7JJJ  !  ! 3&,{:S@@r&   already_has_special_tokensc                    > U(       a  [         TU ]  XSS9$ Uc  S/S/[        U5      -  -   S/-   $ S/S/[        U5      -  -   SS/-   S/[        U5      -  -   S/-   $ )ae  
Retrieves sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer `prepare_for_model` methods.

Args:
    token_ids_0 (`List[int]`):
        List of ids.
    token_ids_1 (`List[int]`, *optional*):
        Optional second list of IDs for sequence pairs.
    already_has_special_tokens (`bool`, *optional*, defaults to `False`):
        Set to True if the token list is already formatted with special tokens for the model

Returns:
    `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
T)ru   rv   r      r   )rI   get_special_tokens_maskrV   )rK   ru   rv   r   rO   s       r   r   &MPNetTokenizer.get_special_tokens_mask   s    $ &72']a 3   31#K 001QC77sqcC,,-A61#K@P:PQUVTWWWr&   c                     U R                   /nU R                  /nUc  [        XA-   U-   5      S/-  $ [        XA-   U-   U-   U-   U-   5      S/-  $ )a{  
Creates a mask from the two sequences passed to be used in a sequence-pair classification task. MPNet 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   )rz   ry   rV   )rK   ru   rv   r|   r{   s        r   $create_token_type_ids_from_sequences3MPNetTokenizer.create_token_type_ids_from_sequences  si        !  !s(3./1#553$s*S0;>DEKKr&   save_directoryfilename_prefixc                    Sn[         R                  R                  U5      (       a6  [         R                  R                  X(       a  US-   OS[        S   -   5      nOU(       a  US-   OSU-   n[        USSS9 n[        U R                  R                  5       S S	9 H>  u  pgX7:w  a  [        R                  S
U S35        UnUR                  US-   5        US-  nM@     S S S 5        U4$ ! , (       d  f       U4$ = f)Nr   -ro   r   wr   r   c                     U S   $ )Nr   r<   )kvs    r   <lambda>0MPNetTokenizer.save_vocabulary.<locals>.<lambda>1  s    PRSTPUr&   )keyzSaving vocabulary to z\: vocabulary indices are not consecutive. Please check that the vocabulary is not corrupted!r   r   )r?   r@   isdirrp   VOCAB_FILES_NAMESr   sortedr   rC   loggerwarningwrite)rK   r   r   r   r   writerr   token_indexs           r   save_vocabularyMPNetTokenizer.save_vocabulary(  s    77==((/3!6rUfgsUt tJ 4C/C/n\J*cG4&,TZZ-=-=-?EU&V"'NN/
| <N N (EUT\*
 'W 5 } 54 }s   9A&C**
C:)rF   r4   rD   r   rH   )TTN<s></s>r   r   z[UNK]z<pad>z<mask>TNTrR   )NF)__name__
__module____qualname____firstlineno____doc__r   vocab_files_namesmodel_input_namesrJ   propertyr/   rW   r]   rd   rh   rk   rs   r   intr   r}   boolr   r   r>   r   r   __static_attributes____classcell__)rO   s   @r   r(   r(   4   sr   =~ *$&67
 #%)<
| 2 2  E= JNA9A3;DI3FA	cA4 sxX9X3;DI3FXkoX	cX X8 JNL9L3;DI3FL	cL.c HSM ]bcf]g  r&   r(   c                   X    \ rS rSrSr     SS jrSS jrS rSS jrS r	S	 r
S
 rSrg)rE   i>  ab  
Constructs a BasicTokenizer that will run basic tokenization (punctuation splitting, lower casing, etc.).

Args:
    do_lower_case (`bool`, *optional*, defaults to `True`):
        Whether or not to lowercase the input when tokenizing.
    never_split (`Iterable`, *optional*):
        Collection of tokens which will never be split during tokenization. Only has an effect when
        `do_basic_tokenize=True`
    tokenize_chinese_chars (`bool`, *optional*, defaults to `True`):
        Whether or not to tokenize Chinese characters.

        This should likely be deactivated for Japanese (see this
        [issue](https://github.com/huggingface/transformers/issues/328)).
    strip_accents (`bool`, *optional*):
        Whether or not to strip all accents. If this option is not specified, then it will be determined by the
        value for `lowercase` (as in the original BERT).
    do_split_on_punc (`bool`, *optional*, defaults to `True`):
        In some instances we want to skip the basic punctuation splitting so that later tokenization can capture
        the full context of the words, such as contractions.
Nc                 ^    Uc  / nXl         [        U5      U l        X0l        X@l        XPl        g rR   )r/   setr0   r1   r2   do_split_on_punc)rK   r/   r0   r1   r2   r   s         r   rJ   BasicTokenizer.__init__U  s4     K*{+&<#* 0r&   c                 z   U(       a$  U R                   R                  [        U5      5      OU R                   nU R                  U5      nU R                  (       a  U R                  U5      n[        R                  " SU5      n[        U5      n/ nU H  nXb;  ad  U R                  (       a1  UR                  5       nU R                  SLa  U R                  U5      nO"U R                  (       a  U R                  U5      nUR                  U R                  Xb5      5        M     [        SR                  U5      5      nU$ )a:  
Basic Tokenization of a piece of text. For sub-word tokenization, see WordPieceTokenizer.

Args:
    never_split (`List[str]`, *optional*)
        Kept for backward compatibility purposes. Now implemented directly at the base class level (see
        [`PreTrainedTokenizer.tokenize`]) List of token not to split.
NFCFrn   )r0   unionr   _clean_textr1   _tokenize_chinese_charsunicodedata	normalizer%   r/   lowerr2   _run_strip_accentsextend_run_split_on_puncrp   )rK   r$   r0   unicode_normalized_textorig_tokensrc   r   output_tokenss           r   r`   BasicTokenizer.tokenizee  s
    CNd&&,,S-=>SWScSc% &&//5D"-"7"7t"D)*AB E'%%!KKME))6 $ 7 7 >'' 33E:E 7 7 KL ! ,CHH\,BCr&   c                     [         R                  " SU5      n/ nU H2  n[         R                  " U5      nUS:X  a  M!  UR                  U5        M4     SR	                  U5      $ )z$Strips accents from a piece of text.NFDMnro   )r   r   categoryrb   rp   )rK   r$   outputcharcats        r   r   !BasicTokenizer._run_strip_accents  sY    $$UD1D&&t,Cd{MM$	 
 wwvr&   c                    U R                   (       a  Ub  X;   a  U/$ [        U5      nSnSn/ nU[        U5      :  am  X4   n[        U5      (       a  UR	                  U/5        SnO.U(       a  UR	                  / 5        SnUS   R	                  U5        US-  nU[        U5      :  a  Mm  U Vs/ s H  nSR                  U5      PM     sn$ s  snf )z&Splits punctuation on a piece of text.r   TFr   ro   )r   listrV   r
   rb   rp   )	rK   r$   r0   charsistart_new_wordr   r   xs	            r   r   !BasicTokenizer._run_split_on_punc  s    $$)@TEX6MT
#e*n8Dt$$tf%!%!MM"%!&r
!!$'FA #e*n %++Fq
F+++s   .Cc                    / nU Hj  n[        U5      nU R                  U5      (       a5  UR                  S5        UR                  U5        UR                  S5        MY  UR                  U5        Ml     SR                  U5      $ )z)Adds whitespace around any CJK character.rn   ro   )ord_is_chinese_charrb   rp   rK   r$   r   r   cps        r   r   &BasicTokenizer._tokenize_chinese_chars  sk    DTB$$R((c"d#c"d#  wwvr&   c                     US:  a  US::  dT  US:  a  US::  dH  US:  a  US::  d<  US:  a  US::  d0  US	:  a  US
::  d$  US:  a  US::  d  US:  a  US::  d  US:  a  US::  a  gg)z6Checks whether CP is the codepoint of a CJK character.i N  i  i 4  iM  i   iߦ i  i? i@ i i  i i   i  i  i TFr<   )rK   r   s     r   r   BasicTokenizer._is_chinese_char  sr     6\bFlfvg"-g"-g"-g"-fvg"-r&   c                     / nU H`  n[        U5      nUS:X  d  US:X  d  [        U5      (       a  M,  [        U5      (       a  UR                  S5        MO  UR                  U5        Mb     SR	                  U5      $ )zBPerforms invalid character removal and whitespace cleanup on text.r   i  rn   ro   )r   r	   r   rb   rp   r   s        r   r   BasicTokenizer._clean_text  sg    DTBQw",+d*;*;d##c"d#  wwvr&   )r/   r   r0   r2   r1   )TNTNTrR   )r   r   r   r   r   rJ   r`   r   r   r   r   r   r   r<   r&   r   rE   rE   >  s<    0 #1 $L	,,0r&   rE   c                   (    \ rS rSrSrSS jrS rSrg)rG   i  zRuns WordPiece tokenization.c                 (    Xl         X l        X0l        g rR   )r   r3   max_input_chars_per_word)rK   r   r3   r   s       r   rJ   WordpieceTokenizer.__init__  s    
"(@%r&   c                 8   / n[        U5       GH  n[        U5      n[        U5      U R                  :  a  UR	                  U R
                  5        ME  SnSn/ nU[        U5      :  ax  [        U5      nSn	Xh:  a<  SR                  XFU 5      n
US:  a  SU
-   n
XR                  ;   a  U
n	OUS-  nXh:  a  M<  U	c  SnO$UR	                  U	5        UnU[        U5      :  a  Mx  U(       a  UR	                  U R
                  5        M  UR                  U5        GM
     U$ )a  
Tokenizes a piece of text into its word pieces. This uses a greedy longest-match-first algorithm to perform
tokenization using the given vocabulary.

For example, `input = "unaffable"` will return as output `["un", "##aff", "##able"]`.

Args:
    text: A single token or whitespace separated tokens. This should have
        already been passed through *BasicTokenizer*.

Returns:
    A list of wordpiece tokens.
Fr   Nro   z##r   T)	r%   r   rV   r   rb   r3   rp   r   r   )rK   r$   r   r   r   is_badstart
sub_tokensend
cur_substrsubstrs              r   r`   WordpieceTokenizer.tokenize  s    (.EKE5zD999$$T^^4FEJ#e*$%j!
kWWU%56Fqy!%+%+
1HC k %!F!!*- #e*$" $$T^^4$$Z0; /< r&   )r   r3   r   N)d   )r   r   r   r   r   rJ   r`   r   r<   r&   r   rG   rG     s    &A
.r&   rG   )r   r   r?   r   typingr   r   r   tokenization_utilsr   r   r	   r
   r   utilsr   
get_loggerr   r   r   r    r%   r(   rE   rG   __all__r<   r&   r   <module>r      s{     &  	  ( ( o o  
		H	%!;/ F( FT^ ^D6 6r 
r&   