
    qi"                         d Z ddlmZmZ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  ej                  e      Zdd	d
Z G d de      ZdgZy)zTokenization classes for MPNet.    )	Tokenizerdecodersnormalizerspre_tokenizers
processors)	WordPiece   )
AddedToken)TokenizersBackend)loggingz	vocab.txtztokenizer.json)
vocab_filetokenizer_filec                        e Zd ZdZeZddgZeZ	 	 	 	 	 	 	 	 	 	 	 d
de	e
e	ef   z  dz  f fdZede	fd       Zej                  d	        Z xZS )MPNetTokenizera  
    Construct a MPNet tokenizer (backed by HuggingFace's *tokenizers* library). Based on WordPiece.

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

    Args:
        vocab (`str` or `dict[str, int]`, *optional*):
            Dictionary mapping tokens to their IDs. If not provided, an empty vocab is initialized.
        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_maskNvocabc                    ||ni | _         t        t        | j                   t        |                  | _        t        j                  d|
||      | j                  _        t        j                         | j                  _
        t        j                  d      | j                  _        || _        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!        | D  d||||||||	|
|d
| t        | j$                        }t        | j&                        }| j(                  | j(                  nd	}| j*                  | j*                  nd
}t-        j.                  | d| d| d| d| d| d||f||fg      | j                  _        y )N)	unk_tokenT)
clean_texthandle_chinese_charsstrip_accents	lowercasez##)prefixFlstriprstrip)
do_lower_case	bos_token	eos_token	sep_token	cls_tokenr   	pad_token
mask_tokentokenize_chinese_charsr   r      z:0 $A:0 z:0z:0 z:0 $B:1 z:1)singlepairspecial_tokens )_vocabr   r   str
_tokenizerr   BertNormalizer
normalizerr   BertPreTokenizerpre_tokenizerr   decoderr   
isinstancer
   super__init__r"   r!   cls_token_idsep_token_idr   TemplateProcessingpost_processor)selfr   r   r   r    r!   r"   r   r#   r$   r%   r   kwargscls_strsep_strr6   r7   	__class__s                    ^/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/mpnet/tokenization_mpnet.pyr5   zMPNetTokenizer.__init__Y   s;      %0eb $IdkkS^$TU &1%?%?!7'#	&
" )7(G(G(I% #+"4"4D"A + 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'	
 	
 dnn%dnn%,0,=,=,It((q,0,=,=,It((q)3)F)FYhwir29HWIS	'"M,','*
&    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,   )r:   s    r?   r$   zMPNetTokenizer.mask_token   s8     #||GH4##$$r@   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)r3   r,   r
   rC   )r:   values     r?   r$   zMPNetTokenizer.mask_token   s)     AK5RU@V
5e<\a r@   )NT<s></s>rJ   rI   z[UNK]z<pad>z<mask>TN)__name__
__module____qualname____doc__VOCAB_FILES_NAMESvocab_files_namesmodel_input_namesr   modelr,   dictintr5   propertyr$   setter__classcell__)r>   s   @r?   r   r      s    4l *$&67E .2#L
T#s(^#d*L
\ %C % % 	! 	!r@   r   N)rN   
tokenizersr   r   r   r   r   tokenizers.modelsr   tokenization_pythonr
   tokenization_utils_tokenizersr   utilsr   
get_loggerrK   rE   rO   r   __all__r*   r@   r?   <module>r_      sV    & S S ' - >  
		H	%#.BRS b!& b!J 
r@   