o
    *j
                     @   s   d dl mZmZmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d
gZejejejdG dd
 d
eZdS )    )AnyDictOptionalUnionN)	Pipelines)Model)
OutputKeys)Pipeline)	PIPELINES)WordAlignmentPreprocessor)TasksWordAlignmentPipeline)module_namec                	       s   e Zd Z					ddeeef dededef fd	d
Zdeee	f deee	f fddZ
deee	f deee	f fddZ  ZS )r   NgpuT   modelpreprocessorconfig_filedevicec                    sB   t  j|||||d |du rtj| jjfd|i|| _dS dS )u  Use `model` and `preprocessor` to create a nlp text dual encoder then generates the text representation.
        Args:
            model (str or Model): Supply either a local model dir which supported the WS task,
            or a model id from the model hub, or a torch model instance.
            preprocessor (Preprocessor): A WordAlignmentPreprocessor.
            kwargs (dict, `optional`):
                Extra kwargs passed into the preprocessor's constructor.
         Example:
            >>> from modelscope.pipelines import pipeline
            >>> from modelscope.utils.constant import Tasks
            >>> model_id = 'damo/Third-Party-Supervised-Word-Aligner-mBERT-base-zhen'
            >>> input = {"sentence_pair": '贝利 在 墨西哥 推出 自传 。||| pele promotes autobiography in mexico .'}
            >>> pipeline_ins = pipeline(Tasks.word_alignment, model=model_id)
            >>> print(pipeline_ins(input)['output'])
        )r   r   r   r   auto_collateNsequence_length)super__init__r   Zfrom_pretrainedr   Z	model_dirr   )selfr   r   r   r   r   r   kwargs	__class__ q/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/pipelines/nlp/word_alignment_pipeline.pyr      s    zWordAlignmentPipeline.__init__inputsreturnc                 K   s   | j di ||S )Nr   )r   )r   r   Zforward_paramsr   r   r   forward9   s   zWordAlignmentPipeline.forwardc                 C   sJ   g }|d d   D ]}||d  d|d   q
d|}tj|iS )Nr   -    )keysappendjoinr   ZOUTPUT)r   r   alignkr   r   r   postprocess=   s
   

z!WordAlignmentPipeline.postprocess)NNr   Tr   )__name__
__module____qualname__r   r   strr   r   r   r   r!   r*   __classcell__r   r   r   r   r      s&    
#

*)typingr   r   r   r   numpynpZmodelscope.metainfor   Zmodelscope.modelsr   Zmodelscope.outputsr   Zmodelscope.pipelines.baser	   Zmodelscope.pipelines.builderr
   Zmodelscope.preprocessorsr   Zmodelscope.utils.constantr   __all__Zregister_moduleZword_alignmentr   r   r   r   r   <module>   s   