Ë
    T^(hJ©  ã                   ó  — 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 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 ddlmZmZ  ej@                  e!«      Z"ddddœZ# e«       d„ «       Z$d„ Z% G d„ de«      Z&dgZ'y)z­
Fast tokenization class for MarkupLM. It overwrites 2 methods of the slow tokenizer class, namely _batch_encode_plus
and _encode_plus, in which the Rust tokenizer is used.
é    N)Ú	lru_cache)ÚDictÚListÚOptionalÚTupleÚUnion)Ú
processorsé   )ÚPaddingStrategyÚ
TensorTypeÚadd_end_docstrings)ÚENCODE_KWARGS_DOCSTRINGÚ
AddedTokenÚBatchEncodingÚEncodedInputÚPreTokenizedInputÚ	TextInputÚTextInputPairÚTruncationStrategy)ÚPreTrainedTokenizerFast)Úloggingé   )Ú0MARKUPLM_ENCODE_PLUS_ADDITIONAL_KWARGS_DOCSTRINGÚMarkupLMTokenizerz
vocab.jsonz
merges.txtztokenizer.json)Ú
vocab_fileÚmerges_fileÚtokenizer_filec            	      óò  — t        t        t        d«      t        d«      dz   «      «      t        t        t        d«      t        d«      dz   «      «      z   t        t        t        d«      t        d«      dz   «      «      z   } | dd }d	}t        d
«      D ]1  }|| vsŒ| j                  |«       |j                  d
|z   «       |dz  }Œ3 |D �cg c]  }t	        |«      ‘Œ }}t        t        | |«      «      S c c}w )a3  
    Returns list of utf-8 byte and a mapping to unicode strings. We specifically avoids mapping to whitespace/control
    characters the bpe code barfs on. The reversible bpe codes work on unicode strings. This means you need a large #
    of unicode characters in your vocab if you want to avoid UNKs. When you're at something like a 10B token dataset
    you end up needing around 5K for decent coverage. This is a significant percentage of your normal, say, 32K bpe
    vocab. To avoid that, we want lookup tables between utf-8 bytes and unicode strings.
    ú!ú~r   õ   Â¡õ   Â¬õ   Â®õ   Ã¿Nr   é   )ÚlistÚrangeÚordÚappendÚchrÚdictÚzip)ÚbsÚcsÚnÚbs       úu/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/markuplm/tokenization_markuplm_fast.pyÚbytes_to_unicoder2   /   sæ   € ô 	ŒU”3�s“8œS ›X¨™\Ó*Ó+¬d´5¼¸T»ÄCÈÃIÐPQÁMÓ3RÓ.SÑSÔVZÔ[`ÔadÐeiÓajÔloÐptÓluÐxyÑlyÓ[zÓV{Ñ{ð ð 
‰Aˆ€BØ	€AÜ�4‹[ò ˆØ�BŠ;Ø�I‰I�aŒLØ�I‰I�d˜Q‘hÔØ�‰F‰Að	ð
 Ö	�QŒ#ˆa�&Ð	€BÐ	Ü”�B˜“ÓÐùò 
s   ÃC4c                 ób   — t        «       }| d   }| dd D ]  }|j                  ||f«       |}Œ |S )z„
    Return set of symbol pairs in a word. Word is represented as tuple of symbols (symbols being variable-length
    strings).
    r   r   N)ÚsetÚadd)ÚwordÚpairsÚ	prev_charÚchars       r1   Ú	get_pairsr:   F   sF   € ô
 ‹E€EØ�Q‘€IØ�Q�R�ò ˆØ�	‰	�9˜dÐ#Ô$Ø‰	ðð €Ló    c            *       ó  ‡ — e Zd ZdZeZeZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d0ˆ fd„	Zd„ Z	 e
ee«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d1d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 e
ee«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d1deee   ee   ee   f   dee   d
eeeee            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d2ded ee   dedee   fd!„Z e
ee«      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d1deeef   d	ee   d
eeee         deee      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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e   ee   f   de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j<                  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j<                  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d(„Z%	 d3d)ee   d*eee      dee   fd+„Z&	 d3d)ee   d*eee      dee   fd,„Z'd3d-ed.ee   de(e   fd/„Z)ˆ xZ*S )4ÚMarkupLMTokenizerFasta  
    Construct a MarkupLM tokenizer. Based on byte-level Byte-Pair-Encoding (BPE).

    [`MarkupLMTokenizerFast`] 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 [`PreTrainedTokenizer`] which
    contains most of the main methods.

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

    Args:
        vocab_file (`str`):
            Path to the vocabulary file.
        merges_file (`str`):
            Path to the merges file.
        errors (`str`, *optional*, defaults to `"replace"`):
            Paradigm to follow when decoding bytes to UTF-8. See
            [bytes.decode](https://docs.python.org/3/library/stdtypes.html#bytes.decode) for more information.
        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).
    NFTc                 ó(  •— 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|}t        ‰| �  di d|“d|“d|“d|“d|“d	|“d
|“d|
“d|“d|	“d|“d|“d|“d|“d|“d|“d|“d|“d|“|¤Ž |rt        d«      ‚|| _        d}t        | j                  |d «      }|r«t        j                  |j                  «       «      }d|v rt        |d   «      |d<   d|v rt        |d   «      |d<   d}|j                  d|«      |k7  r||d<   d}|r>t        t        |j                  d«      «      } |di |¤Ž}t!        | j                  ||«       || _        || _        || _        t)        | j                  «      | _        | j*                  dz   | _        | j,                  g| j"                  z  | _        | j&                  g| j"                  z  | _        || _        || _        y )NF)ÚlstripÚrstripTr   r   Ú	tags_dictr   ÚerrorsÚ	bos_tokenÚ	eos_tokenÚ	unk_tokenÚ	sep_tokenÚ	cls_tokenÚ	pad_tokenÚ
mask_tokenÚadd_prefix_spaceÚtrim_offsetsÚ	max_depthÚ	max_widthÚ	pad_widthÚpad_token_labelÚonly_label_first_subwordzY`trim_offsets=True` is not implemented for MarkupLMTokenizerFast. Please set it to False.Úpost_processorÚsepÚclsÚtyper   © )Ú
isinstanceÚstrr   ÚsuperÚ__init__ÚNotImplementedErrorrA   ÚgetattrÚbackend_tokenizerÚjsonÚloadsÚ__getstate__ÚtupleÚgetr	   ÚpopÚsetattrrL   rM   rN   ÚlenÚ
unk_tag_idÚ
pad_tag_idÚpad_xpath_tags_seqÚpad_xpath_subs_seqrO   rP   )Úselfr   r   rA   r   rB   rC   rD   rF   rG   rE   rH   rI   rJ   rL   rM   rN   rO   rP   rK   ÚkwargsÚtokenizer_componentÚtokenizer_component_instanceÚstateÚchanges_to_applyÚcomponent_classÚ	new_valueÚ	__class__s                              €r1   rY   zMarkupLMTokenizerFast.__init__�   s  ø€ ô. JTÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ÜISÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ÜISÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ÜISÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ÜISÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ÜISÐT]Ô_bÔIc”J˜y°¸uÕEÐirˆ	ô KUÐU_ÔadÔJe”Z 
°4ÀÕFÐkuˆ
ä‰Ñò 	
Ù!ð	
á#ð	
ñ  ð	
ñ *ð		
ñ
 ð	
ñ  ð	
ñ  ð	
ñ  ð	
ñ  ð	
ñ  ð	
ñ  ð	
ñ "ð	
ñ .ð	
ñ &ð	
ñ  ð	
ñ   ð!	
ñ"  ð#	
ñ$ ,ð%	
ñ& &>Øò)	
ñ, ô
 &Økóð ð #ˆŒà.ÐÜ'.¨t×/EÑ/EÐGZÐ\`Ó'aÐ$Ù'Ü—J‘JÐ;×HÑHÓJÓKˆEð ˜‰~Ü$ U¨5¡\Ó2��e‘Ø˜‰~Ü$ U¨5¡\Ó2��e‘à$Ðà�y‰yÐ+Ð-=Ó>ÐBRÒRØ,<�Ð(Ñ)Ø#'Ð áÜ")¬*°e·i±iÀÓ6GÓ"H�Ù+Ñ4¨eÑ4�	Ü˜×.Ñ.Ð0CÀYÔOð #ˆŒØ"ˆŒØ"ˆŒÜ˜dŸn™nÓ-ˆŒØŸ/™/¨AÑ-ˆŒØ#'§?¡?Ð"3°d·n±nÑ"DˆÔØ#'§>¡>Ð"2°T·^±^Ñ"CˆÔØ.ˆÔØ(@ˆÕ%r;   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Ústriprd   Úintr)   rA   ra   re   ÚminrM   rL   rf   rN   )	ri   ÚxpathÚxpath_tags_listÚxpath_subs_listÚxpath_unitsÚunitÚ	name_subsÚtag_nameÚsubs	            r1   Úget_xpath_seqz#MarkupLMTokenizerFast.get_xpath_seqó   s+  € ð
 ˆØˆà—k‘k #Ó&ˆØò 	=ˆDØ—:‘:”<ØØŸ
™
›×*Ñ*¨3Ó/ˆIØ  ‘|ˆHÜ˜9“~¨Ò*‘!´°I¸a±LÀÀ"Ð4EÓ0FˆCØ×"Ñ" 4§>¡>×#5Ñ#5°hÀÇÁÓ#PÔQØ×"Ñ"¤3 t§~¡~°sÓ#;Õ<ð	=ð *Ð*:¨D¯N©NÐ;ˆØ)Ð*:¨D¯N©NÐ;ˆØ˜DŸO™OÐ,°·±ÄÀ_ÓAUÑ0UÑVÑVˆØ˜DŸN™NÐ+¨t¯~©~ÄÀOÓ@TÑ/TÑUÑUˆà Ð/Ð/r;   r   ÚtextÚ	text_pairÚxpathsÚnode_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|}|€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 )"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).
        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)rV   rW   r&   r`   rd   )Úts    r1   Ú_is_valid_text_inputz<MarkupLMTokenizerFast.__call__.<locals>._is_valid_text_input7  sz   € Ü˜!œSÔ!àÜ˜A¤¤e˜}Ô-ä�q“6˜Q’;àÜ  !¡¤cÔ*àÜ  !¡¤t¬U mÔ4ä˜q ™t›9¨™>ÒE¬Z¸¸!¹¸Q¹ÄÓ-EÐEà àr;   NzStext 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).r   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_pairr…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   rƒ   r„   rU   )	Ú
ValueErrorrV   r&   r`   rd   r,   ÚboolÚbatch_encode_plusÚencode_plus)ri   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   rj   rš   Ú
is_batchedÚnodesÚnodes_exampleÚxpaths_examplerœ   r�   s                               r1   Ú__call__zMarkupLMTokenizerFast.__call__  sb  € òV	ð( Ð á'¨Ô-Ü Ð!vÓwÐwÜ˜i¬$´¨Ô7Ü ðMóð ô ˜d¤T¬5 MÔ2Ü ðMóð ð
 Ð Ü# D¬4´¨-Ó8‰Jä# D¬4´¨-Ó8Òh¸TÒhÄjÐQUÐVWÑQXÔ[_ÔafÐZgÓFhˆJà!Ð)‘¨yˆØÐ!ÐJÐ#JÓJÐ!ÙÜ�u“:¤ V£Ò,ÐqÐ.qÓqÐ,Ü14°U¸FÓ1Cò wÑ-�˜~Ü˜=Ó)¬S°Ó-@Ó@ÐvÐBvÓvÐ@ñwô �u“:¤ V£Ò,ÐbÐ.bÓbÐ,áØÐ$¬¨T«´c¸)³nÒ)DÜ Ø.¬s°4«y¨kð :Ü˜I›Ð' qð*óð ð FOÐEZ¤t¬C°°iÓ,@Ô'AÐ`dÐ$Ü˜9¨DÐ0Ó1ˆGØ)�4×)Ñ)ò Ù)Aðáðñ ðñ (ð	ñ
 $6ðñ  ðñ &ðñ &ðñ ðñ $6ðñ *ðñ  .ðñ '<ðñ '<ðñ +Dðñ  ,Fð!ñ" (>ð#ñ$ ,ð%ñ&  Øñ)ð ð. $�4×#Ñ#ò Ùðá#ðñ ðñ (ð	ñ
 $6ðñ  ðñ &ðñ &ðñ ðñ $6ðñ *ðñ  .ðñ '<ðñ '<ðñ +Dðñ  ,Fð!ñ" (>ð#ñ$ ,ð%ñ&  Øñ)ð r;   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©rˆ   r‰   rŠ   rŒ   r•   rœ   r�   r…   r†   r‡   Úpadding_strategyÚtruncation_strategyrŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   rU   )Ú"_get_padding_truncation_strategiesÚ_batch_encode_plus)ri   rœ   r�   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   rj   r©   rª   s                          r1   r    z'MarkupLMTokenizerFast.batch_encode_plus   s  € ð: ElÀD×DkÑDkð E
ØØ!Ø!Ø1ØñE
ð ñE
ÑAÐÐ-¨z¸6ð 'ˆt×&Ñ&ò 
Ù%=ð
áð
ñ ð
ñ $ð	
ñ
  2ð
ñ .ð
ñ !4ð
ñ "ð
ñ ð
ñ  2ð
ñ &ð
ñ *ð
ñ #8ð
ñ #8ð
ñ '@ð
ñ  (Bð!
ñ" $:ð#
ñ$ (ð%
ñ& Øñ)
ð 	
r;   Úpairc                 ót   — |r||fgn|g} | j                   j                  |f|ddœ|¤Ž}|d   j                  S )NF©r‡   Úis_pretokenizedr   )Ú
_tokenizerÚencode_batchÚtokens)ri   rƒ   r­   r‡   rj   Úbatched_inputÚ	encodingss          r1   ÚtokenizezMarkupLMTokenizerFast.tokenizeÝ  sQ   € Ù*.˜$ ˜™°T°FˆØ0�D—O‘O×0Ñ0Øð
Ø.@ÐRWñ
Ø[añ
ˆ	ð ˜‰|×"Ñ"Ð"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 )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¨   rƒ   r…   r„   r†   r‡   r©   rª   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   rU   )r«   Ú_encode_plus)ri   rƒ   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   rj   r©   rª   s                          r1   r¡   z!MarkupLMTokenizerFast.encode_pluså  s  € ðJ ElÀD×DkÑDkð E
ØØ!Ø!Ø1ØñE
ð ñE
ÑAÐÐ-¨z¸6ð !ˆt× Ñ ò 
Ùð
áð
ñ  ð
ñ $ð	
ñ
  2ð
ñ .ð
ñ !4ð
ñ "ð
ñ ð
ñ  2ð
ñ &ð
ñ *ð
ñ #8ð
ñ #8ð
ñ '@ð
ñ  (Bð!
ñ" $:ð#
ñ$ (ð%
ñ& Øñ)
ð 	
r;   r©   rª   c                 óÐ  — t        |t        «      st        dt        |«      › d�«      ‚| j	                  ||||	|
|¬«       |r|D ��cg c]
  \  }}|g|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 }$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,                  | j.                  fv r7|(j!                  | j"                  «       |)j!                  | j$                  «       Œât1        d
«      ‚ |$j!                  |(«       |%j!                  |)«       �ŒT |$|d<   |%|d<   |�ôg }/t        t        |d   «      «      D ]Î  }&|r	|d	   |&   }'n|&}'g }0t        |d   |&   |d   |&   ||&   j                  «      D ]ƒ  \  }*}1},|,�`| j2                  r<|1d   dk(  r|0j!                  ||'   |,   «       Œ5|0j!                  | j4                  «       ŒQ|0j!                  ||'   |,   «       Œi|0j!                  | j4                  «       Œ… |/j!                  |0«       ŒÐ |/|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 ú))r©   rª   rŠ   r‹   rŒ   r�   Tr¯   )Úencodingr�   r�   r‘   r’   r“   r”   r•   r   Ú	input_idsÚoverflow_to_sample_mappingzId not recognizedÚxpath_tags_seqÚxpath_subs_seqÚoffset_mappingÚlabels)Útensor_type)rV   r&   Ú	TypeErrorrT   Úset_truncation_and_paddingr±   r²   Ú_convert_encodingÚkeysÚ	enumeraterd   Ú&_eventual_warn_about_too_long_sequencer'   r,   Úsequence_idsÚword_idsr)   rg   rh   r‚   ÚextendÚcls_token_idÚsep_token_idÚpad_token_idrž   rP   rO   r   )2ri   rœ   r�   r…   r†   r‡   r©   rª   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   rƒ   r„   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_idr{   r|   rÁ   Úlabels_exampleÚoffsets2                                                     r1   r¬   z(MarkupLMTokenizerFast._batch_encode_plus*  sä  € ô4 Ð2´DÔ9ÜÐMÌdÐSkÓNlÐMmÐmnÐoÓpÐpð 	×'Ñ'Ø-Ø 3Ø!ØØ1Ø%ð 	(ô 	
ñ ØSk×'lÁÀÀi¨$¨°Ò(;Ð'lÐ$Ñ'là—O‘O×0Ñ0Ø$Ø1Ø ð 1ó 
ˆ	ð, &ö 
ð ð ×"Ñ"Ø!Ø&;Ø&;Ø*CØ+EàÐ*ñ (,à+Ø+Øð #õ ð 
Ðð  
ð, ÐØ'¨Ñ*¨1Ñ-×2Ñ2Ó4ò 	*ˆCØ&:×NÐN™7˜4 ÀDÈÁIÒN¸q’QÐN�QÐNˆEÒNØ$)Ð˜SÒ!ð	*ð 1E×SÐS¡W Q¨ÈdÒSÈšqÐS˜qÐSÐÒSñ %Ø)+Ð&Ü )Ð*>Ó ?ò K‘�‘9�D˜!Ø*¨q¨c´C¸¸[Ñ8IÓ4JÑ.JÑJÑ*ðKà=WÐÐ9Ñ:à)¨+Ñ6ò 	XˆIØ×7Ñ7¸	À:ÈwÕWð	Xð ˆØˆÜ ¤Ð%5°kÑ%BÓ!CÓDó 	:ˆKÙ(Ø!1Ð2NÑ!OÐP[Ñ!\‘à!,�Ø%'Ð"Ø%'Ð"Ü,/Ø  Ñ-¨kÑ:Ø# KÑ0×=Ñ=Ø# KÑ0×9Ñ9ó-ò >Ñ(��K ð
 Ð&Ù ;°!Ò#3Ø.×5Ñ5°d×6MÑ6MÔNØ.×5Ñ5°d×6MÑ6MÕNà;?×;MÑ;MÈfÐUcÑNdÐelÑNmÓ;nÑ8˜¨Ø.×5Ñ5°Ð6GÔHØ.×5Ñ5°Ð6GÕHà˜d×/Ñ/°×1BÑ1BÀD×DUÑDUÐVÑVØ.×5Ñ5°d×6MÑ6MÔNØ.×5Ñ5°d×6MÑ6MÕNä(Ð)<Ó=Ð=ð%>ð& ×!Ñ!Ð"8Ô9Ø×!Ñ!Ð"8Ö9ð7	:ð: .<ÐÐ)Ñ*Ø-;ÐÐ)Ñ*ð Ð"ØˆFÜ$¤SÐ)9¸+Ñ)FÓ%GÓHò .�Ù,Ø%5Ð6RÑ%SÐT_Ñ%`‘Nà%0�NØ!#�Ü+.Ø$ [Ñ1°+Ñ>Ø$Ð%5Ñ6°{ÑCØ'¨Ñ4×=Ñ=ó,ò DÑ'�B˜ ð
 Ð*Ø×8Ò8Ø% a™y¨Aš~à .× 5Ñ 5°kÀ.Ñ6QÐRYÑ6ZÕ [à .× 5Ñ 5°d×6JÑ6JÕ Kà*×1Ñ1°+¸nÑ2MÈgÑ2VÕWà&×-Ñ-¨d×.BÑ.BÕCðDð  —‘˜nÕ-ð-.ð0 *0Ð˜XÑ&á)Ø$Ð%5Ð6äÐ-Ð/BÐP^Ô_Ð_ùók (mùò 
ùô0 OùäSs   ÁOÁ;$OÃO
Ã)O!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�   r…   r†   r‡   r©   rª   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   r   r¼   )	r¬   rŸ   r   Úitemsrd   rV   r&   rµ   rÈ   )ri   rƒ   r„   r…   r†   r‡   r©   rª   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   rj   r´   Úbatched_xpathsÚbatched_node_labelsÚbatched_outputrÑ   Úvalues                              r1   r¸   z"MarkupLMTokenizerFast._encode_plusÉ  s‘  € ñ6 09˜$ 	Ð*Ñ+¸t¸fˆØ ˜ˆØ/:Ð/F˜{™mÈDÐØ0˜×0Ñ0Øò
ä˜¨$Ð.Ô/ð
ñ "ð
ñ ,ð	
ñ
  2ð
ñ .ð
ñ !4ð
ñ "ð
ñ ð
ñ  2ð
ñ &ð
ñ *ð
ñ #8ð
ñ #8ð
ñ '@ð
ñ  (Bð!
ñ" $:ð#
ñ$ (ð%
ñ& Øñ)
ˆð2 Ð!Ñ*CÜ*ð '5×&:Ñ&:Ó&<÷á"˜˜Uð ¤S¨£Z°!¢^¼
À5ÈÁ8ÌTÔ8R˜˜qšÐX]Ñ]óð ×(Ñ(óˆNð 	×3Ñ3°NÀ;Ñ4OÐQ[Ð]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   | 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)
        Úattention_maskr   r   ÚrightÚtoken_type_idsr¾   r¿   rÁ   Úspecial_tokens_maskÚleftzInvalid padding strategy:)Úmodel_input_namesr   ÚLONGESTrd   Ú
DO_NOT_PADr�   Úpad_token_type_idrg   rh   rO   rÎ   rž   rW   )
ri   rè   rŠ   r©   rŒ   r�   r�   Úrequired_inputÚneeds_to_be_paddedÚ
differences
             r1   Ú_padzMarkupLMTokenizerFast._pad  s“  € ðB !Ð(Ø$4¸×8NÑ8NÐ$NÐ!à'¨×(>Ñ(>¸qÑ(AÑBˆàœ×6Ñ6Ò6Ü˜^Ó,ˆJàÐ!Ð&8Ð&DÈ*ÐWiÑJiÐmnÒJnØ%Ð);Ñ;¸qÑ@ÐDVÑVˆJà-´×1KÑ1KÑKÒqÔPSÐTbÓPcÐgqÑPqÐñ !Ð%5¸^Ñ%KØ01¨s´S¸Ó5HÑ/HˆNÐ+Ñ,âØ#¤c¨.Ó&9Ñ9ˆJØ+7Ð+C™<È×IZÑIZˆLØ˜wÒ&Ù(Ø7EÐFVÑ7WÐ[\ÐZ]Ð`jÑZjÑ7j�NÐ#3Ñ4Ø# ~Ñ5à&Ð'7Ñ8¸D×<RÑ<RÐ;SÐV`Ñ;`Ñ`ð #Ð#3Ñ4ð $ ~Ñ5à&Ð'7Ñ8¸D×<SÑ<SÐ;TÐWaÑ;aÑað #Ð#3Ñ4ð $ ~Ñ5à&Ð'7Ñ8¸D×<SÑ<SÐ;TÐWaÑ;aÑað #Ð#3Ñ4ð ˜~Ñ-Ø/=¸hÑ/GÈ4×K_ÑK_ÐJ`ÐcmÑJmÑ/m�N 8Ñ,Ø(¨NÑ:Ø<JÐK`Ñ<aÐefÐdgÐjtÑdtÑ<t�NÐ#8Ñ9Ø<JÈd×N_ÑN_ÐM`ÐcmÑMmÑ<m�˜t×5Ñ5°aÑ8Ñ9ð0 Ðð/  Ò'Ù(Ø89°s¸ZÑ7GÈ.ÐYiÑJjÑ7j�NÐ#3Ñ4Ø# ~Ñ5Ø8<×8NÑ8NÐ7OÐR\Ñ7\Ð_mØ(ñ`ñ 8�NÐ#3Ñ4ð $ ~Ñ5Ø8<×8OÑ8OÐ7PÐS]Ñ7]Ð`nØ(ñañ 8�NÐ#3Ñ4ð $ ~Ñ5Ø8<×8OÑ8OÐ7PÐS]Ñ7]Ð`nØ(ñañ 8�NÐ#3Ñ4ð ˜~Ñ-Ø04×0DÑ0DÐ/EÈ
Ñ/RÐUcÐdlÑUmÑ/m�N 8Ñ,Ø(¨NÑ:Ø=>¸CÀ*Ñ<LÈ~Ð^sÑOtÑ<t�NÐ#8Ñ9Ø=A×=NÑ=NÐ<OÐR\Ñ<\Ð_mÑ<m�˜t×5Ñ5°aÑ8Ñ9ð Ðô !Ð!<¼sÀ<Ó?PÑ!PÓQÐQàÐr;   Ú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.
        )rÌ   rÍ   )ri   r÷   rø   rS   rR   s        r1   Ú build_inputs_with_special_tokensz6MarkupLMTokenizerFast.build_inputs_with_special_tokenso  sb   € ð" ÐØ×%Ñ%Ð&¨Ñ4¸×8IÑ8IÐ7JÑJÐJØ× Ñ Ð!ˆØ× Ñ Ð!ˆØ�[Ñ  3Ñ&¨Ñ4°sÑ:Ð:r;   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   )rÍ   rÌ   rd   )ri   r÷   rø   rR   rS   s        r1   Ú$create_token_type_ids_from_sequencesz:MarkupLMTokenizerFast.create_token_type_ids_from_sequences†  sh   € ð × Ñ Ð!ˆØ× Ñ Ð!ˆàÐÜ�s˜[Ñ(¨3Ñ.Ó/°1°#Ñ5Ð5Ü�3˜Ñ$ sÑ*¨[Ñ8¸3Ñ>Ó?À1À#ÑEÐEr;   Úsave_directoryÚfilename_prefixc                 óf   — | j                   j                  j                  ||¬«      }t        |«      S )N)Úname)r±   ÚmodelÚsaver`   )ri   rý   rþ   Úfiless       r1   Úsave_vocabularyz%MarkupLMTokenizerFast.save_vocabularyœ  s+   € Ø—‘×%Ñ%×*Ñ*¨>ÀÐ*ÓPˆÜ�U‹|Ðr;   )NÚreplaceú<s>ú</s>r  r  z<unk>z<pad>z<mask>Fé2   iè  ié  iœÿÿÿTF)NNNTFNNr   NNNNNFFFFT)NF)N)+Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚVOCAB_FILES_NAMESÚvocab_files_namesr   Úslow_tokenizer_classrY   r‚   r   r   r   r   r   r   r   r   rx   rŸ   rW   r   r   r   r   r¦   r   r    r¶   r¡   rñ   ÚDO_NOT_TRUNCATEr¬   r¸   r   r   r+   rö   rú   rü   r   r  Ú__classcell__)rq   s   @r1   r=   r=   S   s·	  ø„ ñ7ðr *ÐØ,Ðð ØØØØØØØØØØØØØØ!%Øõ)aAòF0ñ2 Ð/Ð1aÓbð RVØ@DØCGØ#'Ø5:Ø;?Ø$(ØØ,0Ø&*Ø;?Ø04Ø04Ø*/Ø+0Ø',Ø#Øñ)Qà�IÐ0°$°y±/À4ÐHYÑCZÐZÑ[ðQð ˜EÐ"3°TÐ:KÑ5LÐ"LÑMÑNðQð �d˜4 ™9‘o t¨D°°c±©OÑ'<Ð<Ñ=ð	Qð
 ˜e D¨¡I¨t°D¸±I©Ð$>Ñ?Ñ@ðQð !ðQð �t˜S /Ð1Ñ2ðQð ˜$ Ð%7Ð7Ñ8ðQð ˜S‘MðQð ðQð % S™MðQð ˜s‘mðQð !  s¨J Ñ!7Ñ8ðQð  (¨™~ðQð  (¨™~ðQð  $(ð!Qð" %)ð#Qð$ !%ð%Qð& ð'Qð( ð)Qð, 
ò-Qó cðQñf Ð/Ð1aÓbð #'Ø26ØCGØ#'Ø5:Ø;?Ø$(ØØ,0Ø&*Ø;?Ø04Ø04Ø*/Ø+0Ø',Ø#Øñ1:
à"'Ø�‰OØ�ÑØÐ"Ñ#ð%ñ#
ð:
ð ˜$‘ð:
ð ˜˜d 4¨¡9™oÑ.Ñ/ð:
ð ˜e D¨¡I¨t°D¸±I©Ð$>Ñ?Ñ@ð:
ð !ð:
ð �t˜S /Ð1Ñ2ð:
ð ˜$ Ð%7Ð7Ñ8ð:
ð ˜S‘Mð:
ð ð:
ð % S™Mð:
ð  ˜s‘mð!:
ð" !  s¨J Ñ!7Ñ8ð#:
ð$  (¨™~ð%:
ð&  (¨™~ð':
ð( $(ð):
ð* %)ð+:
ð, !%ð-:
ð. ð/:
ð0 ð1:
ð4 
ò5:
ó cð:
ñx#˜Sð #¨°©ð #ÐRVð #ÐmqÐruÑmvó #ñ Ð/Ð1aÓbð 26Ø,0Ø+/Ø#'Ø5:Ø;?Ø$(ØØ,0Ø&*Ø;?Ø04Ø04Ø*/Ø+0Ø',Ø#Øñ)B
à�IÐ0Ð0Ñ1ðB
ð Ð-Ñ.ðB
ð ˜˜d 3™i™Ñ)ð	B
ð
 ˜d 3™iÑ(ðB
ð !ðB
ð �t˜S /Ð1Ñ2ðB
ð ˜$ Ð%7Ð7Ñ8ðB
ð ˜S‘MðB
ð ðB
ð % S™MðB
ð ˜s‘mðB
ð !  s¨J Ñ!7Ñ8ðB
ð  (¨™~ðB
ð  (¨™~ðB
ð  $(ð!B
ð" %)ð#B
ð$ !%ð%B
ð& ð'B
ð( ð)B
ð, 
ò-B
ó cðB
ðV #'Ø26Ø15Ø#'Ø,;×,FÑ,FØ2D×2TÑ2TØ$(ØØ,0Ø&*Ø(,Ø04Ø04Ø*/Ø+0Ø',Ø#Øñ1]`à"'Ø�‰OØ�ÑØÐ"Ñ#ð%ñ#
ð]`ð ˜$‘ð]`ð ˜˜d 4¨¡9™oÑ.Ñ/ð]`ð ˜d 4¨¡9™oÑ.ð]`ð !ð]`ð *ð]`ð 0ð]`ð ˜S‘Mð]`ð ð]`ð % S™Mð]`ð  ˜s‘mð!]`ð" ! ™ð#]`ð$  (¨™~ð%]`ð&  (¨™~ð']`ð( $(ð)]`ð* %)ð+]`ð, !%ð-]`ð. ð/]`ð0 ð1]`ð2 
ó3]`ðD 26Ø,0Ø+/Ø#'Ø,;×,FÑ,FØ2D×2TÑ2TØ$(ØØ,0Ø&*Ø)-Ø04Ø04Ø*/Ø+0Ø',Ø#Øñ)Bà�IÐ0Ð0Ñ1ðBð Ð-Ñ.ðBð ˜˜d 3™i™Ñ)ð	Bð
 ˜d 3™iÑ(ðBð !ðBð *ðBð 0ðBð ˜S‘MðBð ðBð % S™MðBð ˜s‘mðBð ! ™ðBð  (¨™~ðBð  (¨™~ðBð  $(ð!Bð" %)ð#Bð$ !%ð%Bð& ð'Bð( ð)Bð, 
ó-BðN %)Ø,;×,FÑ,FØ,0Ø&*Ø04ñ`à˜d 3¨Ð#4Ñ5°}ÐDÑEð`ð ˜S‘Mð`ð *ð	`ð
 % S™Mð`ð ˜s‘mð`ð  (¨™~ð`ð 
ó`ðF JNñ;Ø ™9ð;Ø3;¸DÀ¹IÑ3Fð;à	ˆc‰ó;ð0 JNñFØ ™9ðFØ3;¸DÀ¹IÑ3FðFà	ˆc‰óFñ,¨cð ÀHÈSÁMð Ð]bÐcfÑ]g÷ r;   r=   )(r  r]   Ú	functoolsr   Útypingr   r   r   r   r   Ú
tokenizersr	   Ú
file_utilsr   r   r   Útokenization_utils_baser   r   r   r   r   r   r   r   Útokenization_utils_fastr   Úutilsr   Útokenization_markuplmr   r   Ú
get_loggerr	  Úloggerr  r2   r:   r=   Ú__all__rU   r;   r1   ú<module>r     s’   ðñó
 Ý ß 5Õ 5å !ç IÑ I÷	÷ 	ó 	õ ?Ý ß fð 
ˆ×	Ñ	˜HÓ	%€à#/ÀÐ`pÑqÐ ñ ƒñó ðò,
ôKÐ3ô Kð\ #Ð
#�r;   