
    9i0                     <   S SK JrJrJrJr  S SKrS SKJr  S SK	J
r
  S SKJr  S SKJrJr  S SKJr  S SKJr  S S	KJrJr  S
/r\R0                  " \R2                  \R2                  S9\R0                  " \R2                  \R4                  S9 " S S
\5      5       5       rg)    )AnyDictOptionalUnionN)	Pipelines)Model)
OutputKeys)PipelineTensor)	PIPELINES)Preprocessor)	ModelFileTasksFillMaskPipeline)module_namec            	          ^  \ rS rSr      SS\\\4   S\\   S\S\4U 4S jjjr	S\
\\4   S\
\\4   4S	 jrS\
\\4   S\
\\4   4S
 jrSrU =r$ )r      modelpreprocessorconfig_filedevicec                   > [         T	U ]  UUUUUUR                  SS5      UR                  S0 5      S9  [        U R                  [
        5      (       d   S[        R                   35       eUc3  [        R                  " U R                  R                  4UUS.UD6U l        U R                  R                  5         [        U R                  S5      (       d   S	5       eg)
a  The inference pipeline for all the fill mask sub-tasks.

Args:
    model (`str` or `Model` or module instance): A model instance or a model local dir
        or a model id in the model hub.
    preprocessor (`Preprocessor`, `optional`): A Preprocessor instance.
    kwargs (dict, `optional`):
        Extra kwargs passed into the preprocessor's constructor.

Examples:

>>> from modelscope.pipelines import pipeline
>>> pipeline_ins = pipeline('fill-mask', model='damo/nlp_structbert_fill-mask_english-large')
>>> input = 'Everything in [MASK] you call reality is really [MASK] a reflection of your [MASK].'
>>> print(pipeline_ins(input))

Examples:

>>> from modelscope.pipelines import pipeline
>>> pipeline_ins = pipeline('fill-mask', model='damo/nlp_ponet_fill-mask_english-base')
>>> input = 'Everything in [MASK] you call reality is really [MASK] a reflection of your [MASK].'
>>> print(pipeline_ins(input))

NOTE2: Please pay attention to the model's special tokens.
If bert based model(bert, structbert, etc.) is used, the mask token is '[MASK]'.
If the xlm-roberta(xlm-roberta, veco, etc.) based model is used, the mask token is '<mask>'.
To view other examples please check tests/pipelines/test_fill_mask.py.
compileFcompile_options)r   r   r   r   auto_collater   r   z,please check whether model config exists in N)first_sequencesequence_lengthmask_idz9The input preprocessor should have the mask_id attribute.)super__init__pop
isinstancer   r   r   CONFIGURATIONr   from_pretrained	model_dirr   evalhasattr)
selfr   r   r   r   r   r   r   kwargs	__class__s
            k/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/nlp/fill_mask_pipeline.pyr    FillMaskPipeline.__init__   s    J 	%#%JJy%0"JJ'8"= 	 	? $**e,, 	U:9;R;R:ST	U, , < <

$$!- /! 	!D
 	

y
 
 	GF	G 
    inputsreturnc                 *    U R                   " S0 UDUD6$ )N )r   )r(   r.   forward_paramss      r+   forwardFillMaskPipeline.forwardR   s    zz5F5n55r-   c                    U[         R                     R                  5       R                  5       R	                  5       nU[         R
                     R                  5       R                  5       R	                  5       n[        R                  " USS9n[        R                  " X0R                  R                  :H  UU5      n/ nU H/  nU R                  R                  USSS9nUR                  U5        M1     [         R                  U0$ )a  process the prediction results

Args:
    inputs (Dict[str, Any]): The model outputs.
    The output should follow some rules:
        1. Values can be retrieved by keys(dict-like, or the __getitem__ method is overriden)
        2. 'logits' and 'input_ids' key exists.
    Models in modelscope will return the output dataclass `modelscope.outputs.FillMaskModelOutput`.
Returns:
    Dict[str, str]: the prediction results
)axisT)skip_special_tokensclean_up_tokenization_spaces)r	   LOGITSdetachcpunumpy	INPUT_IDSnpargmaxwherer   r   decodeappendTEXT)	r(   r.   logits	input_idspred_idsrst_idspred_stringsidspred_strings	            r+   postprocessFillMaskPipeline.postprocessV   s     
))*113779??A://0779==?EEG	99V"-((9(9(9(A(AA8$& C++22$(-1 3 3K ,  ..r-   )r   )NNgpuTsentence   )__name__
__module____qualname____firstlineno__r   r   strr   r   r    r   r   r3   r   rL   __static_attributes____classcell__)r*   s   @r+   r   r      s     9=$($" *!$9GeSj)9G'59G "9G 	9G 9Gv6d38n 6%)#s(^6/$sF{"3 /S&[8I / /r-   )typingr   r   r   r   r=   r?   modelscope.metainfor   modelscope.modelsr   modelscope.outputsr	   modelscope.pipelines.baser
   r   modelscope.pipelines.builderr   modelscope.preprocessorsr   modelscope.utils.constantr   r   __all__register_module	fill_maskfill_mask_ponetr   r1   r-   r+   <module>rd      s    . -  ) # ) 6 2 1 6
 5??	8K8KL
	OO!:!:<[/x [/< M[/r-   