o
    *j#	                     @   s   d dl Z d dlZd dl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mZ d	gZejeje	jd
G dd	 d	eZdS )    N)AnyDict)XLMRobertaTokenizer)	Pipelines)
OutputKeys)Pipeline)	PIPELINES)	ModelFileTasks$TranslationQualityEstimationPipeline)module_namec                       s   e Zd Zddedef fddZdee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   gpumodeldevicec                    s   t  j||d tj| jtj}t|d}t	
| }W d    n1 s(w   Y  t| j| _tjj|| jd| j| _d S )N)r   r   rb)Zmap_location)super__init__ospathjoinr   r	   ZTORCH_MODEL_FILEopenioBytesIOreadr   Zfrom_pretrained	tokenizertorchZjitloadr   to)selfr   r   kwargsZ
model_filefbuffer	__class__ /var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/pipelines/nlp/translation_quality_estimation_pipeline.pyr      s   z-TranslationQualityEstimationPipeline.__init__inputsc                 C   sf   |d   }|d   }| jj||ggdddd}|d | j}|d | j}|||d |S )	NZsource_textZtarget_textptT)Zreturn_tensorspaddingZ
truncation	input_idsattention_mask)r)   r*   )stripr   Zbatch_encode_plusr   r   update)r   r&   Zsrc_textZtgt_textZencoded_inputsr)   r*   r$   r$   r%   
preprocess!   s   z/TranslationQualityEstimationPipeline.preprocessreturnc                 C   sJ   d|vr	|  |}| |d |d }tjdtj|d    i}|S )Nr)   r*   z-1r   )r-   r   r   ZLABELSZSCORESdetachZsqueezetolist)r   r&   resresultr$   r$   r%   forward1   s   
z,TranslationQualityEstimationPipeline.forwardc                 C   s   |S )zprocess the prediction results

        Args:
            inputs (Dict[str, Any]): input data dict

        Returns:
            Dict[str, str]: the prediction results
        r$   )r   r&   r$   r$   r%   postprocess;   s   	z0TranslationQualityEstimationPipeline.postprocess)r   )__name__
__module____qualname__strr   r   r   r-   r3   r4   __classcell__r$   r$   r"   r%   r      s
    	"*
)r   r   typingr   r   r   Ztransformersr   Zmodelscope.metainfor   Zmodelscope.outputsr   Zmodelscope.pipelines.baser   Zmodelscope.pipelines.builderr   Zmodelscope.utils.constantr	   r
   __all__Zregister_moduleZsentence_similarityZtranslation_quality_estimationr   r$   r$   r$   r%   <module>   s    