+0
日增长
9,977
stars
1,305
forks
405
watchers
115
prs
193
issues
4
releases
README
!Sonnet
Sonnet
Documentation | Examples
Sonnet is a library built on top of TensorFlow 2
designed to provide simple, composable abstractions for machine learning
research.
Introduction
Sonnet has been designed and built by researchers at DeepMind. It can be used to
construct neural networks for many different purposes (un/supervised learning,
reinforcement learning, ...). We find it is a successful abstraction for our
organization, you might too!
More specifically, Sonnet provides a simple but powerful programming model
centered around a single concept: snt.Module. Modules can hold references to
parameters, other modules and methods that apply some function on the user
input. Sonnet ships with many predefined modules (e.g. snt.Linear,
snt.Conv2D, snt.BatchNorm) and some predefined networks of modules (e.g.
snt.nets.MLP) but users are also encouraged to build their own modules.
Unlike many frameworks Sonnet is extremely unopinionated about how you will
use your modules. Modules are designed to be self contained and entirely
decoupled from one another. Sonnet does not ship with a training framework and
users are encouraged to build their own or adopt those built by others.
Sonnet is also designed to be simple to understand, our code is (hopefully!)
clear and focussed. Where we have picked defaults (e.g. defaults for initial
parameter values) we try to point out why.
Getting Started
Examples
The easiest way to try Sonnet is to use Google Colab which offers a free Python
notebook attached to a GPU or TPU.
- Predicting MNIST with an MLP
- Training a Little GAN on MNIST
- Distributed training with snt.distribute
Installation
To get started install TensorFlow 2.0 and Sonnet 2:
shell
$ pip install tensorflow tensorflow-probability
$ pip install dm-sonnet
You can run the following to verify things installed correctly:
python
import tensorflow as tf
import sonnet as snt
print("TensorFlow version {}".format(tf.__version__))
print("Sonnet version {}".format(snt.__version__))
Using existing modules
Sonnet ships with a number of built in modules that you can trivially use. For
example to define an MLP we can use the snt.Sequential module to call a
sequence of modules, passing the output of a given module as the input for the
next module. We can use snt.Linear and tf.nn.relu to actually define our
computation:
python
mlp = snt.Sequential([
snt.Linear(1024),
tf.nn.relu,
snt.Linear(10),
])
To use our module we need to "call" it. The Sequential module (and most
modules) define a __call__ method that means you can call them by name:
python
logits = mlp(tf.random.normal([batch_size, input_size]))
It is also very common to request all the parameters for your module. Most
modules in Sonnet create their parameters the first time they are called with
some input (since in most cases the shape of the parameters is a function of
the input). Sonnet modules provide two properties for accessing parameters.
The variables property Top issues
#271sonnet abstract module in tensorflow2 10 comments · 2023-09-30#246Cannot install sonnet on mac m15 comments · 2022-06-20#198VQ-VAE training example(v2) returned NAN loss4 comments · 2021-02-13#161v2: `dynamic_unroll` using `lstm_with_recurrent_dropout` doesn't work4 comments · 2020-02-22#261Issues using Sonnet3 comments · 2023-01-16#233Spectral Normalisation for ConvND Layers3 comments · 2022-03-04#193Is there any convenient way to do spectrum normalization? (Sonnet version: 2.0.0)3 comments · 2020-11-12#156The test TrainableStateTest.testForCore fails consistently3 comments · 2020-01-27
Latest release
v2.0.2 v2.0.2 2024-01-02Sonnet 2 is a re-write of Sonnet for TensorFlow 2.0, it is built on top of tf.Module (https://github.com/tensorflow/community/pull/56) enabling a simple and researcher friendly interface to TensorFlow. Main changes since 2.0.1: What's Changed 267 Fixes use of internal TF symbol removed in a minor release <= 2.10.0. (Fixes 273) Full Changelog: https://github.com/google-deepmind/sonnet/compare/v2.0.1...v2.0.2