/usr/local/lib/python3.6/site-packages/transformers/pipelines
NameSizeModeActions
__pycache__/-0755rm
audio_classification.py58400644editdlrm
audio_utils.py77840644editdlrm
automatic_speech_recognition.py189920644editdlrm
base.py439580644editdlrm
conversational.py134660644editdlrm
feature_extraction.py35810644editdlrm
fill_mask.py98700644editdlrm
image_classification.py43250644editdlrm
image_segmentation.py80450644editdlrm
object_detection.py53040644editdlrm
pt_utils.py115130644editdlrm
question_answering.py260000644editdlrm
table_question_answering.py181100644editdlrm
text2text_generation.py151230644editdlrm
text_classification.py72900644editdlrm
text_generation.py124940644editdlrm
token_classification.py208380644editdlrm
zero_shot_classification.py108070644editdlrm
zero_shot_image_classification.py50880644editdlrm
__init__.py303590644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/transformers/pipelines/feature_extraction.py (3581B)
from typing import Dict from .base import GenericTensor, Pipeline # Can't use @add_end_docstrings(PIPELINE_INIT_ARGS) here because this one does not accept `binary_output` class FeatureExtractionPipeline(Pipeline): """ Feature extraction pipeline using no model head. This pipeline extracts the hidden states from the base transformer, which can be used as features in downstream tasks. 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). Arguments: model ([`PreTrainedModel`] or [`TFPreTrainedModel`]): The model that will be used by the pipeline to make predictions. This needs to be a model inheriting from [`PreTrainedModel`] for PyTorch and [`TFPreTrainedModel`] for TensorFlow. tokenizer ([`PreTrainedTokenizer`]): The tokenizer that will be used by the pipeline to encode data for the model. This object inherits from [`PreTrainedTokenizer`]. modelcard (`str` or [`ModelCard`], *optional*): Model card attributed to the model for this pipeline. framework (`str`, *optional*): The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework must be installed. If no framework is specified, will default to the one currently installed. If no framework is specified and both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no model is provided. task (`str`, defaults to `""`): A task-identifier for the pipeline. args_parser ([`~pipelines.ArgumentHandler`], *optional*): Reference to the object in charge of parsing supplied pipeline parameters. device (`int`, *optional*, defaults to -1): Device ordinal for CPU/GPU supports. Setting this to -1 will leverage CPU, a positive will run the model on the associated CUDA device id. """ def _sanitize_parameters(self, truncation=None, **kwargs): preprocess_params = {} if truncation is not None: preprocess_params["truncation"] = truncation return preprocess_params, {}, {} def preprocess(self, inputs, truncation=None) -> Dict[str, GenericTensor]: return_tensors = self.framework if truncation is None: kwargs = {} else: kwargs = {"truncation": truncation} model_inputs = self.tokenizer(inputs, return_tensors=return_tensors, **kwargs) return model_inputs def _forward(self, model_inputs): model_outputs = self.model(**model_inputs) return model_outputs def postprocess(self, model_outputs): # [0] is the first available tensor, logits or last_hidden_state. if self.framework == "pt": return model_outputs[0].tolist() elif self.framework == "tf": return model_outputs[0].numpy().tolist() def __call__(self, *args, **kwargs): """ 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. """ return super().__call__(*args, **kwargs)