🏗️ Models API Reference
Welcome to the KMR Models documentation! All models are designed to work exclusively with Keras 3 and provide high-level abstractions for common tabular data processing tasks.
What You'll Find Here
Each model includes detailed documentation with: - ✨ Complete parameter descriptions with types and defaults - 🎯 Usage examples showing real-world applications - ⚡ Best practices and performance considerations - 🎨 When to use guidance for each model - 🔧 Implementation notes for developers
Ready-to-Use Models
These models provide complete architectures that you can use out-of-the-box or customize for your specific needs.
Base Classes
All models inherit from BaseModel
ensuring consistent behavior and Keras 3 compatibility.
🏗️ Core Models
🚀 BaseFeedForwardModel
Flexible feed-forward model architecture for tabular data with customizable layers.
kmr.models.feed_forward.BaseFeedForwardModel
BaseFeedForwardModel(
feature_names,
hidden_units,
output_units=1,
dropout_rate=0.0,
activation="relu",
preprocessing_model=None,
kernel_initializer="glorot_uniform",
bias_initializer="zeros",
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
**kwargs
)
Base feed forward neural network model.
This model implements a basic feed forward neural network with configurable hidden layers, activations, and regularization options.
Example
# Create a simple feed forward model
model = BaseFeedForwardModel(
feature_names=['feature1', 'feature2'],
hidden_units=[64, 32],
output_units=1
)
# Compile and train the model
model.compile(optimizer='adam', loss='mse')
model.fit(train_dataset, epochs=10)
Initialize Feed Forward Neural Network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature_names |
list[str]
|
list of feature names. |
required |
hidden_units |
list[int]
|
list of hidden layer units. |
required |
output_units |
int
|
Number of output units. |
1
|
dropout_rate |
float
|
Dropout rate. |
0.0
|
activation |
str
|
Activation function. |
'relu'
|
preprocessing_model |
Model | None
|
Optional preprocessing model. |
None
|
kernel_initializer |
str | Any | None
|
Weight initializer. |
'glorot_uniform'
|
bias_initializer |
str | Any | None
|
Bias initializer. |
'zeros'
|
kernel_regularizer |
str | Any | None
|
Weight regularizer. |
None
|
bias_regularizer |
str | Any | None
|
Bias regularizer. |
None
|
activity_regularizer |
str | Any | None
|
Activity regularizer. |
None
|
kernel_constraint |
str | Any | None
|
Weight constraint. |
None
|
bias_constraint |
str | Any | None
|
Bias constraint. |
None
|
**kwargs |
Any
|
Additional arguments. |
{}
|
Functions
from_config
classmethod
from_config(config)
Create model from configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
dict[str, Any]
|
Dict containing model configuration. |
required |
Returns:
Type | Description |
---|---|
BaseFeedForwardModel
|
Instantiated model. |
🎯 Advanced Models
🧩 SFNEBlock
Sparse Feature Network Ensemble block for advanced feature processing and ensemble learning.
kmr.models.SFNEBlock
This module implements a SFNEBlock (Slow-Fast Neural Engine Block) model that combines slow and fast processing paths for feature extraction. It's a building block for the Terminator model.
Classes
SFNEBlock
SFNEBlock(
input_dim,
output_dim=None,
hidden_dim=64,
num_layers=2,
slow_network_layers=3,
slow_network_units=128,
preprocessing_model=None,
name=None,
**kwargs
)
Slow-Fast Neural Engine Block for feature processing.
This model combines a slow network path and a fast processing path to extract features. It uses a SlowNetwork to generate hyper-kernels, which are then used by a HyperZZWOperator to compute context-dependent weights. These weights are further processed by global and local convolutions before being combined.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
int
|
Dimension of the input features. |
required |
output_dim |
int
|
Dimension of the output features. Default is same as input_dim. |
None
|
hidden_dim |
int
|
Number of hidden units in the network. Default is 64. |
64
|
num_layers |
int
|
Number of layers in the network. Default is 2. |
2
|
slow_network_layers |
int
|
Number of layers in the slow network. Default is 3. |
3
|
slow_network_units |
int
|
Number of units per layer in the slow network. Default is 128. |
128
|
preprocessing_model |
Model | None
|
Optional preprocessing model to apply before the main processing. |
None
|
name |
str | None
|
Optional name for the model. |
None
|
Input shape
2D tensor with shape: (batch_size, input_dim)
or a dictionary with feature inputs
Output shape
2D tensor with shape: (batch_size, output_dim)
Example
import keras
from kmr.models import SFNEBlock
# Create sample input data
x = keras.random.normal((32, 16)) # 32 samples, 16 features
# Create the model
sfne = SFNEBlock(input_dim=16, output_dim=8)
y = sfne(x)
print("Output shape:", y.shape) # (32, 8)
Initialize the SFNEBlock model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
int
|
Input dimension. |
required |
output_dim |
int
|
Output dimension. |
None
|
hidden_dim |
int
|
Hidden dimension. |
64
|
num_layers |
int
|
Number of layers. |
2
|
slow_network_layers |
int
|
Number of slow network layers. |
3
|
slow_network_units |
int
|
Number of units in slow network. |
128
|
preprocessing_model |
Model | None
|
Preprocessing model. |
None
|
name |
str | None
|
Name of the model. |
None
|
**kwargs |
Any
|
Additional keyword arguments. |
{}
|
Functions
from_config
classmethod
from_config(config)
Creates a model from its configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
dict[str, Any]
|
Dictionary containing the model configuration. |
required |
Returns:
Type | Description |
---|---|
SFNEBlock
|
A new instance of the model. |
🎭 TerminatorModel
Comprehensive tabular model that combines multiple SFNE blocks for complex data tasks.
kmr.models.TerminatorModel
This module implements a TerminatorModel that combines multiple SFNE blocks for advanced feature processing. It's designed for complex tabular data modeling tasks.
Classes
TerminatorModel
TerminatorModel(
input_dim,
context_dim,
output_dim,
hidden_dim=64,
num_layers=2,
num_blocks=3,
slow_network_layers=3,
slow_network_units=128,
preprocessing_model=None,
name=None,
**kwargs
)
Terminator model for advanced feature processing.
This model stacks multiple SFNE blocks to process features in a hierarchical manner. It's designed for complex tabular data modeling tasks where feature interactions are important.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
int
|
Dimension of the input features. |
required |
context_dim |
int
|
Dimension of the context features. |
required |
output_dim |
int
|
Dimension of the output. |
required |
hidden_dim |
int
|
Number of hidden units in the network. Default is 64. |
64
|
num_layers |
int
|
Number of layers in the network. Default is 2. |
2
|
num_blocks |
int
|
Number of SFNE blocks to stack. Default is 3. |
3
|
slow_network_layers |
int
|
Number of layers in each slow network. Default is 3. |
3
|
slow_network_units |
int
|
Number of units per layer in each slow network. Default is 128. |
128
|
preprocessing_model |
Model | None
|
Optional preprocessing model to apply before the main processing. |
None
|
name |
str | None
|
Optional name for the model. |
None
|
Input shape
List of 2D tensors with shapes: [(batch_size, input_dim), (batch_size, context_dim)]
Output shape
2D tensor with shape: (batch_size, output_dim)
Example
import keras
from kmr.models import TerminatorModel
# Create sample input data
x = keras.random.normal((32, 16)) # 32 samples, 16 features
context = keras.random.normal((32, 8)) # 32 samples, 8 context features
# Create the model
terminator = TerminatorModel(input_dim=16, context_dim=8, output_dim=1)
y = terminator([x, context])
print("Output shape:", y.shape) # (32, 1)
Initialize the TerminatorModel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dim |
int
|
Input dimension. |
required |
context_dim |
int
|
Context dimension. |
required |
output_dim |
int
|
Output dimension. |
required |
hidden_dim |
int
|
Hidden dimension. |
64
|
num_layers |
int
|
Number of layers. |
2
|
num_blocks |
int
|
Number of blocks. |
3
|
slow_network_layers |
int
|
Number of slow network layers. |
3
|
slow_network_units |
int
|
Number of units in slow network. |
128
|
preprocessing_model |
Model | None
|
Preprocessing model. |
None
|
name |
str | None
|
Name of the model. |
None
|
**kwargs |
Any
|
Additional keyword arguments. |
{}
|
Functions
from_config
classmethod
from_config(config)
Creates a model from its configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
dict[str, Any]
|
Dictionary containing the model configuration. |
required |
Returns:
Type | Description |
---|---|
TerminatorModel
|
A new instance of the model. |
🔧 Base Classes
🏛️ BaseModel
Base class for all KMR models, providing common functionality and Keras 3 compatibility.
kmr.models._base.BaseModel
Functions
inspect_signatures
inspect_signatures(model)
Inspect the model signatures.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
write your description |
required | |
model |
Model
|
write your description |
required |