
    g.                         d dl mZ ddlmZ ddlmZmZmZ  e edd          d	           G d
 de                      ZdS )    )Dict   )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                   T     e Zd ZdZd
dZdeeef         fdZd Z	ddZ
 fd	Z x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).
    Nc                 ^    |i }|d|v rt          d          ||d<   |}i }|||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_paramss          e/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/pipelines/feature_extraction.py_sanitize_parametersz.FeatureExtractionPipeline._sanitize_parameters(   sk    " O!.. r   -7OL)+%3A/0 "&888    returnc                 0     | j         |fd| j        i|}|S )Nr   )	tokenizer	framework)r   inputsr   model_inputss       r   
preprocessz$FeatureExtractionPipeline.preprocess;   s(    %t~f__T^___r   c                       | j         di |}|S )N )model)r   r   model_outputss      r   _forwardz"FeatureExtractionPipeline._forward?   s    "
22\22r   Fc                     |r|d         S | j         dk    r|d                                         S | j         dk    r,|d                                                                         S d S )Nr   pttf)r   tolistnumpy)r   r$   r   s      r   postprocessz%FeatureExtractionPipeline.postprocessC   sq     	$ ##>T!! #**,,,^t## #))++22444 $#r   c                 6     t                      j        |i |S )a  
        Extract the features of the input(s).

        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   argsr   	__class__s      r   r.   z"FeatureExtractionPipeline.__call__L   s!      uww0000r   )NNN)F)__name__
__module____qualname____doc__r   r   strr   r    r%   r+   r.   __classcell__)r0   s   @r   r   r      s         09 9 9 9&tC<N7O      5 5 5 5
1 
1 
1 
1 
1 
1 
1 
1 
1r   r   N)	typingr   utilsr   baser   r   r	   r   r"   r   r   <module>r:      s          & & & & & & C C C C C C C C C C 4NNNk G1 G1 G1 G1 G1 G1 G1 G1 G1 G1r   