View Source Bumblebee.Featurizer behaviour (Bumblebee v0.5.3)

An interface for configuring and applying featurizers.

A featurizer is used to convert raw data into model input.

Every module implementing this behaviour is expected to also define a configuration struct.

Summary

Callbacks

Returns an input template for process_batch/2.

Optional batch processing stage.

Converts the given input to a batched tensor (or a tensor container).

Functions

Optional batch processing stage.

Converts the given input to a batched tensor (or a tensor container).

Types

Callbacks

Link to this callback

batch_template(t, batch_size)

View Source (optional)
@callback batch_template(t(), batch_size :: pos_integer()) :: Nx.t() | Nx.Container.t()

Returns an input template for process_batch/2.

The shape is effectively the same as the result of process_input/2, except for the batch size.

Link to this callback

process_batch(t, input)

View Source (optional)
@callback process_batch(t(), input :: Nx.t() | Nx.Container.t()) ::
  Nx.t() | Nx.Container.t()

Optional batch processing stage.

This is a numerical function. It receives the result of process_input/2, except the batch size may differ.

When using featurizer as part of Nx.Serving, the batch stage can be merged with the model computation and compiled together.

@callback process_input(t(), input :: any()) :: Nx.t() | Nx.Container.t()

Converts the given input to a batched tensor (or a tensor container).

Numerical batch processing should be moved to process_batch/2 whenever possible.

Functions

Link to this function

batch_template(featurizer, batch_size)

View Source
@spec batch_template(t(), pos_integer()) :: Nx.t() | Nx.Container.t() | nil

Returns an input template for process_batch/2.

If the featurizer does not define batch processing, nil is returned.

Link to this function

process_batch(featurizer, batch)

View Source
@spec process_batch(t(), Nx.t() | Nx.Container.t()) :: Nx.t() | Nx.Container.t()

Optional batch processing stage.

This is a numerical function. It receives the result of process_input/2, except the batch size may differ.

If the featurizer does not define batch processing, the input is returned as is.

Link to this function

process_input(featurizer, input)

View Source
@spec process_input(t(), any()) :: Nx.t() | Nx.Container.t()

Converts the given input to a batched tensor (or a tensor container).