
    qi                         d Z ddlmZmZmZmZmZmZ ddlm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZmZ  ej,                  e      Zddd	Zd
ZdZ G d de      ZdgZeZy)z8
Tokenization class for LayoutLMv2. Based on WordPiece.
    )	Tokenizerdecodersmodelsnormalizerspre_tokenizers
processors   )BatchEncodingEncodedInputPaddingStrategyPreTokenizedInput
TensorType	TextInputTextInputPairTruncationStrategy)TokenizersBackend)add_end_docstringsloggingz	vocab.txtztokenizer.json)
vocab_filetokenizer_filea  
            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).
an  
            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
c            *           e Zd ZdZeZej                  Zg dZ	ddddddd	g d
g dg d
dddddfde
ee
ef   z  dz  f fdZ eee      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4deez  ee   z  ee   z  deee   z  dz  deee      eeee         z  dz  dee   eee      z  dz  dedee
z  ez  dee
z  ez  dedz  dededz  de
dz  de
ez  dz  dedz  dedz  d ed!ed"ed#ed$ed%ef(d&       Z eee      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4d'ee   ee   z  ee   z  d(edz  deeee         dz  dee   eee      z  dz  dedee
z  ez  dee
z  ez  dedz  dededz  de
dz  de
ez  dz  dedz  dedz  d ed!ed"ed#ed$ed%ef(d)       Zd5de
d*e
dz  ded%ee
   fd+Z eee      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4deez  dedz  deee      dz  dee   dz  dedee
z  ez  dee
z  ez  dedz  dededz  de
dz  de
ez  dz  dedz  dedz  d ed!ed"ed#ed$ed%ef(d,       Zddddej<                  ej>                  ddddddddddddfd'ee   ee   z  ee   z  d(edz  deeee         dz  deee      dz  ded-ed.ededz  dededz  de
dz  de
dz  dedz  dedz  d ed!ed"ed#ed$ed%ef(d/Z ddddej<                  ej>                  ddddddddddddfdeez  dedz  deee      dz  dee   dz  ded-ed.ededz  dededz  de
dz  dedz  dedz  dedz  d ed!ed"ed#ed$ed%ef(d0Z!dej<                  dddfd1ee
e"f   ez  dedz  d-ededz  de
dz  dedz  d%efd2Z#d6d3Z$ xZ%S )7LayoutLMv2Tokenizera&  
    Construct a "fast" LayoutLMv2 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.
        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.
        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 LayoutLMv2).
    )	input_idsattention_masktoken_type_idsNTz[UNK]z[SEP]z[PAD]z[CLS]z[MASK])r   r   r   r   )  r   r   r   ii   vocabc                 r   || _         ||| _        n>t        |      dt        |      dt        |      dt        |      dt        |      di| _        t        t	        j
                  | j                  t        |                  | _        t        j                  d|||      | j                  _	        t        j                         | j                  _        t        j
                  d	
      | j                  _        t        | @  d||||||||	|
|||||d| || _        |	| _        |
| _        || _        || _        t        | j,                        }t        | j.                        }| j0                  }| j2                  }t5        j6                  | d| d| d| d| d||f||fg      | j                  _        y )Nr         r	      )r   	unk_tokenT)
clean_texthandle_chinese_charsstrip_accents	lowercasez##)prefix)do_lower_caser"   	sep_token	pad_token	cls_token
mask_tokencls_token_boxsep_token_boxpad_token_boxpad_token_labelonly_label_first_subwordtokenize_chinese_charsr%   model_max_lengthz:0 $A:0 z:0z:0 $B:1 z:1)singlepairspecial_tokens )r(   _vocabstrr   r   	WordPiece
_tokenizerr   BertNormalizer
normalizerr   BertPreTokenizerpre_tokenizerr   decodersuper__init__r-   r.   r/   r0   r1   r+   r)   cls_token_idsep_token_idr   TemplateProcessingpost_processor)selfr   r(   r"   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r%   r3   kwargsclsseprC   rD   	__class__s                        h/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/layoutlmv2/tokenization_layoutlmv2.pyrB   zLayoutLMv2Tokenizer.__init__   s   & +DK IIIIJDK $F$4$44;;RUV_R`$ab%0%?%?!7'#	&
" )7(G(G(I%"*"4"4D"A 	
'!'''+%=#9'-	
 	
$ +**.(@% $..!$..!(((()3)F)FU(3%r*5XcU"5l#l#*
&    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verbosereturnc                 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)
isinstancer9   listtuplelen)ts    rL   _is_valid_text_inputz:LayoutLMv2Tokenizer.__call__.<locals>._is_valid_text_input  sz    !S!Ae}-q6Q;!c*!tUm4qt9>EZ!Q-EE rM   NzStext input must of type `str` (single example) or `List[str]` (batch of examples). zwWords must be 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_pairrP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rN   rO   r7   )	
ValueErrorrd   re   rf   rg   zipboolbatch_encode_plusencode_plus)rG   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rH   ri   
is_batchedwordswords_exampleboxes_examplerk   rl   s                               rL   __call__zLayoutLMv2Tokenizer.__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!" (>#$ ,%&  ) rM   rk   rl   c           	           | j                   d||||
|d|\  }}}} | j                  di d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|d|d|d||S )NrS   rT   rU   rW   r`   rk   rl   rP   rQ   rR   padding_strategytruncation_strategyrU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   r7   )"_get_padding_truncation_strategies_batch_encode_plus)rG   rk   rl   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rH   ry   rz   s                          rL   rp   z%LayoutLMv2Tokenizer.batch_encode_plus  s   2 ElDDkDk E
!!1E
 E
A-z6 't&& 
%=

 
 $	

  2
 .
 !4
 "
 
  2
 &
 *
 #8
 #8
 '@
  (B!
" $:#
$ (%
& )
 	
rM   r5   c                 |    |r||fgn|g} | j                   j                  |f|dd|}|r|d   j                  S g S )NFrR   is_pretokenizedr   )r;   encode_batchtokens)rG   rN   r5   rR   rH   batched_input	encodingss          rL   tokenizezLayoutLMv2Tokenizer.tokenize  sX    *.$TF0DOO00
.@RW
[a
	 '0y|""7R7rM   c           	           | j                   d||||
|d|\  }}}} | j                  di d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|d|d|d||S )aj  
        Tokenize and prepare for the model a sequence or a pair of sequences. .. warning:: This method is deprecated,
        `__call__` should be used instead.

        Args:
            text (`str`, `List[str]`, `List[List[str]]`):
                The first sequence to be encoded. This can be a string, a list of strings or a list of list of strings.
            text_pair (`List[str]` or `List[int]`, *optional*):
                Optional second sequence to be encoded. This can be a list of strings (words of a single example) or a
                list of list of strings (words of a batch of examples).
        rx   rN   rP   rO   rQ   rR   ry   rz   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   r7   )r{   _encode_plus)rG   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rH   ry   rz   s                          rL   rq   zLayoutLMv2Tokenizer.encode_plus  s   J ElDDkDk E
!!1E
 E
A-z6 !t   


  
 $	

  2
 .
 !4
 "
 
  2
 &
 *
 #8
 #8
 '@
  (B!
" $:#
$ (%
& )
 	
rM   ry   rz   c                 `   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   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"                         t/        d
       |$j!                  |'       $ |$|d<   |g }+t        t        |d               D ]  }%|r	|d	   |%   }&n|%}&g },t        |d   |%   |d   |%   ||%   j                        D ]  \  }(}-}*|*`| j0                  r<|-d   dk(  r|,j!                  ||&   |*          5|,j!                  | j2                         Q|,j!                  ||&   |*          i|,j!                  | j2                          |+j!                  |,        |+|d<   |s|d= t5        |||      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 ))ry   rz   rU   rV   rW   rX   Tr~   )encodingrZ   r[   r\   r]   r^   r_   r`   r   r   overflow_to_sample_mappingzId not recognizedbboxoffset_mappinglabels)tensor_type)rd   re   	TypeErrortypeset_truncation_and_paddingsplitr;   r   _convert_encoding	enumeraterg   &_eventual_warn_about_too_long_sequencerangern   sequence_idsword_idsappendr/   rC   r-   rD   r.   pad_token_idrm   r1   r0   r
   ).rG   rk   rl   rP   rQ   rR   ry   rz   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rN   rO   r   r   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.                                                 rL   r|   z&LayoutLMv2Tokenizer._batch_encode_plus  s   , 2D9MdSkNlMmmnopp 	''- 3!1% 	( 	
 Yq'rodIy(A'r$'rOO00$1  1 
	2 & 
  ""!&;&;*C+E* (,++ #  
  
, '*1- 	*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N"
(N)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 )Nrl   rP   rQ   rR   ry   rz   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   r   r   )	r|   ro   r
   itemsrg   rd   re   r   r   )rG   rN   rO   rP   rQ   rR   ry   rz   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rH   r   batched_boxesbatched_word_labelsbatched_outputr   values                              rL   r   z LayoutLMv2Tokenizer._encode_plus  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 )a#  
        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:
                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   rightr   r   r   special_tokens_maskleftzInvalid padding strategy:)model_input_namesr   LONGESTrg   
DO_NOT_PADrX   pad_token_type_idr/   r0   r   rm   r9   )
rG   r   rU   ry   rW   rX   r[   required_inputneeds_to_be_padded
differences
             rL   _padzLayoutLMv2Tokenizer._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rM   c                 l    | j                   g|z   | j                  gz   }|r||| j                  g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. A BERT sequence has the following format:

        - single sequence: `[CLS] X [SEP]`
        - pair of sequences: `[CLS] A [SEP] B [SEP]`

        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.
        )rC   rD   )rG   token_ids_0token_ids_1outputs       rL    build_inputs_with_special_tokensz4LayoutLMv2Tokenizer.build_inputs_with_special_tokensH  sE    " ##${2d6G6G5HHkT%6%6$777FrM   )NNNTFNNr   NNNNNFFFFT)NF)N)&__name__
__module____qualname____doc__VOCAB_FILES_NAMESvocab_files_namesr   r:   modelr   r9   dictintrB   r   "LAYOUTLMV2_ENCODE_KWARGS_DOCSTRING2LAYOUTLMV2_ENCODE_PLUS_ADDITIONAL_KWARGS_DOCSTRINGr   r   re   ro   r   r   r   r
   rv   r   rp   r   rq   r   DO_NOT_TRUNCATEr|   r   r   r   r   __classcell__)rK   s   @rL   r   r   p   s   +Z *EI .2"."!%#!O
T#s(^#d*O
b :<no IM@D:>#'056:!%)-#'26-1-1*/+0',#)U++d9o=EV@WWU %t,='>>EU DId49o!66=	U
 #Yd3i047U !U o-U 3J!33U $JU U  $JU DjU j(4/U  $d{U  $d{U  $(!U" %)#U$ !%%U& 'U( )U, 
-U pUn :<no  $.2:>#'056:!%)-#'26-1-1*/+0',#)6
"&y/D4G"G$O`Ja"a6
 6
 DcO$t+	6

 #Yd3i0476
 !6
 o-6
 3J!336
 $J6
 6
  $J6
 Dj6
 j(4/6
  $d{6
  $d{6
  $(!6
" %)#6
$ !%%6
& '6
( )6
, 
-6
 p6
p8S 8d
 8t 8jnorjs 8 :<no /3(,(,#'056:!%)-#'26-1-1*/+0',#)B
++B
 %t+B
 DI%	B

 #Y%B
 !B
 o-B
 3J!33B
 $JB
 B
  $JB
 DjB
 j(4/B
  $d{B
  $d{B
  $(!B
" %)#B
$ !%%B
& 'B
( )B
, 
-B
 pB
N  $.2.2#',;,F,F2D2T2T!%)-#'%)-1-1*/+0',#)X`"&y/D4G"G$O`Ja"aX` X` DcO$t+	X`
 $s)_t+X` !X` *X` 0X` $JX` X`  $JX` DjX` d
X`  $d{X`  $d{X`  $(!X`" %)#X`$ !%%X`& 'X`( )X`* 
+X`z /3(,(,#',;,F,F2D2T2T!%)-#'&*-1-1*/+0',#)B++B %t+B DI%	B
 #Y%B !B *B 0B $JB B  $JB DjB tB  $d{B  $d{B  $(!B" %)#B$ !%%B& 'B( )B, 
-BN "&,;,F,F)-#'-1WS,./-?W $JW *	W
  $JW DjW  $d{W 
WrrM   r   N)r   
tokenizersr   r   r   r   r   r   tokenization_utils_baser
   r   r   r   r   r   r   r   tokenization_utils_tokenizersr   utilsr   r   
get_loggerr   loggerr   r   r   r   __all__LayoutLMv2TokenizerFastr7   rM   rL   <module>r      s}    \ [	 	 	 ? 0 
		H	%#.BRS )& "V6 2<n+ nb !
! . rM   