U
    ,-e                     @   sh   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	 d	eZdS )
z
Processor class for ViLT.
    N)ListOptionalUnion   )ProcessorMixin)BatchEncodingPaddingStrategyPreTokenizedInput	TextInputTruncationStrategy)
TensorTypec                       s   e Zd ZdZddgZdZdZd fdd	Zdee	e
ee	 ee
 f 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d Zdd Zedd Zedd Zedd Z  ZS )ViltProcessora]  
    Constructs a ViLT processor which wraps a BERT tokenizer and ViLT image processor into a single processor.

    [`ViltProcessor`] offers all the functionalities of [`ViltImageProcessor`] and [`BertTokenizerFast`]. See the
    docstring of [`~ViltProcessor.__call__`] and [`~ViltProcessor.decode`] for more information.

    Args:
        image_processor (`ViltImageProcessor`):
            An instance of [`ViltImageProcessor`]. The image processor is a required input.
        tokenizer (`BertTokenizerFast`):
            An instance of ['BertTokenizerFast`]. The tokenizer is a required input.
    image_processor	tokenizerZViltImageProcessor)ZBertTokenizerZBertTokenizerFastNc                    sl   d }d|kr"t dt |d}|d k	r.|n|}|d krBtd|d krRtdt || | j| _d S )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__r   Zcurrent_processor)selfr   r   kwargsr   	__class__ i/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/transformers/models/vilt/processing_vilt.pyr   ,   s    
zViltProcessor.__init__TFr   )text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   sL   | j f ||||||||	|
||||||d|}| j||d}|| |S )a  
        This method uses [`ViltImageProcessor.__call__`] method to prepare image(s) for the model, and
        [`BertTokenizerFast.__call__`] to prepare text for the model.

        Please refer to the docstring of the above two methods for more information.
        )r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   )r,   )r   r   update)r   Zimagesr   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r   encodingZencoding_image_processorr   r   r   __call__?   s,    
zViltProcessor.__call__c                 O   s   | j j||S )z
        This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r   batch_decoder   argsr   r   r   r   r1   q   s    zViltProcessor.batch_decodec                 O   s   | j j||S )z
        This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r   decoder2   r   r   r   r4   x   s    zViltProcessor.decodec                 C   s"   | j j}| jj}tt|| S )N)r   model_input_namesr   listdictfromkeys)r   Ztokenizer_input_namesZimage_processor_input_namesr   r   r   r5      s    zViltProcessor.model_input_namesc                 C   s   t 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_classr   r   r   r   feature_extractor_class   s
    z%ViltProcessor.feature_extractor_classc                 C   s   t dt | jS )Nz[`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.)r   r   r   r   r:   r   r   r   r      s
    zViltProcessor.feature_extractor)NN)NTFNNr   NNNFFFFTN)__name__
__module____qualname____doc__
attributesr9   Ztokenizer_classr   r   r
   r	   r   boolstrr   r   r   intr   r   r0   r1   r4   propertyr5   r;   r   __classcell__r   r   r   r   r      s\                  2

r   )r?   r   typingr   r   r   Zprocessing_utilsr   Ztokenization_utils_baser   r   r	   r
   r   utilsr   r   r   r   r   r   <module>   s   