Advanced Feature Processing Model with Stacked SFNE Blocks
Overview
TerminatorModel combines multiple SFNE (Slow-Fast Neural Engine) blocks for advanced feature processing. It's designed for complex tabular data modeling tasks where feature interactions are important. The model stacks multiple SFNE blocks to process features in a hierarchical manner, enabling deep feature interactions and complex pattern learning.
Key Features
Stacked Architecture: Multiple SFNE blocks for hierarchical feature processing
Dual Input Support: Handles both input features and context features
Deep Feature Interactions: Enables complex feature relationship learning
Flexible Configuration: Configurable number of blocks and network dimensions
Preprocessing Integration: Optional preprocessing model support
Production Ready: Supports unified training/inference pipelines
Parameters
input_dim (int): Dimension of the input features. Must be positive.
context_dim (int): Dimension of the context features. Must be positive.
output_dim (int): Dimension of the output. Must be positive.
hidden_dim (int, default=64): Number of hidden units in the network.
num_layers (int, default=2): Number of layers in each SFNE block.
num_blocks (int, default=3): Number of SFNE blocks to stack.
slow_network_layers (int, default=3): Number of layers in each slow network.
slow_network_units (int, default=128): Number of units per layer in each slow network.
Input:
- List of 2D tensors: [(batch_size, input_dim), (batch_size, context_dim)]
- Or dictionary with feature inputs when using preprocessing model
- Type: Float32
# Small modelsmall_model=TerminatorModel(input_dim=16,context_dim=8,output_dim=1,hidden_dim=32,num_layers=1,num_blocks=2,slow_network_layers=2,slow_network_units=64)# Large modellarge_model=TerminatorModel(input_dim=16,context_dim=8,output_dim=1,hidden_dim=128,num_layers=3,num_blocks=5,slow_network_layers=4,slow_network_units=256)
With Preprocessing Model
1 2 3 4 5 6 7 8 9101112131415161718192021
fromkerasfactory.utils.data_analyzerimportDataAnalyzerimportpandasaspd# Create preprocessing model for both inputsdf_input=pd.DataFrame(np.random.randn(100,16))df_context=pd.DataFrame(np.random.randn(100,8))analyzer_input=DataAnalyzer(df_input)analyzer_context=DataAnalyzer(df_context)preprocessing_model_input=analyzer_input.create_preprocessing_model()preprocessing_model_context=analyzer_context.create_preprocessing_model()# Note: You may need to combine preprocessing models or use separate models# This is a simplified examplemodel=TerminatorModel(input_dim=16,context_dim=8,output_dim=1,preprocessing_model=preprocessing_model_input# Simplified)
Regression Task
1 2 3 4 5 6 7 8 91011121314
# Regression with multiple outputsmodel_regression=TerminatorModel(input_dim=16,context_dim=8,output_dim=3,# Multiple outputshidden_dim=64,num_blocks=3)model_regression.compile(optimizer='adam',loss='mse',metrics=['mae','mse'])
# Save modelmodel.save('terminator_model.keras')# Load modelloaded_model=keras.models.load_model('terminator_model.keras')# Save weights onlymodel.save_weights('terminator_weights.h5')# Load weightsmodel_new=TerminatorModel(input_dim=16,context_dim=8,output_dim=1)model_new.load_weights('terminator_weights.h5')
Best Use Cases
Complex Tabular Data: When feature interactions are important
Dual Input Scenarios: When you have both main features and context features
Deep Feature Learning: When you need hierarchical feature processing
High-Dimensional Data: When you need to learn complex feature relationships
Production Systems: With preprocessing model integration
Performance Considerations
num_blocks: More blocks enable deeper feature interactions but increase computation
hidden_dim: Larger values improve capacity but increase parameters
num_layers: More layers per block can learn complex patterns but may overfit
slow_network_units: Larger values improve hyper-kernel quality but increase parameters
input_dim/context_dim: Match your data dimensions
Architecture Details
Stacked SFNE Blocks: Each block processes features hierarchically
Dual Input: Separate processing for input and context features
Hierarchical Processing: Features flow through multiple processing stages