Ë
    ÜÓ^jì  ã                   óÞ   — d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlmZmZ ddlmZ  ej"                  e«      Z G d	„ d
e
d¬«      Z G d„ ded¬«      Ze G d„ de	«      «       ZdgZy)z
Processor class for UDOP.
é    )Úloggingé   )ÚBatchFeature)Ú
ImageInput)ÚProcessingKwargsÚProcessorMixinÚ
TextKwargsÚUnpack)ÚPreTokenizedInputÚ	TextInput)Úauto_docstringc                   ój   — e Zd ZU ee   eee      z  dz  ed<   eee      eeee         z  dz  ed<   y)ÚUdopTextKwargsNÚword_labelsÚboxes)Ú__name__Ú
__module__Ú__qualname__ÚlistÚintÚ__annotations__© ó    ús/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/udop/processing_udop.pyr   r      sC   … Ø�c‘˜T $ s¡)™_Ñ,¨tÑ3Ó3Ø��S‘	‰?˜T $ t¨C¡y¡/Ñ2Ñ2°TÑ9Ô9r   r   F)Útotalc                   ó4   — e Zd ZU eed<   dddddddddddœ	iZy)ÚUdopProcessorKwargsÚtext_kwargsTFr   )	Úadd_special_tokensÚpaddingÚ
truncationÚstrideÚreturn_overflowing_tokensÚreturn_special_tokens_maskÚreturn_offsets_mappingÚreturn_lengthÚverboseN)r   r   r   r   r   Ú	_defaultsr   r   r   r   r   #   s2   … ØÓàØ"&ØØØØ).Ø*/Ø&+Ø"Øñ

ð�Ir   r   c            
       óŠ   ‡ — e Zd ZdZˆ fd„Ze	 	 ddedz  deez  e	e   z  e	e   z  de
e   defd„«       Zd	„ Zed
„ «       Zˆ xZS )ÚUdopProcessoras  
    Constructs a UDOP processor which combines a LayoutLMv3 image processor and a UDOP tokenizer into a single processor.

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

    It first uses [`LayoutLMv3ImageProcessor`] to resize, rescale and normalize document images, and optionally applies OCR
    to get words and normalized bounding boxes. These are then provided to [`UdopTokenizer`],
    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).

    Additionally, it also supports passing `text_target` and `text_pair_target` to the tokenizer, which can be used to
    prepare labels for language modeling tasks.
    c                 ó&   •— t         ‰| �  ||«       y )N)ÚsuperÚ__init__)ÚselfÚimage_processorÚ	tokenizerÚ	__class__s      €r   r-   zUdopProcessor.__init__E   s   ø€ Ü‰Ñ˜¨)Õ4r   NÚimagesÚtextÚkwargsÚreturnc                 ó6  —  | j                   t        fd| j                  j                  i|¤Ž}|d   j	                  dd «      }|d   j	                  dd «      }|d   j	                  dd «      }|d   j                  dd«      }|d   j                  dd«      }	|d   j                  d	d «      }
| j                  j                  r|�t        d
«      ‚| j                  j                  r|�t        d«      ‚|r|	st        d«      ‚|
� | j                  di |d   ¤ŽS  | j                  dd|i|d   ¤Ž}|j	                  dd «      }|j	                  dd «      }|d   j	                  d	d «       |d   j	                  dd «       ||d   d<   |�|n||d   d<   ||d   d<   |�3| j                  j                  r|€t        |t        «      r|g}||d   d<    | j                  dd|�|n|i|d   ¤Ž}|du r| j                  |d   |d   «      |d<   |j                  |«       |S )NÚtokenizer_init_kwargsr   r   r   Ú	text_pairr#   Fr%   Útext_targetzdYou 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.zKYou cannot return overflowing tokens without returning the offsets mapping.r2   Úimages_kwargsÚwordsÚtext_pair_targetr3   TÚpixel_valuesÚoverflow_to_sample_mappingr   )Ú_merge_kwargsr   r0   Úinit_kwargsÚpopÚgetr/   Ú	apply_ocrÚ
ValueErrorÚ
isinstanceÚstrÚget_overflowing_imagesÚupdate)r.   r2   r3   r4   Úoutput_kwargsr   r   r8   r#   r%   r9   ÚfeaturesÚfeatures_wordsÚfeatures_boxesÚencoded_inputss                  r   Ú__call__zUdopProcessor.__call__H   s•  € ð +˜×*Ñ*Üñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð ˜mÑ,×0Ñ0°¸$Ó?ˆØ# MÑ2×6Ñ6°}ÀdÓKˆØ! -Ñ0×4Ñ4°[À$ÓGˆ	Ø$1°-Ñ$@×$DÑ$DÐE`ÐbgÓ$hÐ!Ø!.¨}Ñ!=×!AÑ!AÐBZÐ\aÓ!bÐØ# MÑ2×6Ñ6°}ÀdÓKˆà×Ñ×)Ò)¨uÐ/@ÜØvóð ð ×Ñ×)Ò)¨{Ð/FÜØsóð ñ %Ñ-CÜÐjÓkÐkàÐ"à!�4—>‘>ñ Ø Ñ.ñð ð ,�t×+Ñ+Ñ\°6Ð\¸]È?Ñ=[Ñ\ˆHØ%Ÿ\™\¨'°4Ó8ˆNØ%Ÿ\™\¨'°4Ó8ˆNà˜-Ñ(×,Ñ,¨]¸DÔAØ˜-Ñ(×,Ñ,Ð-?ÀÔFØ8AˆM˜-Ñ(¨Ñ5Ø=BÐ=N±EÐTbˆM˜-Ñ(¨Ñ1Ø:EˆM˜-Ñ(¨Ñ7ð Ð D×$8Ñ$8×$BÒ$BÀyÐGXÜ˜d¤CÔ(Ø ˜6�DØ<J�˜mÑ,¨[Ñ9à+˜TŸ^™^ñ Ø!Ð-‘T°>ðà Ñ.ñˆNð )¨DÑ0Ø+/×+FÑ+FØ˜^Ñ,¨nÐ=YÑ.Zó,�˜Ñ(ð �O‰O˜NÔ+àˆOr   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ÚlenrD   )r.   r2   r>   Úimages_with_overflowÚ
sample_idxs        r   rG   z$UdopProcessor.get_overflowing_images’   sy   € à!ÐØ4ò 	<ˆJØ ×'Ñ'¨¨zÑ(:Õ;ð	<ô Ð#Ó$¬Ð,FÓ(GÒGÜðÜÐ,Ó-Ð.¨e´CÐ8RÓ4SÐ3TðVóð ð
 $Ð#r   c                 ó~   — | j                   j                  }| j                  j                  }t        ||z   dgz   «      S )NÚbbox)r0   Úmodel_input_namesr/   r   )r.   Útokenizer_input_namesÚimage_processor_input_namess      r   rV   zUdopProcessor.model_input_names    s=   € à $§¡× @Ñ @ÐØ&*×&:Ñ&:×&LÑ&LÐ#äÐ)Ð,GÑGÈ6È(ÑRÓSÐSr   )NN)r   r   r   Ú__doc__r-   r   r   r   r   r   r
   r   r   rN   rG   ÚpropertyrV   Ú__classcell__)r1   s   @r   r*   r*   4   s–   ø„ ñô5ð ð %)ØZ^ñFà˜TÑ!ðFð Ð+Ñ+¨d°9©oÑ=ÀÐEVÑ@WÑWðFð Ð,Ñ-ð	Fð
 
òFó ðFòR$ð ñTó ôTr   r*   N)rY   Útransformersr   Úimage_processing_utilsr   Úimage_utilsr   Úprocessing_utilsr   r   r	   r
   Útokenization_utils_baser   r   Úutilsr   Ú
get_loggerr   Úloggerr   r   r*   Ú__all__r   r   r   ú<module>re      s~   ðñõ !å 2Ý %ß TÓ Tß CÝ #ð 
ˆ×	Ñ	˜HÓ	%€ô:�Z uõ :ô
Ð*°%õ ð" ôpT�Nó pTó ðpTðf Ð
�r   