Skip to content

Add a Feature Type

  1. Add a new feature class

Souce code for feature classes lives under ludwig/features. Input and output feature classes are defined in the same file, for example CategoryInputFeature and CategoryOutputFeature are defined in ludwig/features/category_feature.py.

An input features inherit from the InputFeature and corresponding mixin feature classes, for example CategoryInputFeature inherits from CategoryFeatureMixin and InputFeature.

Similarly, output features inherit from the OutputFeature and corresponding base feature classes, for example CategoryOutputFeature inherits from CategoryFeatureMixin and OutputFeature.

Feature parameters are provided in a dictionary of key-value pairs as an argument to the input or output feature constructor which contains default parameter values as well.

Input features

All input features should implement __init__ and call methods with the following signatures:

__init__

def __init__(self, feature, encoder_obj=None):

Inputs

  • feature: (dict) contains all feature parameters.
  • encoder_obj: (*Encoder, default: None) is an encoder object of the type supported (a cateory encoder, binary encoder, etc.). It is used only when two input features share the encoder.

call

def call(self, inputs, training=None, mask=None):

Inputs

  • inputs (tf.Tensor): input tensor.
  • training (bool, default: None): boolean indicating whether we are currently training the model or performing inference for prediction.
  • mask (tf.Tensor, default: None): binary tensor indicating which of the values in the inputs tensor should be masked out.

Return

  • hidden (tf.Tensor): feature encodings.

Output features

All input features should implement __init__, logits and predictions methods with the following signatures:

__init__

def __init__(self, feature, encoder_obj=None):

Inputs

  • feature (dict): contains all feature parameters.
  • decoder_obj (*Decoder, default: None): is a decoder object of the type supported (a cateory decoder, binary decoder, etc.). It is used only when two output features share the decoder.

logits

def call(self, inputs, **kwargs):

Inputs

  • inputs (dict): input dictionary that is the output of the combiner.

Return

  • hidden (tf.Tensor): feature logits.

predictions

def call(self, inputs, **kwargs):

Inputs

  • inputs (dict): input dictionary that contains the output of the combiner and the logits function.

Return

  • hidden (dict): contains predictions, probabilities and logits.

  • Add the new feature class to the corresponding feature registry


Input and output feature registries are defined in ludwig/features/feature_registries.py.