TransformersZeroShotTextRouter
Route text strings to different connections based on a category label.
Key Features
- Routes text to different pipeline branches based on zero-shot classification — no training data required.
- Uses a Hugging Face NLI model to classify text against the labels you provide.
- Supports multi-label classification to allow multiple labels per input.
- Each label becomes a separate output connection for downstream routing.
- Compatible with any Hugging Face zero-shot classification model.
Configuration
- Drag the
TransformersZeroShotTextRoutercomponent onto the canvas from the Component Library. - Click the component to open the configuration panel.
- On the General tab:
- Enter the labels to use for routing, such as
["technical", "billing", "general"]. - Enter the model name or path, such as
MoritzLaurer/deberta-v3-base-zeroshot-v1.1-all-33.
- Enter the labels to use for routing, such as
- Go to the Advanced tab to configure multi-label mode, device, token, and Hugging Face pipeline kwargs.
Connections
TransformersZeroShotTextRouter receives a text string as input. It routes the text to one of its output connections, where each label becomes a separate output. Connect each label output to a different downstream component based on the routing logic you want.
Usage Example
components:
TransformersZeroShotTextRouter:
type: components.routers.zero_shot_text_router.TransformersZeroShotTextRouter
init_parameters:
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| text | str | A string of text to route. |
Outputs
| Parameter | Type | Default | Description |
|---|
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| labels | List[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_label | bool | False | Indicates 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. |
| model | str | MoritzLaurer/deberta-v3-base-zeroshot-v1.1-all-33 | The name or path of a Hugging Face model for zero-shot text classification. |
| device | Optional[ComponentDevice] | None | The 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. |
| token | Optional[Secret] | Secret.from_env_var(['HF_API_TOKEN', 'HF_TOKEN'], strict=False) | The API token used to download private models from Hugging Face. If True, uses either HF_API_TOKEN or HF_TOKEN environment variables. |
| huggingface_pipeline_kwargs | Optional[Dict[str, Any]] | None | A 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
| text | str | A string of text to route. |
Was this page helpful?