Ë
    T^(hÛ#  ã                   ót   — d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	m
Z
mZmZmZ ddlmZ  G d„ d	e«      Zd	gZy)
z!
Processor class for LayoutLMv3.
é    N)ÚListÚOptionalÚUnioné   )ÚProcessorMixin)ÚBatchEncodingÚPaddingStrategyÚPreTokenizedInputÚ	TextInputÚTruncationStrategy)Ú
TensorTypec            (       óª  ‡ — e Zd ZdZddgZdZdZd!ˆ fd„	Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"d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   dedededededeeeef      def&d„Zd„ Zd„ Zd„ Zed„ «       Zed„ «       Zed „ «       Zˆ xZS )#ÚLayoutLMv3Processorav  
    Constructs a LayoutLMv3 processor which combines a LayoutLMv3 image processor and a LayoutLMv3 tokenizer into a
    single processor.

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

    It first uses [`LayoutLMv3ImageProcessor`] to resize and normalize document images, and optionally applies OCR to
    get words and normalized bounding boxes. These are then provided to [`LayoutLMv3Tokenizer`] or
    [`LayoutLMv3TokenizerFast`], which turns the words and bounding boxes into token-level `input_ids`,
    `attention_mask`, `token_type_ids`, `bbox`. Optionally, one can provide integer `word_labels`, which are turned
    into token-level `labels` for token classification tasks (such as FUNSD, CORD).

    Args:
        image_processor (`LayoutLMv3ImageProcessor`, *optional*):
            An instance of [`LayoutLMv3ImageProcessor`]. The image processor is a required input.
        tokenizer (`LayoutLMv3Tokenizer` or `LayoutLMv3TokenizerFast`, *optional*):
            An instance of [`LayoutLMv3Tokenizer`] or [`LayoutLMv3TokenizerFast`]. The tokenizer is a required input.
    Úimage_processorÚ	tokenizerÚLayoutLMv3ImageProcessor)ÚLayoutLMv3TokenizerÚLayoutLMv3TokenizerFastc                 óÈ   •— d }d|v r+t        j                  dt        «       |j                  d«      }|�|n|}|€t	        d«      ‚|€t	        d«      ‚t
        ‰| �  ||«       y )NÚfeature_extractorzhThe `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor` instead.z)You need to specify an `image_processor`.z"You need to specify a `tokenizer`.)ÚwarningsÚwarnÚFutureWarningÚpopÚ
ValueErrorÚsuperÚ__init__)Úselfr   r   Úkwargsr   Ú	__class__s        €úr/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/layoutlmv3/processing_layoutlmv3.pyr   zLayoutLMv3Processor.__init__3   sw   ø€ Ø ÐØ &Ñ(Ü�M‰Mðäôð
 !'§
¡
Ð+>Ó ?Ðà-<Ð-H™/ÐN_ˆØÐ"ÜÐHÓIÐIØÐÜÐAÓBÐBä‰Ñ˜¨)Õ4ó    ÚtextÚ	text_pairÚboxesÚword_labelsÚ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                 ó.  — | j                   j                  r|�t        d«      ‚| j                   j                  r|�t        d«      ‚| j                  ||¬«      }|�0| j                   j                  r|€t        |t        «      r|g}|d   } | j
                  di d|�|n|d   “d|�|nd“d|�|n|d   “d	|“d
|“d|“d|“d|	“d|
“d|“d|“d|“d|“d|“d|“d|“d|“d|“|¤Ž}|j                  d«      }|du r| j                  ||d   «      }||d<   |S )aF  
        This method first forwards the `images` argument to [`~LayoutLMv3ImageProcessor.__call__`]. In case
        [`LayoutLMv3ImageProcessor`] was initialized with `apply_ocr` set to `True`, it passes the obtained words and
        bounding boxes along with the additional arguments to [`~LayoutLMv3Tokenizer.__call__`] and returns the output,
        together with resized and normalized `pixel_values`. In case [`LayoutLMv3ImageProcessor`] was initialized with
        `apply_ocr` set to `False`, it passes the words (`text`/``text_pair`) and `boxes` specified by the user along
        with the additional arguments to [`~LayoutLMv3Tokenizer.__call__`] and returns the output, together with
        resized and normalized `pixel_values`.

        Please refer to the docstring of the above two methods for more information.
        NzdYou cannot provide bounding boxes if you initialized the image processor with apply_ocr set to True.zaYou cannot provide word labels if you initialized the image processor with apply_ocr set to True.)Úimagesr4   Úwordsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   Úpixel_valuesTÚoverflow_to_sample_mapping© )r   Ú	apply_ocrr   Ú
isinstanceÚstrr   r   Úget_overflowing_images)r   r7   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r   ÚfeaturesÚencoded_inputss                          r!   Ú__call__zLayoutLMv3Processor.__call__E   sÃ  € ðF ×Ñ×)Ò)¨uÐ/@ÜØvóð ð ×Ñ×)Ò)¨{Ð/FÜØsóð ð
 ×'Ñ'¨vÀnÐ'ÓUˆð Ð × 4Ñ 4× >Ò >À9ÐCTÜ˜$¤Ô$Ø�v�Ø  Ñ)ˆIà'˜Ÿ™ò 
ØÐ)‘¨x¸Ñ/@øð
à#,Ð#8‘i¸døð
ð !Ð,‘%°(¸7Ñ2Cøð
ñ $ð	
ñ
  2ð
ñ ð
ñ "ð
ñ "ð
ñ ð
ñ  2ð
ñ #8ð
ñ #8ð
ñ '@ð
ñ (Bð
ñ $:ð
ñ  (ð!
ñ" ð#
ñ$ *Øñ'
ˆð. —‘˜nÓ-ˆØ$¨Ñ,Ø×0Ñ0°¸ÐHdÑ9eÓfˆFØ)/ˆ�~Ñ&àÐr"   c                 ó´   — g }|D ]  }|j                  ||   «       Œ t        |«      t        |«      k7  r#t        dt        |«      › dt        |«      › �«      ‚|S )Nz`Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got z and )ÚappendÚlenr   )r   r7   r:   Úimages_with_overflowÚ
sample_idxs        r!   r?   z*LayoutLMv3Processor.get_overflowing_images™   sy   € à!ÐØ4ò 	<ˆJØ ×'Ñ'¨¨zÑ(:Õ;ð	<ô Ð#Ó$¬Ð,FÓ(GÒGÜðÜÐ,Ó-Ð.¨e´CÐ8RÓ4SÐ3TðVóð ð
 $Ð#r"   c                 ó:   —  | j                   j                  |i |¤ŽS )zÃ
        This method forwards all its arguments to PreTrainedTokenizer's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r   Úbatch_decode©r   Úargsr   s      r!   rI   z LayoutLMv3Processor.batch_decode§   s    € ð
 +ˆt�~‰~×*Ñ*¨DÐ;°FÑ;Ð;r"   c                 ó:   —  | j                   j                  |i |¤ŽS )z½
        This method forwards all its arguments to PreTrainedTokenizer's [`~PreTrainedTokenizer.decode`]. Please refer
        to the docstring of this method for more information.
        )r   ÚdecoderJ   s      r!   rM   zLayoutLMv3Processor.decode®   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r"   c                 ó
   — g d¢S )N)Ú	input_idsÚbboxÚattention_maskr9   r;   ©r   s    r!   Úmodel_input_namesz%LayoutLMv3Processor.model_input_namesµ   s   € âFÐFr"   c                 óN   — t        j                  dt        «       | j                  S )Nzg`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.)r   r   r   Úimage_processor_classrR   s    r!   Úfeature_extractor_classz+LayoutLMv3Processor.feature_extractor_class¹   s"   € ä�‰ØuÜô	
ð ×)Ñ)Ð)r"   c                 óN   — t        j                  dt        «       | j                  S )Nz[`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.)r   r   r   r   rR   s    r!   r   z%LayoutLMv3Processor.feature_extractorÁ   s"   € ä�‰ØiÜô	
ð ×#Ñ#Ð#r"   )NN)NNNNTFNNr   NNNFFFFTN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
attributesrU   Útokenizer_classr   r   r   r
   r   r   ÚintÚboolr>   r	   r   r   r   rB   r?   rI   rM   ÚpropertyrS   rV   r   Ú__classcell__)r    s   @r!   r   r      s#  ø„ ñð& $ [Ð1€JØ6ÐØH€Oõ5ð* _cØQUØ?CØCGØ#'Ø5:Ø;?Ø$(ØØ,0Ø04Ø04Ø*/Ø+0Ø',Ø#ØØ;?ñ)Rð �IÐ0°$°y±/À4ÐHYÑCZÐZÑ[ðRð ˜EÐ"3°TÐ:KÑ5LÐ"LÑMÑNð	Rð
 �T˜$˜s™)‘_ d¨4°°S±	©?Ñ&;Ð;Ñ<ðRð ˜e D¨¡I¨t°D¸±I©Ð$>Ñ?Ñ@ðRð !ðRð �t˜S /Ð1Ñ2ðRð ˜$ Ð%7Ð7Ñ8ðRð ˜S‘MðRð ðRð % S™MðRð  (¨™~ðRð  (¨™~ðRð $(ðRð  %)ð!Rð" !%ð#Rð$ ð%Rð& ð'Rð( !  s¨J Ñ!7Ñ8ð)Rð, 
ó-Ròh$ò<ò6ð ñGó ðGð ñ*ó ð*ð ñ$ó ô$r"   r   )r[   r   Útypingr   r   r   Úprocessing_utilsr   Útokenization_utils_baser   r	   r
   r   r   Úutilsr   r   Ú__all__r;   r"   r!   ú<module>rg      s:   ðñó ß (Ñ (å .ß wÕ wÝ ôl$˜.ô l$ð^ !Ð
!�r"   