
    sgi                         d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
  e
j                  e      Zdd	iZ G d
 de      Zy)zTokenization classes for Bloom.    N)OptionalTuple   )BatchEncoding)PreTrainedTokenizerFast)loggingtokenizer_fileztokenizer.jsonc                        e Zd ZdZeZddgZdZ	 	 	 	 	 	 	 	 	 d fd	Zde	f fdZ
de	f fdZdd	ed
ee   dee   fdZ xZS )BloomTokenizerFasta~	  
    Construct a "fast" Bloom tokenizer (backed by HuggingFace's *tokenizers* library). Based on 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 BloomTokenizerFast

    >>> tokenizer = BloomTokenizerFast.from_pretrained("bigscience/bloom")
    >>> tokenizer("Hello world")["input_ids"]
    [59414, 8876]

    >>> tokenizer(" Hello world")["input_ids"]
    [86153, 8876]
    ```

    You can get around that behavior by passing `add_prefix_space=True` when instantiating this tokenizer, 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:
        vocab_file (`str`):
            Path to the vocabulary file.
        merges_file (`str`):
            Path to the merges file.
        errors (`str`, *optional*, defaults to `"replace"`):
            Paradigm to follow when decoding bytes to UTF-8. See
            [bytes.decode](https://docs.python.org/3/library/stdtypes.html#bytes.decode) for more information.
        unk_token (`str`, *optional*, defaults to `<|endoftext|>`):
            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.
        bos_token (`str`, *optional*, defaults to `<|endoftext|>`):
            The beginning of sequence token.
        eos_token (`str`, *optional*, defaults to `<|endoftext|>`):
            The end of sequence token.
        add_prefix_space (`bool`, *optional*, defaults to `False`):
            Whether or not to add an initial space to the input. This allows to treat the leading word just as any
            other word. (Bloom tokenizer detect beginning of words by the preceding space).
        trim_offsets (`bool`, *optional*, defaults to `True`):
            Whether or not the post-processing step should trim offsets to avoid including whitespaces.
    	input_idsattention_maskNc
                    t        |   d|||||||||	d	|
 t        j                  | j                  j
                        }t        j                  | j                  j                        }|r$|j                  dd      }|j                  dd      }t        j                  |      | j                  _        t        j                  |      | j                  _        || _	        y )N)	
vocab_filemerges_filer	   	unk_token	bos_token	eos_token	pad_tokenadd_prefix_spaceclean_up_tokenization_spacess   "add_prefix_space":falses   "add_prefix_space": true )
super__init__pickledumpsbackend_tokenizerpre_tokenizerdecoderreplaceloadsr   )selfr   r   r	   r   r   r   r   r   r   kwargspre_tok_statedecoder_state	__class__s                d/var/www/html/venv/lib/python3.12/site-packages/transformers/models/bloom/tokenization_bloom_fast.pyr   zBloomTokenizerFast.__init__X   s     	 	
!#)-)E	
 	
 T%;%;%I%IJT%;%;%C%CD)112MOjkM)112MOjkM/5||M/J,)/m)D& 0    returnc                     |j                  dd      }| j                  s%|r#t        d| j                  j                   d      t        |   |i |S Nis_split_into_wordsFzYou need to instantiate z? with add_prefix_space=True to use it with pretokenized inputs.)getr   	Exceptionr%   __name__r   _batch_encode_plusr!   argsr"   r+   r%   s       r&   r/   z%BloomTokenizerFast._batch_encode_plus~   sb    $jj)>F%%-@*4>>+B+B*C D( ( 
 w)4:6::r'   c                     |j                  dd      }| j                  s%|r#t        d| j                  j                   d      t        |   |i |S r*   )r,   r   r-   r%   r.   r   _encode_plusr0   s       r&   r3   zBloomTokenizerFast._encode_plus   sb    $jj)>F%%-@*4>>+B+B*C D( ( 
 w#T4V44r'   save_directoryfilename_prefixc                 f    | j                   j                  j                  ||      }t        |      S )N)name)
_tokenizermodelsavetuple)r!   r4   r5   filess       r&   save_vocabularyz"BloomTokenizerFast.save_vocabulary   s+    %%**>*PU|r'   )	NNNz<unk>z<s>z</s>z<pad>FF)N)r.   
__module____qualname____doc__VOCAB_FILES_NAMESvocab_files_namesmodel_input_namesslow_tokenizer_classr   r   r/   r3   strr   r   r=   __classcell__)r%   s   @r&   r   r      s    2h *$&67
 %*$1L;] ;	5} 	5c HSM ]bcf]g r'   r   )r@   r   typingr   r   tokenization_utils_baser   tokenization_utils_fastr   utilsr   
get_loggerr.   loggerrA   r   r   r'   r&   <module>rM      sH    &  " 4 >  
		H	%%'78 w0 wr'   