
    qi+                         d dl 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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	d
ZdZ G d de      ZeZddgZy)    )	Tokenizerdecoderspre_tokenizers
processors)BPE   )
ENCODE_KWARGS_DOCSTRING
AddedTokenBatchEncodingEncodedInputPaddingStrategyPreTokenizedInput
TensorType	TextInputTextInputPairTruncationStrategy)TokenizersBackend)add_end_docstringsloggingz
vocab.jsonz
merges.txtztokenizer.json)
vocab_filemerges_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 [`~tokenization_utils_base.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.
            is_split_into_words (`bool`, *optional*, defaults to `False`):
                Whether or not the input is already pretokenized (e.g. split into words). Set this to `True` if you are
                passing pretokenized inputs to avoid additional tokenization.
            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 [`~tokenization_utils_base.TensorType`], *optional*):
                If set, will return tensors instead of list of python integers. Acceptable values are:

                - `'pt'`: Return PyTorch `torch.Tensor` objects.
                - `'np'`: Return Numpy `np.ndarray` objects.
c            ,       N    e Zd ZdZeZg dZeZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4de	e
e	ef   z  eee	ef      z  dz  de	ee	   z  dz  f fdZd	 Z eee      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5d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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      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d6d!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d7de	d$e	dz  dedee	   fd%Z eee      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d6d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jB                  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jB                  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(d*Z#dej@                  dddfd+e
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d,Z%	 d8d-ee   d.ee   dz  dee   fd/Z&	 d8d-ee   d.ee   dz  dee   fd0Z'd8d1e	d2e	dz  dee	   fd3Z( xZ)S )9MarkupLMTokenizera  
    Construct a MarkupLM tokenizer. Based on byte-level Byte-Pair-Encoding (BPE).

    [`MarkupLMTokenizer`] can be used to turn HTML strings into to token-level `input_ids`, `attention_mask`,
    `token_type_ids`, `xpath_tags_seq` and `xpath_tags_seq`. This tokenizer inherits from [`TokenizersBackend`] which
    contains most of the main methods and ensures a `tokenizers` backend is always instantiated.

    Users should refer to this superclass for more information regarding those methods.

    Args:
        vocab (`str` or `dict[str, int]`, *optional*):
            Custom vocabulary dictionary. If not provided, the vocabulary is loaded from `vocab_file`.
        merges (`str` or `list[str]`, *optional*):
            Custom merges list. If not provided, merges are loaded from `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.
        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 `False`):
            Whether or not to add an initial space to the input. This allows to treat the leading word just as any
            other word. (RoBERTa tokenizer detect beginning of words by the preceding space).
    )	input_idstoken_type_idsattention_maskNFTvocabmergesc                    t        |t              rt        |dd      n|}t        |t              rt        |dd      n|}t        |t              rt        |dd      n|}t        |t              rt        |dd      n|}t        |	t              rt        |	dd      n|	}	t        |
t              rt        |
dd      n|
}
t        |t              rt        |dd      n|}|9t        |
      dt        |	      dt        |      dt        |      dt        |      di}|xs g }t        t	        ||d d	d	d
            }t        j                  |      |_        t        j                         |_	        || _
        || _        || _        t        | 8  di d|d|d|d|d|	d|d|d|
d|d|d|d|d|d|d|d|| t        |      }t        |      }| j                  }| j                   }t#        j$                  | d| | d| d| ||f||fg      | j                  _        || _        || _        || _        || _        t1        | j(                        | _        | j2                  dz   | _        | j4                  g| j*                  z  | _        | j.                  g| j*                  z  | _        || _        || _        y ) NF)lstriprstripTr         r       )r   r   dropoutcontinuing_subword_prefixend_of_word_suffixfuse_unk)add_prefix_space	tags_dicterrors	bos_token	eos_token	unk_token	sep_token	cls_token	pad_token
mask_tokenr+   trim_offsets	max_depth	max_width	pad_widthpad_token_labelonly_label_first_subwordz $A z $B )singlepairspecial_tokens )
isinstancestrr
   r   r   r   	ByteLevelpre_tokenizerr   decoder_vocab_merges
_tokenizersuper__init__cls_token_idsep_token_idr   TemplateProcessingpost_processorr,   r6   r7   r8   len
unk_tag_id
pad_tag_idpad_xpath_tags_seqpad_xpath_subs_seqr9   r:   )selfr,   r   r   r-   r.   r/   r1   r2   r0   r3   r4   r+   r6   r7   r8   r9   r:   r5   kwargs	tokenizersep_token_strcls_token_strrI   rJ   	__class__s                            d/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/markuplm/tokenization_markuplm.pyrH   zMarkupLMTokenizer.__init__   s   , JTT]_bIcJyuEir	IST]_bIcJyuEir	IST]_bIcJyuEir	IST]_bIcJyuEir	IST]_bIcJyuEir	IST]_bIcJyuEir	JTU_adJeZ
4Fku
=IIIIJE 2*,#%	
	 #1":":L\"]	$..0	# 	
	
	
  	
  		

  	
  	
  	
  	
 "	
 .	
 &	
  	
  	
  	
 ,	
  &>#	
& II(((()3)F)F#_D8!?$}oT-I--*
& # #""dnn-//A-#'??"3dnn"D#'>>"2T^^"C.(@%    c                    g }g }|j                  d      }|D ]  }|j                         s|j                         j                  d      }|d   }t        |      dk(  rdnt        |d   dd       }|j	                  | j
                  j                  || j                               |j	                  t        | j                  |              |d| j                   }|d| j                   }|| j                  g| j                  t        |      z
  z  z  }|| j                  g| j                  t        |      z
  z  z  }||fS )z
        Given the xpath expression of one particular node (like "/html/body/div/li[1]/div/span[2]"), return a list of
        tag IDs and corresponding subscripts, taking into account max depth.
        /[r   r#   N)splitstriprM   intappendr,   getrN   minr7   r6   rO   r8   )	rR   xpathxpath_tags_listxpath_subs_listxpath_unitsunit	name_substag_namesubs	            rX   get_xpath_seqzMarkupLMTokenizer.get_xpath_seq   s+   
 kk#& 	=D::<

**3/I |H9~*!IaL"4E0FC""4>>#5#5h#PQ""3t~~s#;<	= **:DNN;)*:DNN;DOO,_AU0UVVDNN+t~~O@T/TUU//rY   r   text	text_pairxpathsnode_labelsadd_special_tokenspadding
truncation
max_lengthstrideis_split_into_words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                 T   d}t        |t              rt        |      }|t        |t              rt        |      }|<|
s9||n|}t        |t              rt        |      }|}t        |t              r|j	                         }nt        |t              rw|rHt        |d   t              r5t        d |D              }|r|D cg c]  }|j	                          }}n0|}n-|r+t        |d   t              r|D cg c]  }t        |       }}||}n|}t        |t              r8|r6t        |d   t        t        f      r|D cg c]  }|gt        |      z   }}nt        |d      rt        |      nd}|g|z  }d }|K ||      st        d      t        |t        t        f      st        d      t        |t        t        f      }nVt        |t        t        f      st        d      t        |t        t        f      xr |xr t        |d   t        t        f      }||n|}|J d	       |rQt        |      t        |      k(  sJ d
       t        ||      D ]#  \  } }!t        |       t        |!      k(  rJ d        nt        |      t        |      k(  sJ 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 c c}w c c}w c c}w )%a  
        Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of
        sequences with nodes, xpaths 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).
            xpaths (`list[list[int]]`, `list[list[list[int]]]`):
                Node-level xpaths. Each bounding box should be normalized to be on a 0-1000 scale.
            node_labels (`list[int]`, `list[list[int]]`, *optional*):
                Node-level integer labels (for token classification tasks).
            is_split_into_words (`bool`, *optional*):
                Set to `True` if the inputs are already provided as pretokenized word lists.
        /document/nodeNr   c              3   $   K   | ]  }d |v  
 yw) Nr>   ).0entrys     rX   	<genexpr>z-MarkupLMTokenizer.__call__.<locals>.<genexpr>T  s     (P%(Ps   __len__c                    t        | t              ryt        | t        t        f      ret	        |       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)NTr   F)r?   r@   listtuplerM   )ts    rX   _is_valid_text_inputz8MarkupLMTokenizer.__call__.<locals>._is_valid_text_inputg  sw    !S!!dE]+q6Q;adC(adT5M2qt9>EZ!Q-EErY   zStext input must of type `str` (single example) or `list[str]` (batch of examples). zwNodes must be of type `list[str]` (single pretokenized example), or `list[list[str]]` (batch of pretokenized examples).z%You must provide corresponding xpathszAYou must provide nodes and xpaths for an equal amount of examplesz2You must provide as many nodes as there are xpathszbatch length of `text`: z- does not match batch length of `text_pair`: .batch_text_or_text_pairsis_pairro   rp   rq   rr   rs   rt   ru   rw   rx   ry   rz   r{   r|   r}   r~   r   r   rm   rn   r>   )r?   r   r   r@   r^   anyrM   hasattr
ValueErrorzipboolbatch_encode_plusencode_plus)$rR   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   rS   placeholder_xpathnodes_sourceprocessed_nodesrequires_splitr   samplelengthr   
is_batchednodesnodes_examplexpaths_exampler   r   s$                                       rX   __call__zMarkupLMTokenizer.__call__  s   Z -dE":D Z	5%AYI>"5#,#44)L,.#L1*O,,"."4"4"6L$/J|A$D%((P<(P%PN%FR*SU5;;=*S*S*6!ja%&HBN&OtF|&OO&O &+	/40_TcdeTfimothuIvJYZ,-F;ZZ18)1T_-Z[+,v5
	  '- !vwwi$7 M  $D4-8J dT5M2 M  $D4-8hThjQUVWQX[_afZgFhJ!)y!J#JJ!u:V,q.qq,14UF1C w-~=)S-@@vBvv@w u:V,b.bb,$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!" (>#$ ,%&  ) q +T 'P [s   N8N N%r   r   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rr   rs   rt   rw   r   r   r   ro   rp   rq   padding_strategytruncation_strategyrt   ru   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r>   )"_get_padding_truncation_strategies_batch_encode_plus)rR   r   r   ro   rp   rq   rr   rs   rt   ru   rw   rx   ry   rz   r{   r|   r}   r~   r   r   rS   r   r   s                          rX   r   z#MarkupLMTokenizer.batch_encode_plus  s   2 ElDDkDk E
!!1E
 E
A-z6 't&& 
%=

 
 $	

  2
 .
 !4
 "
 
  2
 &
 *
 #8
 #8
 '@
  (B!
" $:#
$ (%
& )
 	
rY   r<   c                 t    |r||fgn|g} | j                   j                  |f|dd|}|d   j                  S )NFrq   is_pretokenizedr   )rF   encode_batchtokens)rR   rm   r<   rq   rS   batched_input	encodingss          rX   tokenizezMarkupLMTokenizer.tokenize  sQ    *.$TF0DOO00
.@RW
[a
	 |"""rY   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).
        r   rm   ro   rn   rp   rq   r   r   rt   ru   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r>   )r   _encode_plus)rR   rm   rn   ro   rp   rq   rr   rs   rt   ru   rw   rx   ry   rz   r{   r|   r}   r~   r   r   rS   r   r   s                          rX   r   zMarkupLMTokenizer.encode_plus  s   J ElDDkDk E
!!1E
 E
A-z6 !t   


  
 $	

  2
 .
 !4
 "
 
  2
 &
 *
 #8
 #8
 '@
  (B!
" $:#
$ (%
& )
 	
rY   r   r   c                 
	   t        |t              st        dt        |       d      | j	                  ||||	|
|       |r~g }|D ]t  \  }}t        |t
              rt        |      }t        |t              r|g}t        |t
              rt        |      }t        |t              r|g}|j                  ||f       v |}nJg }|D ]A  }t        |t
              rt        |      }t        |t              r|g}|j                  |       C |}| 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 }%g }&t        t        |d               D ]Q  }'|r	|d	   |'   }(n|'}(g })g }*t        |d   |'   | |'   j                   | |'   j"                        D ]  \  }+},}-|-}|r<|,dk(  r7|)j                  | j$                         |*j                  | j&                         G| j)                  ||(   |-         \  }.}/|)j+                  |.g       |*j+                  |/g       |+| j,                  | j.                  | j0                  fv r7|)j                  | j$                         |*j                  | j&                         t3        d
       |%j                  |)       |&j                  |*       T |%|d<   |&|d<   |g }0t        t        |d               D ]  }'|r	|d	   |'   }(n|'}(g }1t        |d   |'   |d   |'   | |'   j"                        D ]  \  }+}2}-|-`| j4                  r<|2d   dk(  r|1j                  ||(   |-          5|1j                  | j6                         Q|1j                  ||(   |-          i|1j                  | j6                          |0j                  |1        |0|d<   |s|d= t9        || |      S c c}w c c}}}w c c}}}w )Nz/batch_text_or_text_pairs has to be a list (got ))r   r   rt   ru   rw   rx   Tr   )encodingrz   r{   r|   r}   r~   r   r   r   r   overflow_to_sample_mappingzId not recognizedxpath_tags_seqxpath_subs_seqoffset_mappinglabels)tensor_type)r?   r   	TypeErrortypeset_truncation_and_paddingr   r@   ra   rF   r   _convert_encoding	enumeraterM   &_eventual_warn_about_too_long_sequenceranger   sequence_idsword_idsrP   rQ   rl   extendrI   rJ   pad_token_idr   r:   r9   r   )3rR   r   r   ro   rp   rq   r   r   rt   ru   rw   rx   ry   rz   r{   r|   r}   r~   r   r   processed_inputsrm   rn   r   r   tokens_and_encodingssanitized_tokenskeyitem_estacksanitized_encodingsr   itoksr   r   r   batch_indexoriginal_indexxpath_tags_seq_examplexpath_subs_seq_exampleidsequence_idword_idre   rf   r   labels_exampleoffsets3                                                      rX   r   z$MarkupLMTokenizer._batch_encode_plusK  s   , 2D9MdSkNlMmmnopp 	''- 3!1% 	( 	
 !#; 	;idE*:DdC( 6Di/ $YIi-!*I ''y(9:	; (8$!0 .dE*:DdC( 6D ''-. (8$OO00$1  1 
	, & 
  ""!&;&;*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 	:K(!12N!OP[!\!,%'"%'",/ -k:#K0==#K099- >(K
 &;!#3.55d6M6MN.55d6M6MN;?;M;MfUcNdelNm;n8.556GH.556GHd//1B1BDDUDUVV.55d6M6MN.55d6M6MN()<==%>& !!"89!!"897	:: .<)*-;)* "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^__U 
0 OSs   ,$Q2%Q7
Q>c                 6   d}t        |t              rt        |      }|t        |t              rt        |      }||n|}|}t        |t              r|j	                         }n't        |t              r|rt        |d   t              r|}||}n|}|t        |d      rt        |      nd}|g|z  }|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   r   r   r   ro   rp   rq   r   r   rt   ru   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   )r?   r   r   r@   r^   r   rM   r   r   r   itemsr   r   )rR   rm   rn   ro   rp   rq   r   r   rt   ru   rw   rx   ry   rz   r{   r|   r}   r~   r   r   rS   r   nodes_singler   r   r   batched_xpathsbatched_node_labelsbatched_outputr   values                                  rX   r   zMarkupLMTokenizer._encode_plus  sE   . -dE":D Z	5%AYI(0ti&lC(*002Od+LYZO]`Aa*O"D'I>-4_i-PS)VWF'(61F 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   73F
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   | 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| 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   
        Args:
        Pad encoded inputs (on left/right and up to predefined length or max length in the batch)
            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   r   special_tokens_maskleftzInvalid padding strategy:)model_input_namesr   LONGESTrM   
DO_NOT_PADrx   pad_token_type_idrP   rQ   r9   r   r   r@   )
rR   r   rt   r   rw   rx   r{   required_inputneeds_to_be_padded
differences
             rX   _padzMarkupLMTokenizer._padV  s   B !($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 $~5&'78D<S<S;TWa;aa ##34 $~5&'78D<S<S;TWa;aa ##34 ~-/=h/G4K_K_J`cmJm/mN8,(N:<JK`<aefdgjtdt<tN#89<JdN_N_M`cmMm<mt55a890 / '(89sZ7G.YiJj7jN#34#~58<8N8N7OR\7\_m(` 8N#34 $~58<8O8O7PS]7]`n(a 8N#34 $~58<8O8O7PS]7]`n(a 8N#34 ~-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rY   token_ids_0token_ids_1c                     || j                   g|z   | j                  gz   S | j                   g}| j                  g}||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. A 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.
        )rI   rJ   )rR   r   r   clsseps        rX    build_inputs_with_special_tokensz2MarkupLMTokenizer.build_inputs_with_special_tokens  sb    " %%&48I8I7JJJ  !  ![ 3&4s::rY   c                     | j                   g}| j                  g}|t        ||z   |z         dgz  S t        ||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. 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   )rJ   rI   rM   )rR   r   r   r   r   s        rX   $create_token_type_ids_from_sequencesz6MarkupLMTokenizer.create_token_type_ids_from_sequences  sh       !  !s[(3./1#553$s*[83>?1#EErY   save_directoryfilename_prefixc                 f    | j                   j                  j                  ||      }t        |      S )N)name)rF   modelsaver   )rR   r   r   filess       rX   save_vocabularyz!MarkupLMTokenizer.save_vocabulary  s+    %%**>*PU|rY   )NNreplace<s></s>r  r  z<unk>z<pad>z<mask>F2   i  i  iTF)NNNTFNNr   FNNNNNFFFFT)NNNTFNNr   NNNNNFFFFT)NF)N)*__name__
__module____qualname____doc__VOCAB_FILES_NAMESvocab_files_namesr   r   r   r@   dictr`   r   r   floatrH   rl   r   r	   0MARKUPLM_ENCODE_PLUS_ADDITIONAL_KWARGS_DOCSTRINGr   r   r   r   r   r   r   r   r   r   r   r   r   DO_NOT_TRUNCATEr   r   r   r   r   r   r   __classcell__)rW   s   @rX   r   r   [   s	   7r *IE
 HL)-!%'bA T#s(^#d5e+<&==DbA d3i$&	bAH02 /1ab IMAE:>#'056:!%$))-#'26-1-1*/+0',#+l++d9o=EV@WWl %t,='>>El T#Y$tDI"77$>	l
 #Yd3i047l !l o-l 3J!33l $Jl l "l  $Jl Djl j(4/l  $d{l   $d{!l" $(#l$ %)%l& !%'l( )l* +l. 
/l cl\ /1ab  $/3:>#'056:!%)-#'26-1-1*/+0',#)6
"&y/D4G"G$O`Ja"a6
 6
 T$s)_%,	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
 c6
p#S #d
 #t #jnorjs # /1ab /3)-(,#'056:!%)-#'26-1-1*/+0',#)B
++B
 %t+B
 T#Y$&	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
 cB
N  $/3.2#',;,F,F2D2T2T!%)-#'%)-1-1*/+0',#)m`"&y/D4G"G$O`Ja"am` m` T$s)_%,	m`
 $s)_t+m` !m` *m` 0m` $Jm` m`  $Jm` Djm` d
m`  $d{m`  $d{m`  $(!m`" %)#m`$ !%%m`& 'm`( )m`* 
+m`d /3)-(,#',;,F,F2D2T2T!%)-#'&*-1-1*/+0',#)Z++Z %t+Z T#Y$&	Z
 #Y%Z !Z *Z 0Z $JZ Z  $JZ DjZ tZ  $d{Z  $d{Z  $(!Z" %)#Z$ !%%Z& 'Z( )Z, 
-Z~ "&,;,F,F)-#'-1`S,./-?` $J` *	`
  $J` Dj`  $d{` 
`F GK;9;379t3C;	c;0 GKF9F379t3CF	cF,c C$J Z_`cZd rY   r   MarkupLMTokenizerFastN)
tokenizersr   r   r   r   tokenizers.modelsr   tokenization_utils_baser	   r
   r   r   r   r   r   r   r   r   tokenization_utils_tokenizersr   utilsr   r   
get_loggerr  loggerr  r  r   r  __all__r>   rY   rX   <module>r     sx     G F !   ? 0 
		H	%#/`pq 04 0fL) L^ *   7
8rY   