Skip to main content

nlp_extract_features

BETA

This component is mostly stable but breaking changes could still be made outside of major version releases if a fundamental problem with the component is found.

Performs feature extraction using a Hugging Face 🤗 NLP pipeline with an ONNX Runtime model.

Introduced in version v1.11.0.

# Common config fields, showing default values
label: ""
nlp_extract_features:
name: "" # No default (optional)
path: /path/to/models/my_model.onnx # No default (required)
normalization: false

Feature Extraction

Feature extraction is the task of extracting features learnt in a model. This processor runs a feature extraction model against batches of text data, returning a model's multidimensional representation of said features in tensor/float64 format. This component uses Hugot, a library that provides an interface for running Open Neural Network Exchange (ONNX) models and transformer pipelines, with a focus on NLP tasks.

Currently, Bento only implements:

What is a pipeline?

From HuggingFace docs:

A pipeline in 🤗 Transformers is an abstraction referring to a series of steps that are executed in a specific order to preprocess and transform data and return a prediction from a model. Some example stages found in a pipeline might be data preprocessing, feature extraction, and normalization.

warning

While, only models in ONNX format are supported, exporting existing formats to ONNX is both possible and straightforward in most standard ML libraries. For more on this, check out the ONNX conversion docs. Otherwise, check out using HuggingFace Optimum for easy model conversion.

Examples

Extract normalized embeddings from text using a sentence transformer model stored locally.

pipeline:
processors:
- nlp_extract_features:
path: "onnx/model.onnx"
normalization: true
# In: "Hello world"
# Out: [0.1234, -0.5678, 0.9012, ...] (384-dimensional vector)

Fields

name

Name of the hugot pipeline. Defaults to a random UUID if not set.

Type: string

path

Path to the ONNX model file, or directory containing the model. When downloading (enable_download: true), this becomes the destination and must be a directory.

Type: string

# Examples

path: /path/to/models/my_model.onnx

path: /path/to/models/

enable_download

When enabled, attempts to download an ONNX Runtime compatible model from HuggingFace specified in repository.

Type: bool
Default: false

download_options

Options used to download a model directly from HuggingFace. Before the model is downloaded, validation occurs to ensure the remote repository contains both an.onnx and tokenizers.json file.

Type: object

download_options.repository

The name of the huggingface model repository.

Type: string

# Examples

repository: KnightsAnalytics/distilbert-NER

repository: KnightsAnalytics/distilbert-base-uncased-finetuned-sst-2-english

repository: sentence-transformers/all-MiniLM-L6-v2

download_options.onnx_filepath

Filepath of the ONNX model within the repository. Only needed when multiple .onnx files exist.

Type: string
Default: "model.onnx"

# Examples

onnx_filepath: onnx/model.onnx

onnx_filepath: onnx/model_quantized.onnx

onnx_filepath: onnx/model_fp16.onnx

normalization

Whether to apply normalization in the feature extraction pipeline.

Type: bool
Default: false