
    sg#                         d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ d	d
lmZ  ej                   e      ZdddZ G d de      Zy)z$Fast Tokenization classes for MPNet.    N)ListOptionalTuple)normalizers   )
AddedToken)PreTrainedTokenizerFast)logging   )MPNetTokenizerz	vocab.txtztokenizer.json)
vocab_filetokenizer_filec                        e Zd ZdZeZeZddgZ	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z	e
defd       Zej                  d        ZddZ	 dd	ee   d
eee      dee   fdZddedee   dee   fdZ xZS )MPNetTokenizerFasta  
    Construct a "fast" MPNet tokenizer (backed by HuggingFace's *tokenizers* library). Based on WordPiece.

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

    Args:
        vocab_file (`str`):
            File containing the vocabulary.
        do_lower_case (`bool`, *optional*, defaults to `True`):
            Whether or not to lowercase the input when tokenizing.
        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.
        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).
    	input_idsattention_maskc                 N   t        |t              rt        |dd      n|}t        |t              rt        |dd      n|}t        |t              rt        |dd      n|}t        |t              rt        |dd      n|}t        |t              rt        |dd      n|}t        |	t              rt        |	dd      n|	}	t        |
t              rt        |
dd      n|
}
t        |   |f||||||||	|
||d| t        j                  | j                  j                  j                               }|j                  d|      |k7  s|j                  d|      |k7  r@t        t        |j                  d            }||d<   ||d<    |di || j                  _        || _        y )	NFlstriprstripT)r   do_lower_case	bos_token	eos_token	sep_token	cls_token	unk_token	pad_token
mask_tokentokenize_chinese_charsstrip_accents	lowercaser    type )
isinstancestrr   super__init__jsonloadsbackend_tokenizer
normalizer__getstate__getgetattrr   popr   )selfr   r   r   r   r   r   r   r   r   r   r   r    kwargspre_tok_statepre_tok_class	__class__s                   d/var/www/html/venv/lib/python3.12/site-packages/transformers/models/mpnet/tokenization_mpnet_fast.pyr'   zMPNetTokenizerFast.__init__]   s     JTT]_bIcJyuEir	IST]_bIcJyuEir	IST]_bIcJyuEir	IST]_bIcJyuEir	IST]_bIcJyuEir	IST]_bIcJyuEir	 KUU_adJeZ
4Fku
	
)'!#9'	
 	
  

4#9#9#D#D#Q#Q#STk=9]J  -@MQ#K1B1B61JKM)6M+&-:M/*0=0N0ND""-*    returnc                     | j                   "| j                  rt        j                  d       yt	        | j                         S )a?  
        `str`: Mask token, to use when training a model with masked-language modeling. Log an error if used while not
        having been set.

        MPNet tokenizer has a special mask token to be usable in the fill-mask pipeline. The mask token will greedily
        comprise the space before the *<mask>*.
        Nz(Using mask_token, but it is not set yet.)_mask_tokenverboseloggererrorr%   )r0   s    r5   r   zMPNetTokenizerFast.mask_token   s8     #||GH4##$$r6   c                 R    t        |t              rt        |dd      n|}|| _        y)z
        Overriding the default behavior of the mask token to have it eat the space before it.

        This is needed to preserve backward compatibility with all the previously used models based on MPNet.
        TFr   N)r$   r%   r   r9   )r0   values     r5   r   zMPNetTokenizerFast.mask_token   s)     AK5RU@V
5e<\a r6   c                     | j                   g|z   | j                  gz   }||S || j                  gz   |z   | j                  gz   S N)bos_token_ideos_token_id)r0   token_ids_0token_ids_1outputs       r5    build_inputs_with_special_tokensz3MPNetTokenizerFast.build_inputs_with_special_tokens   sU    ##${2d6G6G5HHM**++k9T=N=N<OOOr6   rC   rD   c                     | j                   g}| j                  g}|t        ||z   |z         dgz  S t        ||z   |z   |z   |z   |z         dgz  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   )sep_token_idcls_token_idlen)r0   rC   rD   sepclss        r5   $create_token_type_ids_from_sequencesz7MPNetTokenizerFast.create_token_type_ids_from_sequences   sm        !  !s[(3./1#553$s*S0;>DEKKr6   save_directoryfilename_prefixc                 f    | j                   j                  j                  ||      }t        |      S )N)name)
_tokenizermodelsavetuple)r0   rN   rO   filess       r5   save_vocabularyz"MPNetTokenizerFast.save_vocabulary   s+    %%**>*PU|r6   )NNT<s></s>rY   rX   z[UNK]z<pad>z<mask>TNr@   )__name__
__module____qualname____doc__VOCAB_FILES_NAMESvocab_files_namesr   slow_tokenizer_classmodel_input_namesr'   propertyr%   r   setterrF   r   intr   rM   r   rW   __classcell__)r4   s   @r5   r   r   "   s    4l *)$&67 #4+l %C % % 	! 	!P JNL9L3;DI3FL	cL.c HSM ]bcf]g r6   r   )r]   r(   typingr   r   r   
tokenizersr   tokenization_utilsr   tokenization_utils_fastr	   utilsr
   tokenization_mpnetr   
get_loggerrZ   r;   r^   r   r#   r6   r5   <module>rm      sQ     +  ( ( " , >  . 
		H	%#.BRS l0 lr6   