Skip to main content

Nami

Official Repository for Nami — an adaptive activation function with built-in strong regularization capabilities.


Wave

Nami means "wave" in Japanese — the name comes from its wavy nature in the negative domain. Unlike typical activation functions that tend to a single value, Nami oscillates due to the sin function. It combines this oscillation with the smoothness of tanh. The behavior is controlled by three learnable parameters: w, a, and b.


Install

pip install nami-act

Usage

# for torch
from nami import Torch.Nami
nami_torch = Torch.Nami()

# for tensorflow
from nami import TF.Nami
nami_tf = TF.Nami()

# for jax there are two modules 
# one is nami function another is Nami object for Haiku
# if someone uses flax they can simply wrap the functional
# module with flax.nn.Module

from nami.JAX import nami, Nami 

Compatible:

PyTorch
TensorFlow
Jax (needs some fixes)

Plots:

Nami vs Others:

  • Nami consistently leads in high-impact learning phases (e.g., around LR drops), emphasizing its adaptability.
  • This resilience is not observed in traditional activations that either saturate early or destabilize under aggressive scheduling.
nami_vs_others

Derivative of Nami:

  • Nami’s derivative exhibits a non-monotonic, softly saturating profile—a design that diversifies gradient propagation and avoids neuron inactivation.
  • Its flexible form enables localized feature modulation, especially beneficial in deep architectures where gradient dynamics are critical.
derivative of nami

Here is a quick comparison of Nami, Swish and Mish with the same weight initialization on ResNet-18, on CIFAR-10, More Detailed and complex tests are here benchmarks

def seed_everything(seed=42):
    import random, os
    import numpy as np
    import torch

    random.seed(seed)
    os.environ["PYTHONHASHSEED"] = str(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)

    torch.backends.cudnn.deterministic = True
    torch.backends.cudnn.benchmark = False
    torch.use_deterministic_algorithms(True, warn_only=True)

seed_everything(42)

Ran the training for 200 epochs and Nami showed very stable losses troughout the training and especially in the later epochs and that is because of tanh(x * a) in the positive and a * sin(x * w) / b in the negative domain. It has learnable parameters w, a, b, which demand longer runs to learn deeper and complex information from the data.

  • w is responsible for maintaining the wave-length, the smaller it is the smoother the gradients are.

  • a regulates the spikes of the waves, high waves can capture deeper information, but if it rises too much, it may cause overfitting — that’s where b comes into the picture.

  • b tackles overfitting by supressing a's dominance, and increases generalization.

nami eq

Here is a sample benchmark on Resnet18:

Nami

Nami: Validation Accuracy 94.81, Training Loss 0.0015, Validation Loss 0.1963


Mish

Mish: Validation Accuracy 94.09, Training Loss 0.0032, Validation Loss 0.2424


Swish

Swish/SiLU: Validation Accuracy 94.06, Training Loss 0.0024, Validation Loss 0.2347


In conclusion, Nami beats Mish and Swish in both generalization and accuracy! Nami is suitable for Larger and Deeper Networks. And also; for shallow Neural Networks it captures more complex information than any other activation. Despite having three trainable parameters, its computational cost remains minimal — and the convergence is outstanding. For more detailed experiments visit benchmarks.


"I'd love to see ML folks fine-tune LLMs or train deep models using Nami, you can share the stats with me here: Gmail, X


Thanks for your support :)

Metadata

Release files for nami-act 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nami-act 1.1.1
File Size Uploaded
nami_act-1.1.1.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nami-act 1.1.1
File Interpreter ABI Platform
nami_act-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / nami_act-1.1.1.tar.gz

Download URL nami_act-1.1.1.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
dec08d5ab3081d872b7624354d0a72a94a636a3804024d9ddc7dc5d10d53a620
BLAKE2b-256 checksum
How to use checksums
77ed0c484517d9a11b658f42ad4642754053a19eaeaeb48e16496e818bf71c0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / nami_act-1.1.1-py3-none-any.whl

Download URL nami_act-1.1.1-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
342a13d954a39c4e836a2e970795d4c458062a15cc0f0bface7cde5e2c964123
BLAKE2b-256 checksum
How to use checksums
d97bf476b2bcb8793f34f6ecabc4031b143a1ab4c3dd0d18673348f947df7716
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page