Practical overview
When it fits
Use Sonnet when a TensorFlow 2 project needs modular neural-network components and flexibility over the training framework, rather than a prescriptive end-to-end training stack.
Who it is for
- Python machine-learning researchers
- TensorFlow developers building custom neural networks
- Teams creating supervised, unsupervised or reinforcement-learning experiments
Documented uses
- Compose neural networks from reusable built-in modules.
- Define custom modules by subclassing `snt.Module`.
- Prototype supervised and unsupervised learning models.
- Assemble reinforcement-learning research models.
- Access model variables for an externally selected optimizer or training system.
Requirements & limits
The repository is public, open source and licensed under Apache-2.0. The documented setup uses Python package installation with TensorFlow, TensorFlow Probability and dm-sonnet. Colab examples are provided for trying the library in a notebook environment.
- Sonnet is centered on
snt.Module, which supports nested modules, parameters and callable computations. - Built-in modules include linear, convolutional, batch-normalization and sequential components.
- The library does not ship with a training framework, so the surrounding optimization and training workflow must come from the developer or another system.
- Many parameters are created when a module is first called because their shapes depend on the input.
- The repository includes examples for MNIST, GANs and distributed CIFAR-10 workflows.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install Sonnet and verify the Python environment
Set up the documented TensorFlow 2 and Sonnet dependencies, then check that both packages import and report versions.
Before you start
- Python environment
- TensorFlow 2
- TensorFlow Probability
- The dm-sonnet package
Steps
Install TensorFlow and TensorFlow Probability with pip.
Install the dm-sonnet package with pip.
Import TensorFlow and Sonnet.
Print the TensorFlow and Sonnet version values.
Expected outcome
The environment reports imported TensorFlow and Sonnet version values.
Guide limitations
- This recipe verifies package installation and imports only; it does not train or deploy a model.
- The source does not specify a supported Python version or hardware requirement.
Compose an MLP from Sonnet modules
Define and call a simple multilayer perceptron using the documented Sonnet and TensorFlow pattern.
Before you start
- Installed TensorFlow 2 and Sonnet
- A Python program or notebook
- An input tensor with the dimensions expected by the model
Steps
Create an
snt.Sequentialcontainingsnt.Linear(1024),tf.nn.reluandsnt.Linear(10).Call the sequential module with a TensorFlow input tensor.
Retrieve
trainable_variableswhen the model parameters need to be passed to an optimizer.
Expected outcome
The composed module produces a logits tensor and exposes its trainable variables.
Guide limitations
- Sonnet does not provide the training loop or optimizer workflow in this example.
- Parameter creation commonly occurs on the first call, so input shape affects initialization.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 2 October 2026
- Original website title
- google-deepmind/sonnet · Official homepage title · retained in its source language

