o
    iN                     @   sR   d dl mZ ddlmZ ddlmZmZmZ eedddd	G d
d deZdS )    )Any   )add_end_docstrings   )GenericTensorPipelinebuild_pipeline_init_argsTF)has_tokenizersupports_binary_outputa  
        tokenize_kwargs (`dict`, *optional*):
                Additional dictionary of keyword arguments passed along to the tokenizer.
        return_tensors (`bool`, *optional*):
            If `True`, returns a tensor according to the specified framework, otherwise returns a list.c                       s   e Zd ZdZdZdZdZdZdddZde	e
ef fdd	Zd
d ZdddZde
ee
 B dedeee B f fddZ  ZS )FeatureExtractionPipelinea  
    Feature extraction pipeline uses no model head. This pipeline extracts the hidden states from the base
    transformer, which can be used as features in downstream tasks.

    Example:

    ```python
    >>> from transformers import pipeline

    >>> extractor = pipeline(model="google-bert/bert-base-uncased", task="feature-extraction")
    >>> result = extractor("This is a simple test.", return_tensors=True)
    >>> result.shape  # This is a tensor of shape [1, sequence_length, hidden_dimension] representing the input string.
    torch.Size([1, 8, 768])
    ```

    Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial)

    This feature extraction pipeline can currently be loaded from [`pipeline`] using the task identifier:
    `"feature-extraction"`.

    All models may be used for this pipeline. See a list of all models, including community-contributed models on
    [huggingface.co/models](https://huggingface.co/models).
    FTNc                 K   sN   |d u ri }|d urd|v rt d||d< |}i }|d ur"||d< |i |fS )N
truncationz\truncation parameter defined twice (given as keyword argument as well as in tokenize_kwargs)return_tensors)
ValueError)selfr   tokenize_kwargsr   kwargspreprocess_paramspostprocess_params r   k/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/transformers/pipelines/feature_extraction.py_sanitize_parameters-   s   
z.FeatureExtractionPipeline._sanitize_parametersreturnc                 K   s   | j |fddi|}|S )Nr   pt)	tokenizer)r   inputsr   model_inputsr   r   r   
preprocess@   s   z$FeatureExtractionPipeline.preprocessc                 C   s   | j di |}|S )Nr   )model)r   r   model_outputsr   r   r   _forwardD   s   z"FeatureExtractionPipeline._forwardc                 C   s   |r|d S |d   S )Nr   )tolist)r   r   r   r   r   r   postprocessH   s   z%FeatureExtractionPipeline.postprocessargsr   c                    s   t  j|i |S )a  
        Extract the features of the input(s) text.

        Args:
            args (`str` or `list[str]`): One or several texts (or one list of texts) to get the features of.

        Return:
            A nested list of `float`: The features computed by the model.
        )super__call__)r   r"   r   	__class__r   r   r$   N   s   
z"FeatureExtractionPipeline.__call__)NNN)F)__name__
__module____qualname____doc___load_processor_load_image_processor_load_feature_extractor_load_tokenizerr   dictstrr   r   r   r!   listr   r$   __classcell__r   r   r%   r   r      s    	

2r   N)	typingr   utilsr   baser   r   r   r   r   r   r   r   <module>   s    
