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 .
Metadata
Release files for torch-snake 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| torch-snake-1.0.1.tar.gz | 4.8 kB | Without provenance | Details for torch-snake-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torch_snake-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for torch_snake-1.0.1-py3-none-any.whl |
Total release size: 9.9 kB
Release files / torch-snake-1.0.1.tar.gz
| Download URL | torch-snake-1.0.1.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39f7e45fd1f3b3752d4eab995a468b96d810f8027c6b437f35754866996c9b7d
|
|
BLAKE2b-256 checksum How to use checksums |
b820a670d5b6f2dbdf73172e94a20f1bb571428e8350440fe234f12dfab536a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.13
|
Release files / torch_snake-1.0.1-py3-none-any.whl
| Download URL | torch_snake-1.0.1-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
742f12ce366b83a298f7900ae7d8f9981d6c33055a74b51cce825db5939127bd
|
|
BLAKE2b-256 checksum How to use checksums |
41ae978c594aa63a08ccb36880102dc277de51e830614507aeeaa56b2d29ed2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.13
|
Security for torch-snake 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.