o
    ¹ÈÏiý  ã                   @   sZ   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ G dd„ deƒZdgZd	S )
z
Processor class for MarkupLM.
é    )ÚOptionalÚUnioné   )Ú
TensorType)ÚProcessorMixin)ÚBatchEncodingÚPaddingStrategyÚTruncationStrategyc                    @   sº   e Zd ZdZdZdZdZ																			d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 dedededededeee	ef  defdd„ZdS )ÚMarkupLMProcessoraJ  
    Constructs a MarkupLM processor which combines a MarkupLM feature extractor and a MarkupLM tokenizer into a single
    processor.

    [`MarkupLMProcessor`] offers all the functionalities you need to prepare data for the model.

    It first uses [`MarkupLMFeatureExtractor`] to extract nodes and corresponding xpaths from one or more HTML strings.
    Next, these are provided to [`MarkupLMTokenizer`] or [`MarkupLMTokenizerFast`], which turns them into token-level
    `input_ids`, `attention_mask`, `token_type_ids`, `xpath_tags_seq` and `xpath_subs_seq`.

    Args:
        feature_extractor (`MarkupLMFeatureExtractor`):
            An instance of [`MarkupLMFeatureExtractor`]. The feature extractor is a required input.
        tokenizer (`MarkupLMTokenizer` or `MarkupLMTokenizerFast`):
            An instance of [`MarkupLMTokenizer`] or [`MarkupLMTokenizerFast`]. The tokenizer is a required input.
        parse_html (`bool`, *optional*, defaults to `True`):
            Whether or not to use `MarkupLMFeatureExtractor` to parse HTML strings into nodes and corresponding xpaths.
    ÚMarkupLMFeatureExtractor)ÚMarkupLMTokenizerÚMarkupLMTokenizerFastTNFr   Úadd_special_tokensÚpaddingÚ
truncationÚ
max_lengthÚstrideÚpad_to_multiple_ofÚreturn_token_type_idsÚreturn_attention_maskÚreturn_overflowing_tokensÚreturn_special_tokens_maskÚreturn_offsets_mappingÚreturn_lengthÚverboseÚreturn_tensorsÚreturnc                 K   sž  | j r)|du rtdƒ‚|dus|dus|durtdƒ‚|  |¡}|d }|d }n|dur1tdƒ‚|du s9|du r=tdƒ‚|durL| j rLt|tƒrL|g}| jdi d|durW|n|“d	|dur`|n8d“d|“d
|“d|“d|“d|“d|	“d|
“d|“d|“d|“d|“d|“d|“d|“d|“d|“|¤Ž}|S “d|“d
|“d|“d|“d|“d|	“d|
“d|“d|“d|“d|“d|“d|“d|“d|“d|“|¤Ž}|S )aÆ  
        This method first forwards the `html_strings` argument to [`~MarkupLMFeatureExtractor.__call__`]. Next, it
        passes the `nodes` and `xpaths` along with the additional arguments to [`~MarkupLMTokenizer.__call__`] and
        returns the output.

        Optionally, one can also provide a `text` argument which is passed along as first sequence.

        Please refer to the docstring of the above two methods for more information.
        NzDMake sure to pass HTML strings in case `parse_html` is set to `True`zUPlease don't pass nodes, xpaths nor node labels in case `parse_html` is set to `True`ÚnodesÚxpathsz@You have passed HTML strings but `parse_html` is set to `False`.zIMake sure to pass nodes and xpaths in case `parse_html` is set to `False`ÚtextÚ	text_pairÚnode_labelsr   r   r   r   r   r   r   r   r   r   r   r   r   r   © )Ú
parse_htmlÚ
ValueErrorÚfeature_extractorÚ
isinstanceÚstrÚ	tokenizer)ÚselfÚhtml_stringsr   r   r!   Ú	questionsr   r   r   r   r   r   r   r   r   r   r   r   r   r   ÚkwargsÚfeaturesÚencoded_inputsr"   r"   úd/home/ubuntu/.local/lib/python3.10/site-packages/transformers/models/markuplm/processing_markuplm.pyÚ__call__2   sº   !ÿ



€ÿþýüûúùø	÷
öõôóòñðïíìþýüûúùø	÷
öõôóòñðïízMarkupLMProcessor.__call__)NNNNNTFNNr   NNNFFFFTN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úfeature_extractor_classÚtokenizer_classr#   Úboolr   r'   r   r	   r   Úintr   r   r0   r"   r"   r"   r/   r
      sn    ìùø	÷
öõôóòñðïîíìêr
   N)r4   Útypingr   r   Ú
file_utilsr   Úprocessing_utilsr   Útokenization_utils_baser   r   r	   r
   Ú__all__r"   r"   r"   r/   Ú<module>   s   
i