a
    ½Àhý  ã                   @   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                   @   sx   e Zd ZdZdZdZdZdeeee	e
f eee	ef ee eee ee ee eeeeeeee	ef  edœ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.
    ZMarkupLMFeatureExtractor)ZMarkupLMTokenizerZ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 rR|du rtdƒ‚|dus.|dus.|dur6tdƒ‚|  |¡}|d }|d }n(|durbtdƒ‚|du sr|du rztdƒ‚|dur˜| j r˜t|tƒr˜|g}| jf |durª|n||dur¸|n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`)ÚtextZ	text_pairr   Únode_labelsr   r   r   r   r   r   r   r   r   r   r   r   r   r   )Ú
parse_htmlÚ
ValueErrorZfeature_extractorÚ
isinstanceÚstrÚ	tokenizer)ÚselfZhtml_stringsr   r   r   Z	questionsr   r   r   r   r   r   r   r   r   r   r   r   r   r   ÚkwargsÚfeaturesZencoded_inputs© r&   úl/var/www/html/assistant/venv/lib/python3.9/site-packages/transformers/models/markuplm/processing_markuplm.pyÚ__call__2   sP    !ÿ


îízMarkupLMProcessor.__call__)NNNNNTFNNr   NNNFFFFTN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Zfeature_extractor_classZtokenizer_classr   Úboolr   r!   r   r	   r   Úintr   r   r(   r&   r&   r&   r'   r
      sP                      ìêr
   N)r,   Útypingr   r   Z
file_utilsr   Zprocessing_utilsr   Ztokenization_utils_baser   r   r	   r
   Ú__all__r&   r&   r&   r'   Ú<module>   s   i