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
Returns an input template for process_batch/2
.
Optional batch processing stage.
Converts the given input to a batched tensor (or a tensor container).
Types
@type t() :: Bumblebee.Configurable.t()
Callbacks
@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.
@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
@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.
@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.
@spec process_input(t(), any()) :: Nx.t() | Nx.Container.t()
Converts the given input to a batched tensor (or a tensor container).