o
    *j                     @   s   d dl Z 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mZ d dlmZ d dlmZ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OptionalUnion)	Pipelines)Model)
OutputKeys)PipelineTensor)	PIPELINES) FillMaskTransformersPreprocessorPreprocessor)Config)	ModelFileTasksFeatureExtractionPipeline)module_namec                	       s   e Zd Z						ddeeef de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gpuTF   modelpreprocessorconfig_filedevicec           	         sz   t  j||||||dd|di d t| jts#J dtj |du r6tj	| jj
f||d|| _| j  dS )a_  Use `model` and `preprocessor` to create a nlp feature extraction pipeline for prediction

        Args:
            model (str or Model): Supply either a local model dir which supported feature extraction task, or a
            no-head model id from the model hub, or a torch model instance.
            preprocessor (Preprocessor): An optional preprocessor instance, please make sure the preprocessor fits for
            the model if supplied.
            kwargs (dict, `optional`):
                Extra kwargs passed into the preprocessor's constructor.

        Examples:
            >>> from modelscope.pipelines import pipeline
            >>> pipe_ins = pipeline('feature_extraction', model='damo/nlp_structbert_feature-extraction_english-large')
            >>> input = 'Everything you love is treasure'
            >>> print(pipe_ins(input))


        compileFcompile_options)r   r   r   r   auto_collater   r   z,please check whether model config exists in N)paddingsequence_length)super__init__pop
isinstancer   r   r   ZCONFIGURATIONr   Zfrom_pretrainedZ	model_dirr   eval)	selfr   r   r   r   r   r   r   kwargs	__class__ u/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/pipelines/nlp/feature_extraction_pipeline.pyr      s,   

	
z"FeatureExtractionPipeline.__init__inputsreturnc                 K   s@   t   | jdi ||W  d    S 1 sw   Y  d S )Nr'   )torchZno_gradr   )r#   r)   Zforward_paramsr'   r'   r(   forwardF   s   
$z!FeatureExtractionPipeline.forwardc                 C   s   t j|t j  iS )zprocess the prediction results

        Args:
            inputs (Dict[str, Any]): _description_

        Returns:
            Dict[str, str]: the prediction results
        )r   ZTEXT_EMBEDDINGtolist)r#   r)   r'   r'   r(   postprocessK   s   z%FeatureExtractionPipeline.postprocess)NNr   TFr   )__name__
__module____qualname__r   r   strr   r   r   r   r   r,   r
   r.   __classcell__r'   r'   r%   r(   r      s(    
.

*)ostypingr   r   r   r   r+   Zmodelscope.metainfor   Zmodelscope.modelsr   Zmodelscope.outputsr   Zmodelscope.pipelines.baser	   r
   Zmodelscope.pipelines.builderr   Zmodelscope.preprocessorsr   r   Zmodelscope.utils.configr   Zmodelscope.utils.constantr   r   __all__Zregister_moduleZfeature_extractionr   r'   r'   r'   r(   <module>   s    