Sample PyTorch implementation of the snake activation function
Project description
Snake
Based on "Neural Networks Fail to Learn Periodic Functions and How to Fix It" by Liu Ziyin, Tilman Hartwig, Masahito Ueda
This is a PyTorch implementation of the snake
activation function from the paper - or at least I think it is, no affiliation with the authors, use at your own risk, etc., etc.
A few variations of the function are discussed in the paper, this package implements:
Snake is periodic, but also monotonic. To see how snake behaves for a range of x given various choices of a
, watch this video:
Installation
Two methods:
- Using pip,
pip install torch-snake
- To install from source, first clone this repository. Then, from the main repo folder, run
python setup.py install
Usage
Fairly easy really from snake.activations import Snake
. The Snake
constructor (code here) has an optional learnable parameter alpha which defaults to 1. The authors of the paper find values between 5 and 50 work quite well for "known-periodic" data, while for better results with non-periodic data, you should choose a small value like 0.2. The constructor also takes an alpha_learnable
parameter which defaults to True
, so that you can disable "learnability" if your experiments so require.
Sample code
There's a notebook, still quite rough - example.ipynb. Early indications are that good choices of hyperparameters are quite important for best results (though snake's own parameter trains quite readily).
Acknowledgements
This code probably wouldn't have gotten written if it hadn't been for Alexandra Deis and her excellent article .
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
File details
Details for the file torch-snake-1.0.0.tar.gz
.
File metadata
- Download URL: torch-snake-1.0.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2de62e73209e9fd3b79f8ab5b2395b28009c475353079c3470c8771edb94b081 |
|
MD5 | bc5e196a53db506ce43c94888b31b6ad |
|
BLAKE2b-256 | 4bb42e459ebb24458e6cb1db8be997fdd0e46edeb9a33854feff75e010dcc73f |
File details
Details for the file torch_snake-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: torch_snake-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88a4b4ec8ed0ef202eb1df6b85bf9860cb0f7b38b76b8263fab6e6234071622d |
|
MD5 | 731e5c4c02658081952abf2e14f6e963 |
|
BLAKE2b-256 | a60cba096c324389fd202f7f6388f55bb10906d8de81c090024e93e4acc9e96b |