
    qi                         d 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  ej                  e      Zdd	d
dZ G d de
      ZdgZy)z"Tokenization class for Blenderbot.    )	Tokenizerdecoderspre_tokenizers)BPE   )
AddedToken)TokenizersBackend)loggingz
vocab.jsonz
merges.txtztokenizer_config.json)
vocab_filemerges_filetokenizer_config_filec                   H     e Zd ZdZeZddgZeZ	 	 	 	 	 	 	 	 	 	 d fd	Z	 xZ
S )BlenderbotTokenizera  
    Construct a "fast" Blenderbot tokenizer (backed by HuggingFace's *tokenizers* library), derived from the GPT-2
    tokenizer, using byte-level Byte-Pair-Encoding.

    This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will
    be encoded differently whether it is at the beginning of the sentence (without space) or not:

    ```python
    >>> from transformers import BlenderbotTokenizerFast

    >>> tokenizer = BlenderbotTokenizerFast.from_pretrained("facebook/blenderbot-3B")
    >>> tokenizer("Hello world")["input_ids"]
    [6950, 1085, 2]

    >>> tokenizer(" Hello world")["input_ids"]
    [6950, 1085, 2]
    ```

    You can get around that behavior by passing `add_prefix_space=True` when instantiating this tokenizer or when you
    call it on some text, but since the model was not pretrained this way, it might yield a decrease in performance.

    <Tip>

    When used with `is_split_into_words=True`, this tokenizer needs to be instantiated with `add_prefix_space=True`.

    </Tip>

    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:
        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.
        add_prefix_space (`bool`, *optional*, defaults to `True`):
            Whether or not to add an initial space to the input. This allows to treat the leading word just as any
            other word. (Blenderbot tokenizer detect beginning of words by the preceding space).
        vocab (`str` or `dict[str, int]`, *optional*):
            Custom vocabulary dictionary. If not provided, vocabulary is loaded from `vocab_file`.
        merges (`str` or `list[str]`, *optional*):
            Custom merges list. If not provided, merges are loaded from `merges_file`.
    	input_idsattention_maskc                    || _         t        |t              rt        |ddd      n|}|	|	n8t        |      dt        |      dt        |      dt        |      dt        |      di| _        |
xs g | _        t        t        | j                  | j
                  d d	d	d
            | _        t        j                  |      | j                  _        t        j                         | j                  _        t        | <  d||||||||d| y )NTF)lstriprstrip
normalizedr         r       )vocabmergesdropoutcontinuing_subword_prefixend_of_word_suffixfuse_unk)add_prefix_space)	bos_token	eos_token	sep_token	cls_token	unk_token	pad_token
mask_tokenr     )r    
isinstancestrr   _vocab_mergesr   r   
_tokenizerr   	ByteLevelpre_tokenizerr   decodersuper__init__)selfr!   r"   r#   r$   r%   r&   r'   r    r   r   kwargs	__class__s               h/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/blenderbot/tokenization_blenderbot.pyr2   zBlenderbotTokenizer.__init__r   s    !1 *c* z$uO 	    IIIIJ 	 |#kk||*,#%	
 )7(@(@Rb(c%"*"4"4"6 
	
!-
	
 
	
    )
<s></s>r9   r8   z<unk>z<pad>z<mask>TNN)__name__
__module____qualname____doc__VOCAB_FILES_NAMESvocab_files_namesmodel_input_namesr   modelr2   __classcell__)r5   s   @r6   r   r   "   sM    IV *$&67E :
 :
r7   r   N)r=   
tokenizersr   r   r   tokenizers.modelsr   tokenization_utils_baser   tokenization_utils_tokenizersr	   utilsr
   
get_loggerr:   loggerr>   r   __all__r(   r7   r6   <module>rK      s]    ) : : ! 1 >  
		H	% 4 J
+ J
Z !
!r7   