Path Signature in Pure Keras
Project description
keras_sig: Easy Path Signature in Keras
A backend-agnostic Keras implementation of path signature computations, focusing on simplicity and ease of integration.
Overview
keras_sig provides path signature computations as a Keras layer. It aims to offer:
- Native Keras implementation supporting all backends (JAX, PyTorch, TensorFlow)
- Simple integration within Keras models
- Pure Python implementation avoiding C++ dependencies
- Consistent API across different backends
The package builds upon several key projects in the signature computation ecosystem:
Historical Context
- iisignature (repo): The foundational C++ implementation providing highly optimized signature computations
- signatory (repo): A PyTorch-specific implementation using C++ level optimizations
- iisignature-tensorflow-2 (repo): An attempt at wrapping iisignature for TensorFlow 2, which faced limitations with model compilation
- signax (repo): A breakthrough pure JAX implementation showing that C++ optimization could be avoided
- keras_sig (this package): Bringing the pure Python approach to all Keras backends
Installation
pip install keras_sig
Or install from source:
git clone https://github.com/yourusername/keras_sig
cd keras_sig
pip install -e .
Quick Start
import keras
from keras_sig import SigLayer
# Create a model with signature computation
model = keras.Sequential([
keras.layers.Input(shape=(timesteps, features)),
SigLayer(depth=3, stream=False),
keras.layers.Dense(output_dim)
])
# Use it like any other Keras layer
model.compile(optimizer='adam', loss='mse')
model.fit(x_train, y_train, epochs=10)
Performance Considerations
Backend-Specific Performance
- JAX: Best performance and most stable for compilation
- PyTorch: Good performance at simple forward pass, compilation often fails but works fine without (but is much slower than JAX)
- TensorFlow: Bad performance at simple forward pass, but is able to compile and run with JIT (so will ran quicker than torch, but slower than JAX) - main issue is that due to the non-ability to use keras.ops.scan in tensorflow the loop unrolling is not handled directly and for long sequence the compilation can be very problematic. For long sequence go to jax..
For raw forward pass computation:
- Faster than iisignature for big batch/sequence sizes, a bit slower for small sizes
- Slower than signax (due to signax's pure JAX JIT compilation and possible use of GPU, while keras only compile at train time), but similar to it when it is at train time
Training Performance
When integrated in training loops:
- Comparable efficiency to signax in JAX with compatibility with all backend
- JIT compilation available during training
- Seamless integration with Keras training features
Features
Currently implements:
- Standard signature computations
- Support for both streaming and non-streaming modes
- Configurable signature depth
- Backend-agnostic implementation
Not yet implemented (available in other packages):
- Log signatures
- Lyndon words
- Other advanced signature computations
Citations
If using this package, please cite both this work and the foundational packages that inspired it:
@article{reizenstein2017iisignature,
title={iisignature: A python package for computing iterated-integral signatures},
author={Reizenstein, Jeremy},
journal={Journal of Open Source Software},
volume={2},
number={10},
pages={189},
year={2017}
}
@article{kidger2021signatory,
title={Signatory: differentiable computations of the signature and logsignature transforms, on both CPU and GPU},
author={Kidger, Patrick and Lyons, Terry},
journal={International Conference on Learning Representations},
year={2021}
}
@software{signax2023github,
author = {Anh Tong},
title = {signax: Path Signatures in JAX},
url = {https://github.com/anh-tong/signax},
year = {2023},
}
@misc{genet2023iisignaturetf2,
author = {Remi Genet, Hugo Inzirillo},
title = {iisignature-tensorflow-2: TensorFlow 2 Wrapper for iisignature},
url = {https://github.com/remigenet/iisignature-tensorflow-2},
year = {2023},
}
Contributing
Contributions are welcome! Feel free to submit issues and pull requests.
Would you like me to adjust any section or add more details?
Shield:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keras_sig-0.1.2.tar.gz.
File metadata
- Download URL: keras_sig-0.1.2.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.2 Linux/6.8.0-48-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7aff39a17c0101210f26d503508d2fab7b8c1ff6dba352c6a31eabaaae6a042
|
|
| MD5 |
ce589a4e3a73e7875be42194351ea3a6
|
|
| BLAKE2b-256 |
28accfcbea1b34673b080a2a4a47b6279c70ec49503ba21ffce632b0ffc2226d
|
File details
Details for the file keras_sig-0.1.2-py3-none-any.whl.
File metadata
- Download URL: keras_sig-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.2 Linux/6.8.0-48-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
178be850e8a83a76787307fa06d1976e467a7b30e843b7fb639cb5b795fb14db
|
|
| MD5 |
5254a269840c6ee289ba7dced51f9ccc
|
|
| BLAKE2b-256 |
1f027a2253fb94fecaa1959a5542392d8fe509d58ea910526914ab35db47b6f9
|