Skip to main content

🌟 KerasFactory - Reusable Model Architecture Bricks in Keras 🌟

KerasFactory Logo

Provided and maintained by 🦄 UnicoLab

Python 3.10+ Keras 3.8+ License: MIT Code style: black 🦄 UnicoLab Documentation

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.

✨ Key Features

  • 🎯 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

🚀 Quick Start

Installation

# Install from PyPI
poetry add kerasfactory

# Or install from source
git clone https://github.com/UnicoLab/KerasFactory
cd KerasFactory
poetry install

🚀 Quick Start Examples

Example 1: Smart Data Preprocessing

import 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.")

Example 2: Intelligent Feature Fusion

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.")

Example 3: Ready-to-Use Models

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.")

Example 4: Date Feature Engineering

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.")

🧠 Smart Data Analyzer

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!")

🏗️ Architecture Overview

Core Components

Layers (kerasfactory.layers)

  • 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

Models (kerasfactory.models)

  • SFNEBlock: Advanced feature processing block
  • TerminatorModel: Multi-block hierarchical processing model

Utilities (kerasfactory.utils)

  • Data Analyzer: Intelligent CSV analysis and layer recommendation system
  • CLI Tools: Command-line interface for data analysis

Experimental (experimental/)

  • 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

📖 Documentation

🎯 Common Use Cases

📊 Tabular Data Processing

from kerasfactory.layers import DistributionTransformLayer, GatedFeatureFusion

# Smart preprocessing
preprocessor = DistributionTransformLayer(transform_type='auto')

# Feature combination
fusion = GatedFeatureFusion()

🔧 Feature Engineering

from kerasfactory.layers import DateEncodingLayer, BusinessRulesLayer

# Date features
date_encoder = DateEncodingLayer()

# Business rules validation
rules = BusinessRulesLayer(
    rules=[(">", 0), ("<", 100)], 
    feature_type="numerical"
)

🎨 Advanced Architectures

from kerasfactory.layers import StochasticDepth, GatedResidualNetwork

# Regularization
stochastic_depth = StochasticDepth(survival_prob=0.8)

# Advanced processing
grn = GatedResidualNetwork(units=64)

🧪 Testing

# Run all tests
make all_tests

# Run specific test categories
make unittests
make data_analyzer_tests

# Generate coverage report
make coverage

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# 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_tests

Commit Convention

We use semantic commit messages:

  • feat(KerasFactory): add new layer for feature processing
  • fix(KerasFactory): resolve serialization issue
  • docs(KerasFactory): update installation guide

📊 Performance

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

💬 Join Our Community

Have questions or want to connect with other KDP users? Join us on Discord:

Discord

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built with Keras 3
  • Inspired by modern deep learning research
  • Community-driven development

📞 Support


Built with ❤️ for the Keras community by 🦄 UnicoLab.ai

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kerasfactory-0.1.1.tar.gz (116.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kerasfactory-0.1.1-py3-none-any.whl (175.4 kB view details)

Uploaded Python 3

File details

Details for the file kerasfactory-0.1.1.tar.gz.

File metadata

  • Download URL: kerasfactory-0.1.1.tar.gz
  • Upload date:
  • Size: 116.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.14 Linux/6.11.0-1018-azure

File hashes

Hashes for kerasfactory-0.1.1.tar.gz
Algorithm Hash digest
SHA256 36e4d4ce170a9f130d135280ac1dff9eda511c75e94278fd2df19faea924d34d
MD5 052df7ee36b0e42b06da44ea95c4695f
BLAKE2b-256 ae428bd67f5688318a21ebd4b4b955d2375847803c9dcfc39c555e4d152cb36f

See more details on using hashes here.

File details

Details for the file kerasfactory-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kerasfactory-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 175.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.14 Linux/6.11.0-1018-azure

File hashes

Hashes for kerasfactory-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fc9a0218df94474900ad46a778a072d24d19742da1efcf5d54ff3d9539d8983b
MD5 3aa40bf543ead29493b26064b7b73a78
BLAKE2b-256 c7418aa98b36b47c4127678247f23251b1c993fd45674c04e4b5c2ea086123fa

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page