
    sg                         d Z ddlZddlmZ ddlmZmZmZmZm	Z	 ddl
mZ ddlmZmZmZmZmZmZ ddlmZ dd	lmZmZmZmZmZ d
dlmZ  e       rddlmZ ndZ ej>                  e       Z!dZ" G d de      Z#y)z)Tokenization classes for LayoutXLM model.    N)copyfile)DictListOptionalTupleUnion   )
AddedToken)BatchEncodingEncodedInputPreTokenizedInput	TextInputTextInputPairTruncationStrategy)PreTrainedTokenizerFast)PaddingStrategy
TensorTypeadd_end_docstringsis_sentencepiece_availablelogging   )VOCAB_FILES_NAMES   )LayoutXLMTokenizera  
            add_special_tokens (`bool`, *optional*, defaults to `True`):
                Whether or not to encode the sequences with the special tokens relative to their model.
            padding (`bool`, `str` or [`~file_utils.PaddingStrategy`], *optional*, defaults to `False`):
                Activates and controls padding. Accepts the following values:

                - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
                  sequence if provided).
                - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
                  acceptable input length for the model if that argument is not provided.
                - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
                  lengths).
            truncation (`bool`, `str` or [`~tokenization_utils_base.TruncationStrategy`], *optional*, defaults to `False`):
                Activates and controls truncation. Accepts the following values:

                - `True` or `'longest_first'`: Truncate to a maximum length specified with the argument `max_length` or
                  to the maximum acceptable input length for the model if that argument is not provided. This will
                  truncate token by token, removing a token from the longest sequence in the pair if a pair of
                  sequences (or a batch of pairs) is provided.
                - `'only_first'`: Truncate to a maximum length specified with the argument `max_length` or to the
                  maximum acceptable input length for the model if that argument is not provided. This will only
                  truncate the first sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
                - `'only_second'`: Truncate to a maximum length specified with the argument `max_length` or to the
                  maximum acceptable input length for the model if that argument is not provided. This will only
                  truncate the second sequence of a pair if a pair of sequences (or a batch of pairs) is provided.
                - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
                  greater than the model maximum admissible input size).
            max_length (`int`, *optional*):
                Controls the maximum length to use by one of the truncation/padding parameters.

                If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
                is required by one of the truncation/padding parameters. If the model has no specific maximum input
                length (like XLNet) truncation/padding to a maximum length will be deactivated.
            stride (`int`, *optional*, defaults to 0):
                If set to a number along with `max_length`, the overflowing tokens returned when
                `return_overflowing_tokens=True` will contain some tokens from the end of the truncated sequence
                returned to provide some overlap between truncated and overflowing sequences. The value of this
                argument defines the number of overlapping tokens.
            pad_to_multiple_of (`int`, *optional*):
                If set will pad the sequence to a multiple of the provided value. This is especially useful to enable
                the use of Tensor Cores on NVIDIA hardware with compute capability `>= 7.5` (Volta).
            return_tensors (`str` or [`~file_utils.TensorType`], *optional*):
                If set, will return tensors instead of list of python integers. Acceptable values are:

                - `'tf'`: Return TensorFlow `tf.constant` objects.
                - `'pt'`: Return PyTorch `torch.Tensor` objects.
                - `'np'`: Return Numpy `np.ndarray` objects.
            return_token_type_ids (`bool`, *optional*):
                Whether to return token type IDs. If left to the default, will return the token type IDs according to
                the specific tokenizer's default, defined by the `return_outputs` attribute.

                [What are token type IDs?](../glossary#token-type-ids)
            return_attention_mask (`bool`, *optional*):
                Whether to return the attention mask. If left to the default, will return the attention mask according
                to the specific tokenizer's default, defined by the `return_outputs` attribute.

                [What are attention masks?](../glossary#attention-mask)
            return_overflowing_tokens (`bool`, *optional*, defaults to `False`):
                Whether or not to return overflowing token sequences. If a pair of sequences of input ids (or a batch
                of pairs) is provided with `truncation_strategy = longest_first` or `True`, an error is raised instead
                of returning overflowing tokens.
            return_special_tokens_mask (`bool`, *optional*, defaults to `False`):
                Whether or not to return special tokens mask information.
            return_offsets_mapping (`bool`, *optional*, defaults to `False`):
                Whether or not to return `(char_start, char_end)` for each token.

                This is only available on fast tokenizers inheriting from [`PreTrainedTokenizerFast`], if using
                Python's tokenizer, this method will raise `NotImplementedError`.
            return_length  (`bool`, *optional*, defaults to `False`):
                Whether or not to return the lengths of the encoded inputs.
            verbose (`bool`, *optional*, defaults to `True`):
                Whether or not to print more information and warnings.
            **kwargs: passed to the `self.tokenize()` method

        Return:
            [`BatchEncoding`]: A [`BatchEncoding`] with the following fields:

            - **input_ids** -- List of token ids to be fed to a model.

              [What are input IDs?](../glossary#input-ids)

            - **bbox** -- List of bounding boxes to be fed to a model.

            - **token_type_ids** -- List of token type ids to be fed to a model (when `return_token_type_ids=True` or
              if *"token_type_ids"* is in `self.model_input_names`).

              [What are token type IDs?](../glossary#token-type-ids)

            - **attention_mask** -- List of indices specifying which tokens should be attended to by the model (when
              `return_attention_mask=True` or if *"attention_mask"* is in `self.model_input_names`).

              [What are attention masks?](../glossary#attention-mask)

            - **labels** -- List of labels to be fed to a model. (when `word_labels` is specified).
            - **overflowing_tokens** -- List of overflowing tokens sequences (when a `max_length` is specified and
              `return_overflowing_tokens=True`).
            - **num_truncated_tokens** -- Number of tokens truncated (when a `max_length` is specified and
              `return_overflowing_tokens=True`).
            - **special_tokens_mask** -- List of 0s and 1s, with 1 specifying added special tokens and 0 specifying
              regular sequence tokens (when `add_special_tokens=True` and `return_special_tokens_mask=True`).
            - **length** -- The length of the inputs (when `return_length=True`).
c            *           e Zd ZdZeZddgZeZddddddddd	g d
g dg d
ddf fd	Z	e
defd       Z ee      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d8deeeee   ee   f   deeeee   f      deeee      eeee         f   deeee   eee      f      dedeeeef   deeeef   dee   dedee   dee   deeeef      dee   d ee   d!ed"ed#ed$ed%edef(d&       Zd9ded'ee   dedee   fd(Zddddej8                  ej:                  ddddddddddddfd)eee   ee   ee   f   d*edeeeee            deeee         ded+ed,edee   dedee   dee   dee   dee   d ee   d!ed"ed#ed$ed%edef(d-Zddddej8                  ej:                  ddddddddddddfdeeef   dee   deeee         deee      ded+ed,edee   dedee   dee   dee   dee   d ee   d!ed"ed#ed$ed%edef(d.Z dej8                  dddfd/ee!ee"f   ef   dee   d+edee   dee   d ee   de#fd0Z$	 d:d1ee   d2eee      dee   fd3Z%	 d:d1ee   d2eee      dee   fd4Z&d:d5ed6ee   de'e   fd7Z( xZ)S );LayoutXLMTokenizerFasta  
    Construct a "fast" LayoutXLM tokenizer (backed by HuggingFace's *tokenizers* library). Adapted from
    [`RobertaTokenizer`] and [`XLNetTokenizer`]. Based on
    [BPE](https://huggingface.co/docs/tokenizers/python/latest/components.html?highlight=BPE#models).

    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.
        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.
        cls_token_box (`List[int]`, *optional*, defaults to `[0, 0, 0, 0]`):
            The bounding box to use for the special [CLS] token.
        sep_token_box (`List[int]`, *optional*, defaults to `[1000, 1000, 1000, 1000]`):
            The bounding box to use for the special [SEP] token.
        pad_token_box (`List[int]`, *optional*, defaults to `[0, 0, 0, 0]`):
            The bounding box to use for the special [PAD] token.
        pad_token_label (`int`, *optional*, defaults to -100):
            The label to use for padding tokens. Defaults to -100, which is the `ignore_index` of PyTorch's
            CrossEntropyLoss.
        only_label_first_subword (`bool`, *optional*, defaults to `True`):
            Whether or not to only label the first subword, in case word labels are provided.
        additional_special_tokens (`List[str]`, *optional*, defaults to `["<s>NOTUSED", "</s>NOTUSED"]`):
            Additional special tokens used by the tokenizer.
    	input_idsattention_maskNz<s>z</s>z<unk>z<pad>z<mask>)r   r   r   r   )  r   r   r   iTc                     t        |	t              rt        |	dd      n|	}	t        |   |f||||||||	|
||||d| || _        |
| _        || _        || _        || _	        || _
        y )NTF)lstriprstrip)tokenizer_file	bos_token	eos_token	sep_token	cls_token	unk_token	pad_token
mask_tokencls_token_boxsep_token_boxpad_token_boxpad_token_labelonly_label_first_subword)
isinstancestrr
   super__init__
vocab_filer+   r,   r-   r.   r/   )selfr4   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   kwargs	__class__s                   l/var/www/html/venv/lib/python3.12/site-packages/transformers/models/layoutxlm/tokenization_layoutxlm_fast.pyr3   zLayoutXLMTokenizerFast.__init__   s    & KUU_adJeZ
4Fku
	
)!'''+%=	
 	
$ % +**.(@%    returnc                 p    | j                   r)t        j                  j                  | j                         S dS NF)r4   ospathisfile)r5   s    r8   can_save_slow_tokenizerz.LayoutXLMTokenizerFast.can_save_slow_tokenizer  s$    26//rww~~doo.LuLr9   Fr   text	text_pairboxesword_labelsadd_special_tokenspadding
truncation
max_lengthstridepad_to_multiple_ofpadding_sidereturn_tensorsreturn_token_type_idsreturn_attention_maskreturn_overflowing_tokensreturn_special_tokens_maskreturn_offsets_mappingreturn_lengthverbosec                 h   d }|4 ||      st        d      t        |t        t        f      s,t        d      t        |t        t        f      st        d      |t        |t        t        f      }n5t        |t        t        f      xr |xr t        |d   t        t        f      }||n|}|t        d      |rYt	        |      t	        |      k7  rt        d      t        ||      D ]'  \  }}t	        |      t	        |      k7  st        d	       n"t	        |      t	        |      k7  rt        d	      |r|;t	        |      t	        |      k7  r$t        d
t	        |       dt	        |       d      |t        t        ||            n|}t        |du      } | j                  d"i d|d|d|d|d|d|d|d|d|	d|
d|d|d|d|d|d|d|d|d||S  | j                  d"i d |d!|d|d|d|d|d|d|d|	d|
d|d|d|d|d|d|d|d|d||S )#a3  
        Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
        sequences with word-level normalized bounding boxes and optional labels.

        Args:
            text (`str`, `List[str]`, `List[List[str]]`):
                The sequence or batch of sequences to be encoded. Each sequence can be a string, a list of strings
                (words of a single example or questions of a batch of examples) or a list of list of strings (batch of
                words).
            text_pair (`List[str]`, `List[List[str]]`):
                The sequence or batch of sequences to be encoded. Each sequence should be a list of strings
                (pretokenized string).
            boxes (`List[List[int]]`, `List[List[List[int]]]`):
                Word-level bounding boxes. Each bounding box should be normalized to be on a 0-1000 scale.
            word_labels (`List[int]`, `List[List[int]]`, *optional*):
                Word-level integer labels (for token classification tasks such as FUNSD, CORD).
        c                    t        | t              ryt        | t        t        f      rft	        |       dk(  ryt        | d   t              ryt        | d   t        t        f      r)t	        | d         dk(  xs t        | d   d   t              S yy)NTr   F)r0   r1   listtuplelen)ts    r8   _is_valid_text_inputz=LayoutXLMTokenizerFast.__call__.<locals>._is_valid_text_input6  sz    !S!Ae}-q6Q;!c*!tUm4qt9>EZ!Q-EE r9   NzStext input must of type `str` (single example) or `List[str]` (batch of examples). ztwords must of type `List[str]` (single pretokenized example), or `List[List[str]]` (batch of pretokenized examples).ztWords must of type `List[str]` (single pretokenized example), or `List[List[str]]` (batch of pretokenized examples).r   z-You must provide corresponding bounding boxesz@You must provide words and boxes for an equal amount of examplesz:You must provide as many words as there are bounding boxeszbatch length of `text`: z- does not match batch length of `text_pair`: .batch_text_or_text_pairsis_pairrC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rA   rB    )	
ValueErrorr0   rV   rW   rX   zipboolbatch_encode_plusencode_plus)r5   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   r6   rZ   
is_batchedwordswords_exampleboxes_exampler\   r]   s                               r8   __call__zLayoutXLMTokenizerFast.__call__  sa   V	(  '- !vwwi$7 M  dT5M2 M 
  #D4-8J#D4-8hThjQUVWQX[_afZgFhJ!)y=LMM5zSZ' !cdd03E50A c,}}%]);;$%abbc 5zSZ' !]^^$Tc)n)D .s4yk :I'q*  FOEZtCi,@'A`d$9D01G)4)) )A  (	
 $6   & &  $6 *  . '< '< +D  ,F!" (>#$ ,%&  ) . $4## #  (	
 $6   & &  $6 *  . '< '< +D  ,F!" (>#$ ,%&  ) r9   pairc                     |r||fgn|g}|j                  d| j                  j                        | j                  _         | j                  j                  |f|dd|}|d   j                  S )Nsplit_special_tokensFrE   is_pretokenizedr   )pop
_tokenizerencode_special_tokensencode_batchtokens)r5   rA   ri   rE   r6   batched_input	encodingss          r8   tokenizezLayoutXLMTokenizerFast.tokenize  sw    *.$TF06

"DOO$I$I1
- 1DOO00
.@RW
[a
	 |"""r9   r\   r]   padding_strategytruncation_strategyc                 |   t        |t              st        dt        |       d      | j	                  ||||	|
|       |r$|D cg c]  \  }}|j                         |f }}}| j                  j                  ||d      }|D cg c]  }| j                  ||||||dn|||      ! }}i }|d   d   j                         D ]'  }|D cg c]  \  }}||   D ]  }|  }}}}|||<   ) |D cg c]  \  }}|D ]  }|  } }}}|r2g }!t        |      D ]  \  }"\  }#}|!|"gt        |#d         z  z  }! |!|d	<   |d   D ]  }$| j                  |$||        g }%t        t        |d               D ]!  }&|r	|d	   |&   }'n|&}'g }(t        |d   |&   | |&   j                  | |&   j                         D ]  \  })}*}+|+;|r!|*dk(  r|(j#                  | j$                         ,|(j#                  ||'   |+          D|)| j&                  k(  r|(j#                  | j(                         o|)| j*                  k(  r|(j#                  | j,                         |)| j.                  k(  r|(j#                  | j$                         t1        d
       |%j#                  |(       $ |%|d<   |g },t        t        |d               D ]  }&|r	|d	   |&   }'n|&}'g }-t        |d   |&   |d   |&   | |&   j                         D ]  \  })}.}+|+`| j2                  r<|.d   dk(  r|-j#                  ||'   |+          5|-j#                  | j4                         Q|-j#                  ||'   |+          i|-j#                  | j4                          |,j#                  |-        |,|d<   |s|d= t7        || |      S c c}}w c c}w c c}}}w c c}}}w )Nz/batch_text_or_text_pairs has to be a list (got ))rv   rw   rH   rI   rJ   rK   Trl   )encodingrM   rN   rO   rP   rQ   rR   rS   r   r   overflow_to_sample_mappingzId not recognizedbboxoffset_mappinglabels)tensor_type)r0   rV   	TypeErrortypeset_truncation_and_paddingsplitro   rq   _convert_encodingkeys	enumeraterX   &_eventual_warn_about_too_long_sequenceranger`   sequence_idsword_idsappendr-   cls_token_idr+   sep_token_idr,   pad_token_idr_   r/   r.   r   )/r5   r\   r]   rC   rD   rE   rv   rw   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   r6   rA   rB   rt   rz   tokens_and_encodingssanitized_tokenskeyitem_estacksanitized_encodingsr{   itoksr   token_boxesbatch_indexoriginal_indextoken_boxes_exampleidsequence_idword_idr~   labels_exampleoffsets/                                                  r8   _batch_encode_plusz)LayoutXLMTokenizerFast._batch_encode_plus  s   6 2D9MdSkNlMmmnopp 	''- 3!1% 	( 	
 Yq'rodIy(A'r$'rOO00$1  1 
	2 & 
  ""!&;&;*C+E* (,++ #  
  
, '*1-224 	*C&:NN74DINqQNQNEN$)S!	* 1ESSWQdSqSqSS %)+& )*> ? K9D!*qcC[8I4J.JJ*K=W9:)+6 	XI77	:wW	X  %5k%B!CD 	4K(!12N!OP[!\!,"$,/ -k:#K0==#K099- >(K
 &;!#3+2243E3EF+2253H3QRT...+2243E3EFt000+2243E3EFt000+2243E3EF()<==%>& 233	46 $/  "F$S)9+)F%GH .,%56R%ST_%`N%0N!#+.$[1+>$%56{C'4==, D'B
 *88%ayA~ . 5 5k.6QRY6Z [ . 5 5d6J6J K*11+n2Mg2VW&--d.B.BCD  n--.0 *0X&)$%56-/BP^__i (s 
0 OSs   N%$N+N0
6N7c                    |r||fgn|g}|g}||gnd } | j                   |fi dt        |d u      d|d|d|d|d|d|d|	d	|
d
|d|d|d|d|d|d|d|d||}|`|s^t        |j                         D ci c].  \  }}|t	        |      dkD  rt        |d   t              r|d   n|0 c}}|j                        }| j                  |d   ||       |S c c}}w )Nr]   rC   rD   rE   rv   rw   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   r   r   )	r   ra   r   itemsrX   r0   rV   rt   r   )r5   rA   rB   rC   rD   rE   rv   rw   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   r6   rs   batched_boxesbatched_word_labelsbatched_outputr   values                              r8   _encode_plusz#LayoutXLMTokenizerFast._encode_plusO  s   6 09$	*+tf/:/F{mD000
$./
  
 ,	

  2
 .
 !4
 "
 
  2
 &
 *
 #8
 #8
 '@
  (B!
" $:#
$ (%
& )
2 !*C* '5&:&:&<"U SZ!^
58T8RqX]] ((N 	33N;4OQ[]des   3C#
encoded_inputsc                 .   |d| j                   v }|| j                   d      }|t        j                  k(  rt        |      }||||z  dk7  r||z  dz   |z  }|t        j                  k7  xr t        |      |k7  }|rd|vrdgt        |      z  |d<   |r|t        |      z
  }	||n| j
                  }|dk(  r|r|d   dg|	z  z   |d<   d|v r|d   | j                  g|	z  z   |d<   d|v r|d   | j                  g|	z  z   |d<   d|v r|d   | j                  g|	z  z   |d<   d|v r|d   dg|	z  z   |d<   || j                  g|	z  z   || j                   d   <   |S |d	k(  r|rdg|	z  |d   z   |d<   d|v r| j                  g|	z  |d   z   |d<   d|v r| j                  g|	z  |d   z   |d<   d|v r| j                  g|	z  |d   z   |d<   d|v rdg|	z  |d   z   |d<   | j                  g|	z  |z   || j                   d   <   |S t        d
t        |      z         |S )a7  
        Pad encoded inputs (on left/right and up to predefined length or max length in the batch)

        Args:
            encoded_inputs:
                Dictionary of tokenized inputs (`List[int]`) or batch of tokenized inputs (`List[List[int]]`).
            max_length: maximum length of the returned list and optionally padding length (see below).
                Will truncate by taking into account the special tokens.
            padding_strategy: PaddingStrategy to use for padding.

                - PaddingStrategy.LONGEST Pad to the longest sequence in the batch
                - PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
                - PaddingStrategy.DO_NOT_PAD: Do not pad
                The tokenizer padding sides are defined in self.padding_side:

                    - 'left': pads on the left of the sequences
                    - 'right': pads on the right of the sequences
            pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
                This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
                `>= 7.5` (Volta).
            padding_side (`str`, *optional*):
                The side on which the model should have padding applied. Should be selected between ['right', 'left'].
                Default value is picked from the class attribute of the same name.
            return_attention_mask:
                (optional) Set to False to avoid returning attention mask (default: set to model specifics)
        r   r   r   righttoken_type_idsr|   r~   special_tokens_maskleftzInvalid padding strategy:)model_input_namesr   LONGESTrX   
DO_NOT_PADrK   pad_token_type_idr-   r.   r   r_   r1   )
r5   r   rH   rv   rJ   rK   rN   required_inputneeds_to_be_padded
differences
             r8   _padzLayoutXLMTokenizerFast._pad  s   H !($48N8N$N!'(>(>q(AB666^,J!&8&D*WiJimnJn%);;q@DVVJ-1K1KKqPSTbPcgqPq !%5^%K01sS5H/HN+,#c.&99J+7+C<IZIZLw&(7EFV7W[\Z]`jZj7jN#34#~5&'78D<R<R;SV`;`` ##34 ^+-;F-CtGYGYFZ]gFg-gN6*~-/=h/G4K_K_J`cmJm/mN8,(N:<JK`<aefdgjtdt<tN#89<JdN_N_M`cmMm<mt55a89$ # '(89sZ7G.YiJj7jN#34#~58<8N8N7OR\7\_m(` 8N#34 ^+.2.@.@-AJ-NQ_`fQg-gN6*~-040D0D/E
/RUcdlUm/mN8,(N:=>C*<L~^sOt<tN#89=A=N=N<OR\<\_m<mt55a89  !!<s<?P!PQQr9   token_ids_0token_ids_1c                     || j                   g|z   | j                  gz   S | j                   g}| j                  g}||z   |z   |z   |z   |z   S )a  
        Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
        adding special tokens. An XLM-RoBERTa sequence has the following format:

        - single sequence: `<s> X </s>`
        - pair of sequences: `<s> A </s></s> B </s>`

        Args:
            token_ids_0 (`List[int]`):
                List of IDs to which the special tokens will be added.
            token_ids_1 (`List[int]`, *optional*):
                Optional second list of IDs for sequence pairs.

        Returns:
            `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
        )r   r   )r5   r   r   clsseps        r8    build_inputs_with_special_tokensz7LayoutXLMTokenizerFast.build_inputs_with_special_tokens  sg    ( %%&48I8I7JJJ  !  ![ 3&,{:S@@r9   c                     | j                   g}| j                  g}|t        ||z   |z         dgz  S t        ||z   |z   |z   |z   |z         dgz  S )a  
        Create a mask from the two sequences passed to be used in a sequence-pair classification task. XLM-RoBERTa 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   )r   r   rX   )r5   r   r   r   r   s        r8   $create_token_type_ids_from_sequencesz;LayoutXLMTokenizerFast.create_token_type_ids_from_sequences  sm    $   !  !s[(3./1#553$s*S0;>DEKKr9   save_directoryfilename_prefixc                    | j                   st        d      t        j                  j	                  |      st
        j                  d| d       y t        j                  j                  ||r|dz   ndt        d   z         }t        j                  j                  | j                        t        j                  j                  |      k7  rt        | j                  |       |fS )NzhYour fast tokenizer does not have the necessary information to save the vocabulary for a slow tokenizer.zVocabulary path (z) should be a directory.- r4   )r@   r_   r=   r>   isdirloggererrorjoinr   abspathr4   r   )r5   r   r   out_vocab_files       r8   save_vocabularyz&LayoutXLMTokenizerFast.save_vocabulary  s    ++ 
 ww}}^,LL,^,<<TUVo_s22QbcoQpp
 77??4??+rww~/NNT__n5  r9   )NNNTFNNr   NNNNNFFFFTr<   )N)*__name__
__module____qualname____doc__r   vocab_files_namesr   r   slow_tokenizer_classr3   propertyra   r@   r   !LAYOUTXLM_ENCODE_KWARGS_DOCSTRINGr   r   r   r   r   intr1   r   r   r   r   rh   ru   r   DO_NOT_TRUNCATEr   r   r   r   r   dictr   r   r   r   r   __classcell__)r7   s   @r8   r   r      s   ;z *$&67- "."!%.A` M M M 9: RV?CCG#'5:;?$(,0'+;?0404*/+0',#)UI0$y/4HYCZZ[U E"3T:K5L"LMNU T$s)_d4S	?&;;<	U
 eDItDI$>?@U !U tS/12U $%778U SMU U %SMU tnU !sJ!78U  (~U  (~U  $(!U" %)#U$ !%%U& 'U( )U, 
-U ;Un#S # #RV #mqrumv #( 1515#',;,F,F2D2T2T$(,0'+(,0404*/+0',#1]`"'O"#%#
]` ]` T$s)_-.]` d49o.]` !]` *]` 0]` SM]` ]` %SM]`  tn!]`" !#]`$  (~%]`&  (~']`( $()]`* %)+]`, !%-]`. /]`0 1]`4 
5]`D 26+/+/#',;,F,F2D2T2T$(,0'+)-0404*/+0',#)BI001B -.B T#Y(	B
 d3i(B !B *B 0B SMB B %SMB tnB !B  (~B  (~B  $(!B" %)#B$ !%%B& 'B( )B, 
-BN %),;,F,F,0'+04Wd3#45}DEW SMW *	W
 %SMW tnW  (~W 
Wt JNA9A3;DI3FA	cA6 JNL9L3;DI3FL	cL2!c !HSM !]bcf]g !r9   r   )$r   r=   shutilr   typingr   r   r   r   r   tokenization_utilsr
   tokenization_utils_baser   r   r   r   r   r   tokenization_utils_fastr   utilsr   r   r   r   r   )xlm_roberta.tokenization_xlm_roberta_fastr   tokenization_layoutxlmr   
get_loggerr   r   r   r   r^   r9   r8   <module>r      sq    0 	  5 5 ,  ? i i
 : 
		H	%e% !P[
!4 [
!r9   