Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

TransformersZeroShotTextRouter

Route text strings to different connections based on a category label.

Work in Progress

We're working on adding pipeline examples and most common component connections.

Key Features​

  • Routes text strings to different downstream connections based on zero-shot classification.
  • Uses a Hugging Face zero-shot classification model to predict the category of the text.
  • Supports multi-label classification by setting multi_label=True.
  • The set of labels for categorization is configured at initialization time.

Configuration​

  1. Drag the TransformersZeroShotTextRouter component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    • Set the labels list with the categories to route text to.
    • Set the model name. The default is MoritzLaurer/deberta-v3-base-zeroshot-v1.1-all-33.
  4. Go to the Advanced tab to configure multi_label, device, and huggingface_pipeline_kwargs.

Connections​

TransformersZeroShotTextRouter accepts a text string as input. Connect it to any component that outputs a string.

It outputs the text to a dynamically created output named after the predicted label. Connect each labeled output to the appropriate downstream component.

Source Code​

To check this component's source code, open zero_shot_text_router.py in the Haystack repository.

Usage Examples​

Basic Configuration​

TransformersZeroShotTextRouter:
type: haystack_integrations.components.routers.transformers.zero_shot_text_router.TransformersZeroShotTextRouter
init_parameters: {}
# haystack-pipeline
components:
TransformersZeroShotTextRouter:
type: haystack_integrations.components.routers.transformers.zero_shot_text_router.TransformersZeroShotTextRouter
init_parameters:

Parameters​

Inputs​

ParameterTypeDefaultDescription
textstrA string of text to route.

Outputs​

ParameterTypeDefaultDescription

Init Parameters​

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
labelsList[str]The set of labels to use for classification. Can be a single label, a string of comma-separated labels, or a list of labels.
multi_labelboolFalseIndicates if multiple labels can be true. If False, label scores are normalized so their sum equals 1 for each sequence. If True, the labels are considered independent and probabilities are normalized for each candidate by doing a softmax of the entailment score vs. the contradiction score.
modelstrMoritzLaurer/deberta-v3-base-zeroshot-v1.1-all-33The name or path of a Hugging Face model for zero-shot text classification.
deviceOptional[ComponentDevice]NoneThe device for loading the model. If None, automatically selects the default device. If a device or device map is specified in huggingface_pipeline_kwargs, it overrides this parameter.
tokenOptional[Secret]Secret.from_env_var(['HF_API_TOKEN', 'HF_TOKEN'], strict=False)The API token used to download private models from Hugging Face.
huggingface_pipeline_kwargsOptional[Dict[str, Any]]NoneA dictionary of keyword arguments for initializing the Hugging Face zero-shot text classification.

Run Method Parameters​

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
textstrA string of text to route.