Provided and maintained by π¦ UnicoLab
KerasFactory is a comprehensive collection of reusable Keras layers and models specifically designed for tabular data processing, feature engineering, and advanced neural network architectures. Built with Keras 3 and developed by π¦ UnicoLab, it provides a clean, efficient, and extensible foundation for building sophisticated machine learning models for enterprise AI applications.
- π― 38+ Production-Ready Layers: Attention mechanisms, feature processing, preprocessing, and specialized architectures
- π§ Advanced Models: SFNE blocks, Terminator models, and more coming soon
- π Data Analyzer: Intelligent CSV analysis tool that recommends appropriate layers
- π¬ Experimental Modules: 20+ cutting-edge layers and models for research
- β‘ Keras 3 Only: Pure Keras 3 implementation with no TensorFlow dependencies
- π§ͺ Comprehensive Testing: Full test coverage with 38+ test suites
- π Rich Documentation: Detailed guides, examples, and API documentation
# Install from PyPI
poetry add kerasfactory
# Or install from source
git clone https://github.com/UnicoLab/KerasFactory
cd KerasFactory
poetry installimport keras
from kerasfactory.layers import DistributionTransformLayer
# Create a simple model with automatic data transformation
inputs = keras.Input(shape=(10,)) # 10 numerical features
# Automatically transform data to normal distribution
transformed = DistributionTransformLayer(transform_type='auto')(inputs)
# Simple neural network
x = keras.layers.Dense(64, activation='relu')(transformed)
x = keras.layers.Dropout(0.2)(x)
outputs = keras.layers.Dense(1, activation='sigmoid')(x)
model = keras.Model(inputs=inputs, outputs=outputs)
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
print("Model ready! The layer will automatically choose the best transformation for your data.")import keras
from kerasfactory.layers import GatedFeatureFusion
# Create two different representations of your data
inputs = keras.Input(shape=(8,)) # 8 features
# First representation: linear processing
linear_features = keras.layers.Dense(16, activation='relu')(inputs)
# Second representation: non-linear processing
nonlinear_features = keras.layers.Dense(16, activation='tanh')(inputs)
# Intelligently combine both representations
fused_features = GatedFeatureFusion()([linear_features, nonlinear_features])
# Final prediction
outputs = keras.layers.Dense(1, activation='sigmoid')(fused_features)
model = keras.Model(inputs=inputs, outputs=outputs)
model.compile(optimizer='adam', loss='binary_crossentropy')
print("Smart feature fusion model ready! The layer learns which representation to trust more.")import keras
from kerasfactory.models import BaseFeedForwardModel
# Create a complete model with just one line!
model = BaseFeedForwardModel(
feature_names=['age', 'income', 'education', 'experience'],
hidden_units=[64, 32, 16],
output_units=1,
dropout_rate=0.2
)
# Your data (each feature as separate input)
age = keras.random.normal((100, 1))
income = keras.random.normal((100, 1))
education = keras.random.normal((100, 1))
experience = keras.random.normal((100, 1))
# Train with one command
model.compile(optimizer='adam', loss='mse')
model.fit([age, income, education, experience],
keras.random.normal((100, 1)),
epochs=10, verbose=0)
print("β
Model trained successfully! No complex setup needed.")import keras
from kerasfactory.layers import DateEncodingLayer
# Create a model that processes date information
inputs = keras.Input(shape=(4,)) # [year, month, day, day_of_week]
# Convert dates to cyclical features automatically
date_features = DateEncodingLayer()(inputs)
# Simple prediction model
x = keras.layers.Dense(32, activation='relu')(date_features)
outputs = keras.layers.Dense(1, activation='sigmoid')(x)
model = keras.Model(inputs=inputs, outputs=outputs)
model.compile(optimizer='adam', loss='binary_crossentropy')
print("π
Date-aware model ready! Handles seasonality and cyclical patterns automatically.")from kerasfactory.utils import analyze_data
# Get intelligent recommendations for your data
results = analyze_data("your_data.csv")
recommendations = results["recommendations"]
print("π― Recommended layers for your data:")
for layer in recommendations:
print(f" β’ {layer['layer_name']}: {layer['description']}")
print("β¨ No more guessing which layers to use!")- Attention Mechanisms:
TabularAttention,MultiResolutionTabularAttention,ColumnAttention,RowAttention - Feature Processing:
AdvancedNumericalEmbedding,GatedFeatureFusion,VariableSelection - Preprocessing:
DateEncodingLayer,DateParsingLayer,DifferentiableTabularPreprocessor - Advanced Architectures:
TransformerBlock,GatedResidualNetwork,BoostingBlock - Specialized Layers:
BusinessRulesLayer,StochasticDepth,FeatureCutout
- SFNEBlock: Advanced feature processing block
- TerminatorModel: Multi-block hierarchical processing model
- Data Analyzer: Intelligent CSV analysis and layer recommendation system
- CLI Tools: Command-line interface for data analysis
- Time Series: 12+ specialized time series preprocessing layers
- Advanced Models: Neural Additive Models, Temporal Fusion Transformers, and more
- Research Components: Cutting-edge architectures for experimentation
- Note: Experimental components are not included in the PyPI package
- Online Documentation: Full API reference with automatic docstring generation
- API Reference: Complete documentation for all layers, models, and utilities
- Layer Implementation Guide: Comprehensive guide for implementing new layers
- Data Analyzer Documentation: Complete guide to the data analysis tools
- Contributing Guide: How to contribute to the project
from kerasfactory.layers import DistributionTransformLayer, GatedFeatureFusion
# Smart preprocessing
preprocessor = DistributionTransformLayer(transform_type='auto')
# Feature combination
fusion = GatedFeatureFusion()from kerasfactory.layers import DateEncodingLayer, BusinessRulesLayer
# Date features
date_encoder = DateEncodingLayer()
# Business rules validation
rules = BusinessRulesLayer(
rules=[(">", 0), ("<", 100)],
feature_type="numerical"
)from kerasfactory.layers import StochasticDepth, GatedResidualNetwork
# Regularization
stochastic_depth = StochasticDepth(survival_prob=0.8)
# Advanced processing
grn = GatedResidualNetwork(units=64)# Run all tests
make all_tests
# Run specific test categories
make unittests
make data_analyzer_tests
# Generate coverage report
make coverageWe welcome contributions! Please see our Contributing Guide for details.
# Clone the repository
git clone https://github.com/UnicoLab/KerasFactory.git
cd KerasFactory
# Install development dependencies
poetry install
# Install pre-commit hooks
pre-commit install
# Run tests
make all_testsWe use semantic commit messages:
feat(KerasFactory): add new layer for feature processingfix(KerasFactory): resolve serialization issuedocs(KerasFactory): update installation guide
KerasFactory is optimized for performance with:
- Keras 3 Backend: Leverages the latest Keras optimizations
- Efficient Operations: Uses only Keras operations for maximum compatibility
- Memory Optimization: Careful memory management in complex layers
- Batch Processing: Optimized for batch operations
Have questions or want to connect with other KDP users? Join us on Discord:
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Keras 3
- Inspired by modern deep learning research
- Community-driven development
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Online Docs
- Discord:
Built with β€οΈ for the Keras community by π¦ UnicoLab.ai