Skip to main content

ALReLU activation package for Keras with fixed and trainable alpha variants.

Project description

alrelu-keras

PyPI-installable Keras package for the ALReLU activation with 2 variants:

  1. ALReLU (default): current behavior from this project, with fixed alpha=0.01.
  2. TrainableALReLU: same formula with trainable alpha.

Formula used by both variants:

ALReLU(x, alpha) = max(abs(alpha * x), x)

Installation

After publishing:

pip install alrelu-keras

Keras requires a backend. For the common TensorFlow backend:

pip install alrelu-keras[tensorflow]

From source:

pip install .

Usage

1) Default ALReLU (current implementation behavior)

import keras
from alrelu_keras import ALReLU, alrelu

# As activation function
x = keras.ops.array([-2.0, -1.0, 0.0, 1.0], dtype="float32")
y = alrelu(x)  # alpha=0.01 by default

# As Keras layer
model = keras.Sequential(
    [
        keras.layers.Input(shape=(32,)),
        keras.layers.Dense(64),
        ALReLU(),  # fixed alpha
        keras.layers.Dense(10),
    ]
)

2) Trainable alpha variant

import keras
from alrelu_keras import TrainableALReLU

model = keras.Sequential(
    [
        keras.layers.Input(shape=(32,)),
        keras.layers.Dense(64),
        TrainableALReLU(alpha_initializer=0.01),  # alpha is trainable
        keras.layers.Dense(10),
    ]
)

Serialization / model loading

Both ALReLU, TrainableALReLU, and alrelu are registered as Keras-serializable objects. You can save/load models without manually passing custom_objects in standard Keras workflows.

Development

Install dev tools:

pip install -e .[dev]

Run tests:

pytest

Build package:

python -m build

License

MIT License. See 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

alrelu_keras-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

alrelu_keras-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file alrelu_keras-0.1.0.tar.gz.

File metadata

  • Download URL: alrelu_keras-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for alrelu_keras-0.1.0.tar.gz
Algorithm Hash digest
SHA256 160cc6d8a4011e560fb0c13aa7433059886cfd4b4f1afb55b9e8871f161cc5dd
MD5 3a2a218b1e3dc1ef66854c9e12497f76
BLAKE2b-256 ca6958e6bb6f2ec32bdf627edfbf0b579e9da2370ca73281c369a284bd0b56c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for alrelu_keras-0.1.0.tar.gz:

Publisher: publish-keras.yml on MStamatis/ALReLU

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alrelu_keras-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: alrelu_keras-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for alrelu_keras-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc732007f33b082d29d9079d766c3f67956bb5c9bee14938f24ae1ce50062d75
MD5 224d53a8b4a46f392d4720207c4d4f2b
BLAKE2b-256 47552c8ea935a346760a9707eb60e3386f3ccce32efd8ba2cb77638f22f265b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for alrelu_keras-0.1.0-py3-none-any.whl:

Publisher: publish-keras.yml on MStamatis/ALReLU

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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