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. Huge thanks to contributors klae01 and fedebotu who made big improvments to the code.
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 animation:
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.1.tar.gz
.
File metadata
- Download URL: torch-snake-1.0.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39f7e45fd1f3b3752d4eab995a468b96d810f8027c6b437f35754866996c9b7d |
|
MD5 | f622a73a4055b83c1f489dd7e6862a8e |
|
BLAKE2b-256 | b820a670d5b6f2dbdf73172e94a20f1bb571428e8350440fe234f12dfab536a4 |
File details
Details for the file torch_snake-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: torch_snake-1.0.1-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 | 742f12ce366b83a298f7900ae7d8f9981d6c33055a74b51cce825db5939127bd |
|
MD5 | e99c805b3b45325af95ed2ccc67b122d |
|
BLAKE2b-256 | 41ae978c594aa63a08ccb36880102dc277de51e830614507aeeaa56b2d29ed2c |