Ë
    T^(hp$  ã                   ó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 LayoutLMv2.
é    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 )#ÚLayoutLMv2Processorax  
    Constructs a LayoutLMv2 processor which combines a LayoutLMv2 image processor and a LayoutLMv2 tokenizer into a
    single processor.

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

    It first uses [`LayoutLMv2ImageProcessor`] to resize document images to a fixed size, and optionally applies OCR to
    get words and normalized bounding boxes. These are then provided to [`LayoutLMv2Tokenizer`] or
    [`LayoutLMv2TokenizerFast`], 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 (`LayoutLMv2ImageProcessor`, *optional*):
            An instance of [`LayoutLMv2ImageProcessor`]. The image processor is a required input.
        tokenizer (`LayoutLMv2Tokenizer` or `LayoutLMv2TokenizerFast`, *optional*):
            An instance of [`LayoutLMv2Tokenizer`] or [`LayoutLMv2TokenizerFast`]. The tokenizer is a required input.
    Úimage_processorÚ	tokenizerÚLayoutLMv2ImageProcessor)ÚLayoutLMv2TokenizerÚLayoutLMv2TokenizerFastc                 óÈ   •— 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/layoutlmv2/processing_layoutlmv2.pyr   zLayoutLMv2Processor.__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                 óT  — | j                   j                  r|�t        d«      ‚| j                   j                  r|�t        d«      ‚|du r|du 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 )a  
        This method first forwards the `images` argument to [`~LayoutLMv2ImageProcessor.__call__`]. In case
        [`LayoutLMv2ImageProcessor`] was initialized with `apply_ocr` set to `True`, it passes the obtained words and
        bounding boxes along with the additional arguments to [`~LayoutLMv2Tokenizer.__call__`] and returns the output,
        together with resized `images`. In case [`LayoutLMv2ImageProcessor`] 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 [`~LayoutLMv2Tokenizer.__call__`] and returns the output, together with resized `images``.

        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.TFzKYou cannot return overflowing tokens without returning the offsets mapping.)Úimagesr4   Úwordsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   Úpixel_valuesÚoverflow_to_sample_mappingÚimage© )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LayoutLMv2Processor.__call__E   sá  € ðD ×Ñ×)Ò)¨uÐ/@ÜØvóð ð ×Ñ×)Ò)¨{Ð/FÜØsóð ð %¨Ñ,Ð1GÈ5Ñ1PÜÐjÓkÐkð ×'Ñ'¨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Ø"(ˆ�wÑàÐ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*LayoutLMv2Processor.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!   rJ   z LayoutLMv2Processor.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   ÚdecoderK   s      r!   rN   zLayoutLMv2Processor.decode°   s    € ð
 %ˆt�~‰~×$Ñ$ dÐ5¨fÑ5Ð5r"   c                 ó
   — g d¢S )N)Ú	input_idsÚbboxÚtoken_type_idsÚattention_maskr;   r<   ©r   s    r!   Úmodel_input_namesz%LayoutLMv2Processor.model_input_names·   s   € âQÐQr"   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_classrT   s    r!   Úfeature_extractor_classz+LayoutLMv2Processor.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   rT   s    r!   r   z%LayoutLMv2Processor.feature_extractorÃ   s"   € ä�‰ØiÜô	
ð ×#Ñ#Ð#r"   )NN)NNNNTFFNr   NNNFFFFTN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
attributesrW   Útokenizer_classr   r   r   r
   r   r   ÚintÚboolr?   r	   r   r   r   rC   r@   rJ   rN   ÚpropertyrU   rX   r   Ú__classcell__)r    s   @r!   r   r      s#  ø„ ñð& $ [Ð1€JØ6ÐØH€Oõ5ð* _cØQUØ?CØCGØ#'Ø5:Ø;@Ø$(ØØ,0Ø04Ø04Ø*/Ø+0Ø',Ø#ØØ;?ñ)Tð �IÐ0°$°y±/À4ÐHYÑCZÐZÑ[ðTð ˜EÐ"3°TÐ:KÑ5LÐ"LÑMÑNð	Tð
 �T˜$˜s™)‘_ d¨4°°S±	©?Ñ&;Ð;Ñ<ðTð ˜e D¨¡I¨t°D¸±I©Ð$>Ñ?Ñ@ðTð !ðTð �t˜S /Ð1Ñ2ðTð ˜$ Ð%7Ð7Ñ8ðTð ˜S‘MðTð ðTð % S™MðTð  (¨™~ðTð  (¨™~ðTð $(ðTð  %)ð!Tð" !%ð#Tð$ ð%Tð& ð'Tð( !  s¨J Ñ!7Ñ8ð)Tð, 
ó-Tòl$ò<ò6ð ñRó ðRð ñ*ó ð*ð ñ$ó ô$r"   r   )r]   r   Útypingr   r   r   Úprocessing_utilsr   Útokenization_utils_baser   r	   r
   r   r   Úutilsr   r   Ú__all__r<   r"   r!   ú<module>ri      s:   ðñó ß (Ñ (å .ß wÕ wÝ ôn$˜.ô n$ðb !Ð
!�r"   