> For the complete documentation index, see [llms.txt](https://utca.knowledgator.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://utca.knowledgator.com/predictors/transformers-predictors.md).

# Transformers predictors

Huggingface Transformers predictors

## Module: [implementation](/framework-structure.md#implementation).predictors

***

***

## <mark style="color:green;">TransformersModel</mark>

Transformers model predictor. Subclass of [**Predictor**](/predictors/predictor.md).

When executed calls provided model.

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**cfg**</mark>**&#x20;(**[**TransformersModelConfig**](#transformersmodelconfig)**):** Configuration for predictor.
* <mark style="color:orange;">**input\_class**</mark>**&#x20;(Type\[**[**Input**](/core/schemas.md#input)**]):** Class for input validation.
* <mark style="color:orange;">**output\_class**</mark>**&#x20;(Type\[**[**Output**](/core/schemas.md#output)**]):** Class for output validation.
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

### <mark style="color:blue;">invoke</mark>

Call model

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(**[**Input**](/core/schemas.md#input)**)**: Validated input.
* <mark style="color:orange;">**evaluator**</mark>**&#x20;(**[**Evaluator**](/core/evaluator.md)**)**: Evaluator in context of which executed.&#x20;

#### Returns:

* **Dict\[str, Any]**: Result of execution.

***

### <mark style="color:blue;">config (Any)</mark>

Model configuration

***

***

***

## <mark style="color:green;">TransformersGenerativeModel</mark>

Transformers generative model wrapper. Subclass of [**TransformersModel**](#transformersmodel).

When executed calls generate method of provided model.

***

### <mark style="color:blue;">invoke</mark>

Call generate method of the model

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(**[**Input**](/core/schemas.md#input)**)**: Validated input.
* <mark style="color:orange;">**evaluator**</mark>**&#x20;(**[**Evaluator**](/core/evaluator.md)**)**: Evaluator in context of which executed.&#x20;

#### Returns:

* **Dict\[str, Any]**: Result of execution.

***

***

***

## <mark style="color:green;">TransformersModelConfig</mark>

Transformers model configuration. Subclass of [**Config**](/core/schemas.md#config).

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**model**</mark>**&#x20;(Union\[**[**PreTrainedModel**](https://huggingface.co/docs/transformers/main_classes/model#transformers.PreTrainedModel)**,**[ **TFPreTrainedModel**](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/model#transformers.TFPreTrainedModel)**]):** Transformers model that wil be used. See more:

{% embed url="<https://huggingface.co/transformers/v4.11.3/pretrained_models.html>" %}

{% embed url="<https://huggingface.co/models>" %}

* <mark style="color:orange;">**kwargs**</mark>**&#x20;(Optional\[Dict\[str, Any]], optional):** Extra model parameters.

***

### <mark style="color:blue;">config (Any)</mark>

Model configuration

***

***

***

## <mark style="color:green;">TransformersPipeline</mark>

Transformers pipeline predictor. Subclass of [**Predictor**](/predictors/predictor.md).

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**cfg**</mark>**&#x20;(**[**TransformersPipelineConfig**](#transformerspipelineconfig)**):** Configuration for predictor.
* <mark style="color:orange;">**input\_class**</mark>**&#x20;(Type\[**[**Input**](/core/schemas.md#input)**]):** Class for input validation.
* <mark style="color:orange;">**output\_class**</mark>**&#x20;(Type\[**[**Output**](/core/schemas.md#output)**]):** Class for output validation.
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

### <mark style="color:blue;">invoke</mark>

Call pipeline

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(**[**Input**](/core/schemas.md#input)**)**: Validated input.
* <mark style="color:orange;">**evaluator**</mark>**&#x20;(**[**Evaluator**](/core/evaluator.md)**)**: Evaluator in context of which executed.&#x20;

#### Returns:

* **Dict\[str, Any]**: Result of execution.

***

### <mark style="color:blue;">config (Any)</mark>

Model configuration

***

***

***

## <mark style="color:green;">TransformersPipelineConfig</mark>

Transformers pipeline configuration. Subclass of [**Config**](/core/schemas.md#config).

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**task**</mark>**&#x20;(Optional\[str], optional):**  The task defining which pipeline will be returned. Defaults to None. Currently accepted tasks are:
  * **"audio-classification"**: will return a [AudioClassificationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.AudioClassificationPipeline).
  * **"automatic-speech-recognition"**: will return a [AutomaticSpeechRecognitionPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.AutomaticSpeechRecognitionPipeline).
  * **"conversational"**: will return a [ConversationalPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ConversationalPipeline).
  * **"depth-estimation"**: will return a [DepthEstimationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.DepthEstimationPipeline).
  * **"document-question-answering"**: will return a [DocumentQuestionAnsweringPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.DocumentQuestionAnsweringPipeline).
  * **"feature-extraction"**: will return a [FeatureExtractionPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.FeatureExtractionPipeline).
  * **"fill-mask"**: will return a [FillMaskPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.FillMaskPipeline):.
  * **"image-classification"**: will return a [ImageClassificationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ImageClassificationPipeline).
  * **"image-feature-extraction"**: will return an [ImageFeatureExtractionPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ImageFeatureExtractionPipeline).
  * **"image-segmentation"**: will return a [ImageSegmentationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ImageSegmentationPipeline).
  * **"image-to-image"**: will return a [ImageToImagePipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ImageToImagePipeline).
  * **"image-to-text"**: will return a [ImageToTextPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ImageToTextPipeline).
  * **"mask-generation"**: will return a [MaskGenerationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.MaskGenerationPipeline).
  * **"object-detection"**: will return a [ObjectDetectionPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ObjectDetectionPipeline).
  * **"question-answering"**: will return a [QuestionAnsweringPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.QuestionAnsweringPipeline).
  * **"summarization"**: will return a [SummarizationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.SummarizationPipeline).
  * **"table-question-answering"**: will return a [TableQuestionAnsweringPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.TableQuestionAnsweringPipeline).
  * **"text2text-generation"**: will return a [Text2TextGenerationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.Text2TextGenerationPipeline).
  * **"text-classification"** (alias **"sentiment-analysis"** available): will return a [TextClassificationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.TextClassificationPipeline).
  * **"text-generation"**: will return a [TextGenerationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.TextGenerationPipeline):.
  * **"text-to-audio"** (alias **"text-to-speech"** available): will return a [TextToAudioPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.TextToAudioPipeline):.
  * **"token-classification"** (alias **"ner"** available): will return a [TokenClassificationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.TokenClassificationPipeline).
  * **"translation"**: will return a [TranslationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.TranslationPipeline).
  * **"translation\_xx\_to\_yy"**: will return a [TranslationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.TranslationPipeline).
  * **"video-classification"**: will return a [VideoClassificationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.VideoClassificationPipeline).
  * **"visual-question-answering"**: will return a [VisualQuestionAnsweringPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.VisualQuestionAnsweringPipeline).
  * **"zero-shot-classification"**: will return a [ZeroShotClassificationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ZeroShotClassificationPipeline).
  * **"zero-shot-image-classification"**: will return a [ZeroShotImageClassificationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ZeroShotImageClassificationPipeline).
  * **"zero-shot-audio-classification"**: will return a [ZeroShotAudioClassificationPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ZeroShotAudioClassificationPipeline).
  * **"zero-shot-object-detection"**: will return a [ZeroShotObjectDetectionPipeline](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/pipelines#transformers.ZeroShotObjectDetectionPipeline).
* <mark style="color:orange;">**model**</mark>**&#x20;(Optional\[Union\[str,** [**PreTrainedModel**](https://huggingface.co/docs/transformers/main_classes/model#transformers.PreTrainedModel)**,** [**TFPreTrainedModel**](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/model#transformers.TFPreTrainedModel)**]], optional):** The model that will be used by the pipeline to make predictions. This can be a model identifier or an actual instance of a pretrained model inheriting from [**PreTrainedModel**](https://huggingface.co/docs/transformers/main_classes/model#transformers.PreTrainedModel) (for PyTorch) or [**TFPreTrainedModel**](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/model#transformers.TFPreTrainedModel) (for TensorFlow). Defaults to None.
* <mark style="color:orange;">**config**</mark>**&#x20;(Optional\[Union\[str,** [**PretrainedConfig**](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/configuration#transformers.PretrainedConfig)**]], optional):** The configuration that will be used by the pipeline to instantiate the model. This can be a model identifier or an actual pretrained model configuration inheriting from [**PretrainedConfig**](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/configuration#transformers.PretrainedConfig). Defaults to None.
* <mark style="color:orange;">**tokenizer**</mark>**&#x20;(Optional\[Union\[str,**[ **PreTrainedTokenizer**](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/tokenizer#transformers.PreTrainedTokenizer)**]], optional):** The tokenizer that will be used by the pipeline to encode data for the model. This can be a model identifier or an actual pretrained tokenizer inheriting from [**PreTrainedTokenizer**](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/tokenizer#transformers.PreTrainedTokenizer). Defaults to None.
* <mark style="color:orange;">**feature\_extractor**</mark>**&#x20;(Optional\[Any], optional):** The feature extractor that will be used by the pipeline to encode data for the model. This can be a model identifier or an actual pretrained feature extractor inheriting from **PreTrainedFeatureExtractor**. Defaults to None.\
  &#x20;\
  Feature extractors are used for non-NLP models, such as Speech or Vision models as well as multi-modal models. Multi-modal models will also require a tokenizer to be passed.

  \
  If not provided, the default feature extractor for the given **model** will be loaded (if it is a string). If **model** is not specified or not a string, then the default feature extractor for **config** is loaded (if it is a string). However, if **config** is also not given or not a string, then the default feature extractor for the given **task** will be loaded.
* <mark style="color:orange;">**image\_processor**</mark>**&#x20;(Optional\[Union\[str, BaseImageProcessor]], optional):** Defaults to Non&#x65;**.**
* <mark style="color:orange;">**framework**</mark>**&#x20;(Optional\[str], optional):** The framework to use, either **"pt"** for PyTorch or **"tf"** for TensorFlow. The specified framework must be installed.<br>

  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.
* <mark style="color:orange;">**revision**</mark>**&#x20;(Optional\[str], optional):** When passing a task name or a string model identifier: The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so revision can be any identifier allowed by git.\
  \
  If equals to None, **"main"** will be used. Defaults to None.
* <mark style="color:orange;">**use\_fast**</mark>**&#x20;(bool, optional):** Whether or not to use a Fast tokenizer if possible (a [**PreTrainedTokenizerFast**](https://huggingface.co/docs/transformers/v4.40.1/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast)). Defaults to True.
* <mark style="color:orange;">**token**</mark>**&#x20;(Optional\[Union\[str, bool]], optional):** The token to use as HTTP bearer authorization for remote files. If True, will use the token generated when running huggingface-cli login (stored in \~/.huggingface). Defaults to None.
* <mark style="color:orange;">**device**</mark>**&#x20;(Optional\[Union\[int, str,** [**torch.device**](https://pytorch.org/docs/stable/generated/torch.cuda.device.html#device)**]], optional):** Defines the device (e.g., **"cpu"**, **"cuda:1"**, **"mps"**, or a GPU ordinal rank like **1**) on which this pipeline will be allocated. Defaults to None.
* <mark style="color:orange;">**device\_map**</mark>**&#x20;(Optional\[Union\[str, Dict\[str, Union\[int, str, torch.device]]]], optional):** Sent directly as model\_kwargs (just a simpler shortcut). When accelerate library is present, set **device\_map="auto"** to compute the most optimized device\_map automatically (see [here](https://huggingface.co/docs/accelerate/main/en/package_reference/big_modeling#accelerate.cpu_offload) for more information). Defaults to None.

{% hint style="warning" %}
Do not use device\_map **and** device at the same time as they will conflict
{% endhint %}

* <mark style="color:orange;">**torch\_dtype**</mark>**&#x20;(Optional\[Union\[str, torch.dtype]], optional):** Sent directly as model\_kwargs (just a simpler shortcut) to use the available precision for this model (torch.float16, torch.bfloat16, … or "auto"). Defaults to None.
* <mark style="color:orange;">**trust\_remote\_code**</mark>**&#x20;(bool, optional):** Whether or not to allow for custom code defined on the Hub in their own modeling, configuration, tokenization or even pipeline files. This option should only be set to True for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. Defaults to False.
* <mark style="color:orange;">**model\_kwargs**</mark>**&#x20;(Optional\[Dict\[str, Any]], optional):** Additional dictionary of keyword arguments passed along to the model’s from\_pretrained(..., \*\*model\_kwargs) function. Defaults to None.
* <mark style="color:orange;">**pipeline\_class**</mark>**&#x20;(Optional\[Any], optional):** Defaults to None.
* <mark style="color:orange;">**kwargs**</mark>**&#x20;(Optional\[Dict\[str, Any]], optional):** Additional keyword arguments passed along to the specific pipeline init (see the documentation for the corresponding pipeline class for possible values). Defaults to None.

#### For more, see:

{% embed url="<https://huggingface.co/docs/transformers/main_classes/pipelines>" %}

***

***
