§
    ‚Štj8+  ã                   óÚ   — d dl mZmZ d dlZddlmZmZmZ ddl	m
Z
mZmZmZ  e¦   «         rd dlZ ej        e¦  «        Z e ed¬¦  «        d	¦  «         G d
„ de¦  «        ¦   «         ZdS )é    )ÚAnyÚoverloadNé   )Úadd_end_docstringsÚis_torch_availableÚloggingé   )ÚGenericTensorÚPipelineÚPipelineExceptionÚbuild_pipeline_init_argsT)Úhas_tokenizeraO  
        top_k (`int`, *optional*, defaults to 5):
            The number of predictions to return.
        targets (`str` or `list[str]`, *optional*):
            When passed, the model will limit the scores to the passed targets instead of looking up in the whole
            vocab. If the provided targets are not in the model vocab, they will be tokenized and the first resulting
            token will be used (with a warning, and that might be slower).
        tokenizer_kwargs (`dict`, *optional*):
            Additional dictionary of keyword arguments passed along to the tokenizer.c                   ó®  ‡ — e Zd ZdZdZdZdZ	 dedej	        fd„Z
dedej	        fd„Zdefd„Z	 ddeeef         fd
„Zd„ Zdd„Zd„ Zdd„Zedededeeeef                  fd„¦   «         Zedee         dedeeeeef                           fd„¦   «         Zdeee         z  dedeeeef                  eeeeef                           z  fˆ fd„Zˆ xZS )ÚFillMaskPipelineFTÚ	input_idsÚreturnc                 óN   — t          j        || j        j        k    d¬¦  «        }|S )NF©Úas_tuple)ÚtorchÚnonzeroÚ	tokenizerÚmask_token_id)Úselfr   Úmasked_indexs      ú^/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/transformers/pipelines/fill_mask.pyÚget_masked_indexz!FillMaskPipeline.get_masked_indexV   s'   € Ý”} Y°$´.Ô2NÒ%NÐY^Ð_Ñ_Ô_ˆØÐó    c                 óÀ   — |                       |¦  «        }t          j        |j        ¦  «        }|dk     r)t	          d| j        j        d| j        j        › d�¦  «        ‚d S )Nr	   ú	fill-maskzNo mask_token (z) found on the input)	r   ÚnpÚprodÚshaper   ÚmodelÚbase_model_prefixr   Ú
mask_token)r   r   r   Únumels       r   Ú_ensure_exactly_one_mask_tokenz/FillMaskPipeline._ensure_exactly_one_mask_tokenZ   sg   € Ø×,Ò,¨YÑ7Ô7ˆÝ”˜Ô*Ñ+Ô+ˆØ�1Š9ˆ9Ý#ØØ”
Ô,ØQ $¤.Ô";ÐQÐQÐQñô ð ð ˆ9r   Úmodel_inputsc                 óÀ   — t          |t          ¦  «        r(|D ]#}|                      |d         d         ¦  «         Œ$d S |d         D ]}|                      |¦  «         Œd S )Nr   r   )Ú
isinstanceÚlistr(   )r   r)   Úmodel_inputr   s       r   Úensure_exactly_one_mask_tokenz.FillMaskPipeline.ensure_exactly_one_mask_tokend   s‰   € Ý�l¥DÑ)Ô)ð 	?Ø+ð Qð Q�Ø×3Ò3°KÀÔ4LÈQÔ4OÑPÔPÐPÐPðQð Qð *¨+Ô6ð ?ð ?�	Ø×3Ò3°IÑ>Ô>Ð>Ð>ð?ð ?r   Nc                 ó`   — |€d}|€i } | j         |fd|i|¤Ž}|                      |¦  «         |S )NÚptÚreturn_tensors)r   r.   )r   Úinputsr1   Útokenizer_kwargsÚpreprocess_parametersr)   s         r   Ú
preprocesszFillMaskPipeline.preprocessl   sT   € ð Ð!Ø!ˆNØÐ#Ø!Ðà%�t”~ fÐ`Ð`¸^Ð`ÐO_Ð`Ð`ˆØ×*Ò*¨<Ñ8Ô8Ð8ØÐr   c                 ó6   —  | j         di |¤Ž}|d         |d<   |S )Nr   © )r$   )r   r)   Úmodel_outputss      r   Ú_forwardzFillMaskPipeline._forwardx   s.   € Ø"˜œ
Ð2Ð2 \Ð2Ð2ˆØ%1°+Ô%>ˆ�kÑ"ØÐr   é   c                 ó"  — |�|j         d         |k     r|j         d         }|d         d         }|d         }t          j        || j        j        k    d¬¦  «                             d¦  «        }|d|d d …f         }|                     d¬¦  «        }|�
|d|f         }|                     |¦  «        \  }	}
g }|	j         d         d	k    }t          t          |	 
                    ¦   «         |
 
                    ¦   «         ¦  «        ¦  «        D ]û\  }\  }}g }t          ||¦  «        D ]Ë\  }}|                     ¦   «                              ¦   «         }|�||          
                    ¦   «         }||||         <   |t          j        || j        j        k    ¦  «                 }| j                             ||¬
¦  «        }||| j                             |g¦  «        |dœ}|                     |¦  «         ŒÌ|                     |¦  «         Œü|r|d         S |S )Nr   r   ÚlogitsFr   éÿÿÿÿ)Údim.r	   )Úskip_special_tokens)ÚscoreÚtokenÚ	token_strÚsequence)r#   r   r   r   r   ÚsqueezeÚsoftmaxÚtopkÚ	enumerateÚzipÚtolistÚnumpyÚcopyr!   ÚwhereÚpad_token_idÚdecodeÚappend)r   r8   Útop_kÚ
target_idsr   Úoutputsr   r<   ÚprobsÚvaluesÚpredictionsÚresultÚsingle_maskÚiÚ_valuesÚ_predictionsÚrowÚvÚpÚtokensrC   Úpropositions                         r   ÚpostprocesszFillMaskPipeline.postprocess}   s  € àÐ! jÔ&6°qÔ&9¸EÒ&AÐ&AØÔ$ QÔ'ˆEØ! +Ô.¨qÔ1ˆ	Ø Ô)ˆå”} Y°$´.Ô2NÒ%NÐY^Ð_Ñ_Ô_×gÒgÐhjÑkÔkˆð ˜˜L¨!¨!¨!Ð+Ô,ˆØ—’ 2�Ñ&Ô&ˆØÐ!Ø˜#˜z˜/Ô*ˆEà#Ÿjšj¨Ñ/Ô/Ñˆ�àˆØ”l 1”o¨Ò*ˆÝ*3µC¸¿º¹¼È×I[ÒI[ÑI]ÔI]Ñ4^Ô4^Ñ*_Ô*_ð 	ð 	Ñ&ˆAÑ&�˜ØˆCÝ˜G \Ñ2Ô2ð (ð (‘��1à"ŸšÑ*Ô*×/Ò/Ñ1Ô1�ØÐ)Ø" 1œ×,Ò,Ñ.Ô.�Aà*+��| A”Ñ'à¥¤¨°4´>Ô3NÒ)NÑ OÔ OÔP�ð  œ>×0Ò0°È[Ð0ÑYÔY�Ø()°AÀDÄN×DYÒDYÐ[\ÐZ]ÑD^ÔD^ÐltÐuÐu�Ø—
’
˜;Ñ'Ô'Ð'Ð'Ø�MŠM˜#ÑÔÐÐØð 	Ø˜!”9ÐØˆr   c           	      óÂ  — t          |t          ¦  «        r|g}	 | j                             ¦   «         }n# t          $ r i }Y nw xY wg }|D ]Â}|                     |¦  «        }|€”|                      |ddddd¬¦  «        d         }t          |¦  «        dk    rt                               d|› d�¦  «         Œl|d         }t                               d|› d	| j         	                    |¦  «        › d
�¦  «         | 
                    |¦  «         ŒÃt          t          |¦  «        ¦  «        }t          |¦  «        dk    rt          d¦  «        ‚t          j        |¦  «        }|S )NFr	   T)Úadd_special_tokensÚreturn_attention_maskÚreturn_token_type_idsÚ
max_lengthÚ
truncationr   r   zThe specified target token `zd` does not exist in the model vocabulary. We cannot replace it with anything meaningful, ignoring itz:` does not exist in the model vocabulary. Replacing with `z`.z1At least one target must be provided when passed.)r+   Ústrr   Ú	get_vocabÚ	ExceptionÚgetÚlenÚloggerÚwarningÚconvert_ids_to_tokensrO   r,   ÚsetÚ
ValueErrorr!   Úarray)r   ÚtargetsÚvocabrQ   ÚtargetÚid_r   s          r   Úget_target_idszFillMaskPipeline.get_target_ids¦   sº  € Ý�g�sÑ#Ô#ð 	 Ø�iˆGð	Ø”N×,Ò,Ñ.Ô.ˆEˆEøÝð 	ð 	ð 	ØˆEˆEˆEð	øøøàˆ
Øð 	#ð 	#ˆFØ—)’)˜FÑ#Ô#ˆCØˆ{Ø ŸNšNØØ',Ø*/Ø*/Ø Ø#ð +ñ ô ð ô�	õ �y‘>”> QÒ&Ð&Ý—N’NðU°vð Uð Uð Uñô ð ð Ø ”l�õ
 —’ðU°6ð Uð UØ'+¤~×'KÒ'KÈCÑ'PÔ'PðUð Uð Uñô ð ð ×Ò˜cÑ"Ô"Ð"Ð"Ý�#˜j™/œ/Ñ*Ô*ˆ
Ýˆz‰?Œ?˜aÒÐÝÐPÑQÔQÐQÝ”X˜jÑ)Ô)ˆ
ØÐs   š4 ´AÁAc                 ó¶   — i }|�||d<   i }|�|                       |¦  «        }||d<   |�||d<   | j        j        €t          d| j        j        d¦  «        ‚|i |fS )Nr3   rQ   rP   r    z-The tokenizer does not define a `mask_token`.)rv   r   r   r   r$   r%   )r   rP   rr   r3   Úpreprocess_paramsÚpostprocess_paramsrQ   s          r   Ú_sanitize_parametersz%FillMaskPipeline._sanitize_parametersÏ   s�   € ØÐàÐ'Ø4DÐÐ0Ñ1àÐàÐØ×,Ò,¨WÑ5Ô5ˆJØ/9Ð˜|Ñ,àÐØ*/Ð˜wÑ'àŒ>Ô'Ð/Ý#Ø˜TœZÔ9Ð;jñô ð ð ! "Ð&8Ð8Ð8r   r2   Úkwargsc                 ó   — d S ©Nr7   ©r   r2   r{   s      r   Ú__call__zFillMaskPipeline.__call__ä   s   € ØLOÈCr   c                 ó   — d S r}   r7   r~   s      r   r   zFillMaskPipeline.__call__ç   s   € ØX[ÐX[r   c                 óœ   •—  t          ¦   «         j        |fi |¤Ž}t          |t          ¦  «        rt	          |¦  «        dk    r|d         S |S )a“  
        Fill the masked token in the text(s) given as inputs.

        Args:
            inputs (`str` or `list[str]`):
                One or several texts (or one list of prompts) with masked tokens.
            targets (`str` or `list[str]`, *optional*):
                When passed, the model will limit the scores to the passed targets instead of looking up in the whole
                vocab. If the provided targets are not in the model vocab, they will be tokenized and the first
                resulting token will be used (with a warning, and that might be slower).
            top_k (`int`, *optional*):
                When passed, overrides the number of predictions to return.

        Return:
            A list or a list of list of `dict`: Each result comes as list of dictionaries with the following keys:

            - **sequence** (`str`) -- The corresponding input with the mask token prediction.
            - **score** (`float`) -- The corresponding probability.
            - **token** (`int`) -- The predicted token id (to replace the masked one).
            - **token_str** (`str`) -- The predicted token (to replace the masked one).
        r	   r   )Úsuperr   r+   r,   rk   )r   r2   r{   rR   Ú	__class__s       €r   r   zFillMaskPipeline.__call__ê   sT   ø€ ð, #•%‘'”'Ô" 6Ð4Ð4¨VÐ4Ð4ˆÝ�f�dÑ#Ô#ð 	­¨F©¬°qÒ(8Ð(8Ø˜1”:ÐØˆr   )NN)r:   N)NNN)Ú__name__Ú
__module__Ú__qualname__Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr
   r!   Úndarrayr   r(   r.   Údictrg   r5   r9   r`   rv   rz   r   r   r,   r   Ú__classcell__)rƒ   s   @r   r   r      sð  ø€ € € € € ð €OØ!ÐØ#ÐØ€Oð2ðh¨-ð ¸B¼Jð ð ð ð ð¸ð È"Ì*ð ð ð ð ð?¸-ð ?ð ?ð ?ð ?ð =Að
ð 
à	ˆc�=Ð Ô	!ð
ð 
ð 
ð 
ðð ð ð
'ð 'ð 'ð 'ðR'ð 'ð 'ðR9ð 9ð 9ð 9ð* ØO˜sÐO¨cÐO°d¸4ÀÀSÀ¼>Ô6JÐOÐOÐOñ „XØOàØ[˜t CœyÐ[°CÐ[¸DÀÀdÈ3ÐPSÈ8ÄnÔAUÔ<VÐ[Ð[Ð[ñ „XØ[ð˜s T¨#¤Y™ð ¸#ð À$ÀtÈCÐQTÈHÄ~ÔBVÐY]Ð^bÐcgÐhkÐmpÐhpÔcqÔ^rÔYsÑBsð ð ð ð ð ð ð ð ð ð r   r   )Útypingr   r   rJ   r!   Úutilsr   r   r   Úbaser
   r   r   r   r   Ú
get_loggerr„   rl   r   r7   r   r   ú<module>r’      s  ðØ  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à Ð Ð Ð à CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ Vð ÐÑÔð Ø€L€L€Lð 
ˆÔ	˜HÑ	%Ô	%€ð ÐØÐ¨4Ð0Ñ0Ô0ðYñô ðgð gð gð gð g�xñ gô gñô ðgð gð gr   