https://github.com/wesselb/neuralprocesses
A framework for composing Neural Processes in Python
https://github.com/wesselb/neuralprocesses
machine-learning meta-learning neural-processes
Last synced: about 1 year ago
JSON representation
A framework for composing Neural Processes in Python
- Host: GitHub
- URL: https://github.com/wesselb/neuralprocesses
- Owner: wesselb
- License: mit
- Created: 2020-12-22T16:25:33.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-17T21:08:13.000Z (over 1 year ago)
- Last Synced: 2025-03-28T10:05:06.474Z (about 1 year ago)
- Topics: machine-learning, meta-learning, neural-processes
- Language: Python
- Homepage: https://wesselb.github.io/neuralprocesses
- Size: 8 MB
- Stars: 82
- Watchers: 4
- Forks: 15
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# [Neural Processes](http://github.com/wesselb/neuralprocesses)
[](https://github.com/wesselb/neuralprocesses/actions?query=workflow%3ACI)
[](https://coveralls.io/github/wesselb/neuralprocesses?branch=master)
[](https://wesselb.github.io/neuralprocesses)
[](https://github.com/psf/black)
A framework for composing Neural Processes in Python.
## Installation
```
pip install neuralprocesses tensorflow tensorflow-probability # For use with TensorFlow
pip install neuralprocesses torch # For use with PyTorch
```
If something is not working or unclear, please feel free to open an issue.
## Documentation
See [here](https://wesselb.github.io/neuralprocesses).
## TL;DR! Just Get me Started!
Here you go:
```python
import torch
import neuralprocesses.torch as nps
# Construct a ConvCNP.
convcnp = nps.construct_convgnp(dim_x=1, dim_y=2, likelihood="het")
# Construct optimiser.
opt = torch.optim.Adam(convcnp.parameters(), 1e-3)
# Training: optimise the model for 32 batches.
for _ in range(32):
# Sample a batch of new context and target sets. Replace this with your data. The
# shapes are `(batch_size, dimensionality, num_data)`.
xc = torch.randn(16, 1, 10) # Context inputs
yc = torch.randn(16, 2, 10) # Context outputs
xt = torch.randn(16, 1, 15) # Target inputs
yt = torch.randn(16, 2, 15) # Target output
# Compute the loss and update the model parameters.
loss = -torch.mean(nps.loglik(convcnp, xc, yc, xt, yt, normalise=True))
opt.zero_grad(set_to_none=True)
loss.backward()
opt.step()
# Testing: make some predictions.
mean, var, noiseless_samples, noisy_samples = nps.predict(
convcnp,
torch.randn(16, 1, 10), # Context inputs
torch.randn(16, 2, 10), # Context outputs
torch.randn(16, 1, 15), # Target inputs
)
```