Skip to main content

Sample PyTorch implementation of the snake activation function

Project description

PyPI version

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:

snake activation function gets wriggly for higher a

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. It has also benefitted hugely from generous contributions by Federico Berto.

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

torch-snake-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

torch_snake-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file torch-snake-0.1.0.tar.gz.

File metadata

  • Download URL: torch-snake-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for torch-snake-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5f50ef46005c77302a9789a7bd9d13035764cb90ae09bb622db027d38af7b4f5
MD5 245e89ff4e3ac8f54b96c93a74cbff79
BLAKE2b-256 f3510c712e1370a03b1e763572559e139f5a48f1b08e191321bda38269b2e90b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torch_snake-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for torch_snake-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba980e572ed46dc518dc891757031388ec5e8e11c1804f4227706584ae1c03a7
MD5 499d40fb3373f336a62445b0f5553f51
BLAKE2b-256 0b27822972993a106f3e88aabff013efe6d296563ec9e3bcc89d21ab16acf3db

See more details on using hashes here.

Supported by

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