
    sgu!                         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  ej                  e      Zd
diZ G d de	      Zy)z'Fast Tokenization classes for Splinter.    N)ListOptionalTuple)normalizers   )PreTrainedTokenizerFast)logging   )SplinterTokenizer
vocab_filez	vocab.txtc                        e Zd ZdZeZeZ	 	 	 	 	 	 	 	 	 	 	 d fd	Ze	d        Z
	 ddee   deee      dee   f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 )SplinterTokenizerFasta
  
    Construct a "fast" Splinter 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.
        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.
        sep_token (`str`, *optional*, defaults to `"[SEP]"`):
            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.
        pad_token (`str`, *optional*, defaults to `"[PAD]"`):
            The token used for padding, for example when batching sequences of different lengths.
        cls_token (`str`, *optional*, defaults to `"[CLS]"`):
            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.
        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.
        question_token (`str`, *optional*, defaults to `"[QUESTION]"`):
            The token used for constructing question representations.
        clean_text (`bool`, *optional*, defaults to `True`):
            Whether or not to clean the text before tokenization by removing any control characters and replacing all
            whitespaces by the classic one.
        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).
        wordpieces_prefix (`str`, *optional*, defaults to `"##"`):
            The prefix for subwords.
    c                    t        |   |f||||||||
||	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 )N)
tokenizer_filedo_lower_case	unk_token	sep_token	pad_token	cls_token
mask_tokentokenize_chinese_charsstrip_accentsadditional_special_tokens	lowercaser   type )super__init__jsonloadsbackend_tokenizer
normalizer__getstate__getgetattrr   popr   )selfr   r   r   r   r   r   r   r   question_tokenr   r   kwargspre_tok_statepre_tok_class	__class__s                  j/var/www/html/venv/lib/python3.12/site-packages/transformers/models/splinter/tokenization_splinter_fast.pyr   zSplinterTokenizerFast.__init__M   s     		
)'!#9''5&7	
 	
 

4#9#9#D#D#Q#Q#STk=9]J  -@MQ#K1B1B61JKM)6M+&-:M/*0=0N0ND""-*    c                 8    | j                  | j                        S )z
        `Optional[int]`: Id of the question token in the vocabulary, used to condition the answer on a question
        representation.
        )convert_tokens_to_idsr(   )r'   s    r-   question_token_idz'SplinterTokenizerFast.question_token_idw   s     ))$*=*=>>r.   token_ids_0token_ids_1returnc                    || j                   g|z   | j                  gz   S | j                   g}| j                  g}| j                  g| j                  d      gz   }| j                  dk(  r||z   |z   |z   |z   |z   S ||z   |z   |z   |z   |z   S )a  
        Build model inputs from a pair of sequence for question answering tasks by concatenating and adding special
        tokens. A Splinter sequence has the following format:

        - single sequence: `[CLS] X [SEP]`
        - pair of sequences for question answering: `[CLS] question_tokens [QUESTION] . [SEP] context_tokens [SEP]`

        Args:
            token_ids_0 (`List[int]`):
                The question token IDs if pad_on_right, else context tokens IDs
            token_ids_1 (`List[int]`, *optional*):
                The context token IDs if pad_on_right, else question token IDs

        Returns:
            `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
        .right)cls_token_idsep_token_idr1   r0   padding_side)r'   r2   r3   clssepquestion_suffixs         r-    build_inputs_with_special_tokensz6SplinterTokenizerFast.build_inputs_with_special_tokens   s    & %%&48I8I7JJJ  !  !112d6P6PQT6U5VV'$6<{JSPP $s*[8?JSPPr.   c                 n   | j                   g}| j                  g}| j                  g| j                  d      gz   }|t	        ||z   |z         dgz  S | j
                  dk(  r+t	        ||z   |z   |z         dgz  t	        ||z         dgz  z   S t	        ||z   |z         dgz  t	        ||z   |z         dgz  z   S )a  
        Create the token type IDs corresponding to the sequences passed. [What are token type
        IDs?](../glossary#token-type-ids)

        Should be overridden in a subclass if the model has a special way of building those.

        Args:
            token_ids_0 (`List[int]`): The first tokenized sequence.
            token_ids_1 (`List[int]`, *optional*): The second tokenized sequence.

        Returns:
            `List[int]`: The token type ids.
        r6   r   r7   r
   )r9   r8   r1   r0   lenr:   )r'   r2   r3   r<   r;   r=   s         r-   $create_token_type_ids_from_sequencesz:SplinterTokenizerFast.create_token_type_ids_from_sequences   s        !  !112d6P6PQT6U5VVs[(3./1#55's[(?:S@AQCG#k\_N_J`decfJfff s[(3./1#5K/<Y\_<_8`decf8fffr.   save_directoryfilename_prefixc                 f    | j                   j                  j                  ||      }t        |      S )N)name)
_tokenizermodelsavetuple)r'   rB   rC   filess       r-   save_vocabularyz%SplinterTokenizerFast.save_vocabulary   s+    %%**>*PU|r.   )NNTz[UNK]z[SEP]z[PAD]z[CLS]z[MASK]z
[QUESTION]TN)N)__name__
__module____qualname____doc__VOCAB_FILES_NAMESvocab_files_namesr   slow_tokenizer_classr   propertyr1   r   intr   r>   rA   strr   rK   __classcell__)r,   s   @r-   r   r       s    'R *, ##(+T ? ? JNQ9Q3;DI3FQ	cQB JNg9g3;DI3Fg	cg:c HSM ]bcf]g r.   r   )rO   r   typingr   r   r   
tokenizersr   tokenization_utils_fastr   utilsr	   tokenization_splinterr   
get_loggerrL   loggerrP   r   r   r.   r-   <module>r^      sM    .  ( ( " >  4 
		H	%!;/ ^3 ^r.   