🏭 Preprocessing Layers Factory
The PreprocessorLayerFactory
class provides a convenient way to create and manage preprocessing layers for your machine learning models. It supports both standard Keras preprocessing layers and custom layers defined within the KDP framework.
🎡 Using Keras Preprocessing Layers
All preprocessing layers available in Keras can be used within the PreprocessorLayerFactory
. You can access these layers by their class names. Here's an example of how to use a Keras preprocessing layer:
normalization_layer = PreprocessorLayerFactory.create_layer(
"Normalization",
axis=-1,
mean=None,
variance=None
)
- Normalization
- Discretization
- CategoryEncoding
- Hashing
- HashedCrossing
- StringLookup
- IntegerLookup
- TextVectorization
- ... and more
🏗️ Custom KDP Preprocessing Layers
In addition to Keras layers, the PreprocessorLayerFactory
includes several custom layers specific to the KDP framework. Here's a list of available custom layers:
cast_to_float32_layer(name='cast_to_float32', **kwargs)
staticmethod
Create a CastToFloat32Layer layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the layer. |
'cast_to_float32'
|
**kwargs |
dict
|
Additional keyword arguments to pass to the layer constructor. |
{}
|
Returns:
Type | Description |
---|---|
Layer
|
An instance of the CastToFloat32Layer layer. |
create_layer(layer_class, name=None, **kwargs)
staticmethod
Create a layer using the layer class name, automatically filtering kwargs based on the layer class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer_class |
str | Class Object
|
The name of the layer class to be created (e.g., 'Normalization', 'Rescaling') or the class object itself. |
required |
name |
str
|
The name of the layer. Optional. |
None
|
**kwargs |
Additional keyword arguments to pass to the layer constructor. |
{}
|
Returns:
Type | Description |
---|---|
Layer
|
An instance of the specified layer class. |
date_encoding_layer(name='date_encoding_layer', **kwargs)
staticmethod
Create a DateEncodingLayer layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the layer. |
'date_encoding_layer'
|
**kwargs |
dict
|
Additional keyword arguments to pass to the layer constructor. |
{}
|
Returns:
Type | Description |
---|---|
Layer
|
An instance of the DateEncodingLayer layer. |
date_parsing_layer(name='date_parsing_layer', **kwargs)
staticmethod
Create a DateParsingLayer layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the layer. |
'date_parsing_layer'
|
**kwargs |
dict
|
Additional keyword arguments to pass to the layer constructor. |
{}
|
Returns:
Type | Description |
---|---|
Layer
|
An instance of the DateParsingLayer layer. |
date_season_layer(name='date_season_layer', **kwargs)
staticmethod
Create a SeasonLayer layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the layer. |
'date_season_layer'
|
**kwargs |
dict
|
Additional keyword arguments to pass to the layer constructor. |
{}
|
Returns:
Type | Description |
---|---|
Layer
|
An instance of the SeasonLayer layer. |
text_preprocessing_layer(name='text_preprocessing', **kwargs)
staticmethod
Create a TextPreprocessingLayer layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the layer. |
'text_preprocessing'
|
**kwargs |
dict
|
Additional keyword arguments to pass to the layer constructor. |
{}
|
Returns:
Type | Description |
---|---|
Layer
|
An instance of the TextPreprocessingLayer layer. |
transformer_block_layer(name='transformer', **kwargs)
staticmethod
Create a TransformerBlock layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the layer. |
'transformer'
|
**kwargs |
dict
|
Additional keyword arguments to pass to the layer constructor. |
{}
|
Returns:
Type | Description |
---|---|
Layer
|
An instance of the TransformerBlock layer. |