This repository contains notebook implementations of the following Neural Process variants: Conditional Neural Processes (CNPs), Neural Processes (NPs), Attentive Neural Processes (ANPs).

Overview

The Neural Process Family

This repository contains notebook implementations of the following Neural Process variants:

  • Conditional Neural Processes (CNPs)
  • Neural Processes (NPs)
  • Attentive Neural Processes (ANPs)

The code for CNPs can be found in conditional_neural_process.ipynb while the code for both NPs and ANPs is located in attentive_neural_process.ipynb.

The notebooks include an overview of the different building blocks of the models as well as the code to run each model in the browser. Any further details can be found in the CNP paper, the NP paper and the ANP paper.

Quick run

The easiest way to run the code is to run it in the browser on Colab. Here below are the links to each of the notebooks in Colab:

Colaboratory is a free Jupyter notebook environment provided by Google that requires no setup and runs entirely in the cloud. The hosted runtime already includes the following dependencies, tested on the following versions in brackets:

  • Numpy (1.14.6)
  • Tensorflow (1.13.1)
  • Matplotlib (2.2.4)

which are all we need to run the code in this repository.

Alternatively, you can open the .ipynb files using Jupyter notebook. If you do this you will also have to set up a local kernel that includes Tensorflow.

Citing CNPs

If you like our work and end up using neural processes for your reseach give us a shout-out:

  1. Conditional Neural Processes: Garnelo M, Rosenbaum D, Maddison CJ, Ramalho T, Saxton D, Shanahan M, Teh YW, Rezende DJ, Eslami SM. Conditional Neural Processes. In International Conference on Machine Learning 2018.

  2. Neural Processes: Garnelo, M., Schwarz, J., Rosenbaum, D., Viola, F., Rezende, D.J., Eslami, S.M. and Teh, Y.W. Neural processes. ICML Workshop on Theoretical Foundations and Applications of Deep Generative Models 2018.

  3. Attentive Neural Processes: Kim, H., Mnih, A., Schwarz, J., Garnelo, M., Eslami, A., Rosenbaum, D., Vinyals, O. and Teh, Y.W. Attentive Neural Processes. In International Conference on Learning Representations 2019.

Contact

Any feedback is much appreciated! Drop us a line at [email protected] (Conditional Neural Process) or [email protected] ((Attentive) Neural Process).

Disclaimer

This is not an official Google product.

Comments
  • Question for latent encoder of attentive neural processes script

    Question for latent encoder of attentive neural processes script

    Hi,

    First of all, thank you for opening your great script!

    I have a question about latent encoder.

    In your code, posterior and prior use same latent encoder. Exactly using same (x,y) pair encoder is no problem, but the linear layers to sample the latent variable would be different functions for prior and posterior I think.

    If my understanding about the code is wrong, then could I know which point I missed?

    Thanks.

    Best Regards, Jaesik Yoon.

    opened by jsikyoon 2
  • Latent Encoder and Decoder: log_sigma transformation

    Latent Encoder and Decoder: log_sigma transformation

    Hi,

    I was wondering what the reasoning behind the specific parameterizations of the standard deviation in the latent encoder is, i.e. why is it bounded? I usually just use a softplus in such settings.

    Also, they are different between the encoder and decoder, not sure if that is intentional. I'd assume both should be with tf.sigmoid?

    (Latent) Encoder: Bounds SD between 0.1 and 1

        # Compute sigma
        sigma = 0.1 + 0.9 * tf.sigmoid(log_sigma)
    

    Decoder: Bounds SD to be higher than 0.1 and...?

        # Bound the variance
        sigma = 0.1 + 0.9 * tf.nn.softplus(log_sigma)
    

    And thank you for that well-documented repository :).

    opened by FabricioArendTorres 1
  • package version control

    package version control

    1. For the latest version of matplotlib, set_facecolor rather than set_axis_bgcolor should be used in plot_functions?
    2. We should move TensorFlow Distributions to TensorFlow Probability?
    3. It might be better to add information about package versions in the documentation?
    opened by jinxu06 1
  • Reuse error

    Reuse error

    When I run the 'attentive_neural_process.ipynb', I got the mistakes as follows:

    ValueError: Variable layer_3/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

    File "", line 28, in batch_mlp output, output_sizes[-1], name="layer_{}".format(i + 1)) File "", line 31, in call hidden = batch_mlp(encoder_input, self._output_sizes, "latent_encoder") File "", line 58, in call prior = self._latent_encoder(context_x, context_y)

    opened by Spider-scnu 1
  • NP implementation in ANP

    NP implementation in ANP

    I think NP implementation in ANP is a little bit different with NP paper. right?

    In original NP, there is the only latent encoder and latent encoder uses context and target data, while implementation has concated features of latent and deterministic and latent encoder uses only context data.

    opened by JuHyung-Son 1
  • Notebook: Select TensorFlow 1.x in Google Colab

    Notebook: Select TensorFlow 1.x in Google Colab

    By default, Colab will use TensorFlow 2.x as of now, this results in failed execution of cells. By specifying the %tensorflow_version magic, Colab uses the specified TensorFlow version.

    opened by rodrigobdz 2
  • Lack of variability of ANP result

    Lack of variability of ANP result

    So here are two results (two columns) of ANP after 50000+ iterations. The first row is the default plot and the plots in the second row contains 16 samples of the curve (given same context x & y). And the red curve is the mean of these 16 curves. As we can see, there has very limited variation. image

    This is true also for NP. However, if I set use_deterministic_path=False, the variation start to emerge: image

    My guess is that during training the decoder only prefer the deterministic path and just ignore the latent path. Then no matter what latent code is delivered the output won't change much. What's your opinion?

    opened by QhelDIV 0
  • Minor edit of comments in attentive_neural_process.ipynb.

    Minor edit of comments in attentive_neural_process.ipynb.

    Comments on sampling from either prior (during testing) or the posterior (during training) are swapped.

    "Note that targets contain contexts by design" -> is this is referring to how the latent encoder had previously been run on the contexts, rather than the targets themselves actually containing contexts?

    Thanks!

    opened by christabella 3
  • Demo for classification experiment

    Demo for classification experiment

    Hello, I don't know if this is the right forum to ask.....

    Is there a available demo on the one-shot classification using the Omniglot dataset presented in section 4.3 of the paper. I am unable to understand how you combined the different channels of convolutional output to compute the statistics and combine it with test image to perform classification?

    opened by Jamesswiz 0
Owner
DeepMind
DeepMind
StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

StudioGAN is a Pytorch library providing implementations of representative Generative Adversarial Networks (GANs) for conditional/unconditional image generation.

null 3k Jan 8, 2023
This repository contains the implementations related to the experiments of a set of publicly available datasets that are used in the time series forecasting research space.

TSForecasting This repository contains the implementations related to the experiments of a set of publicly available datasets that are used in the tim

Rakshitha Godahewa 80 Dec 30, 2022
This repository contains the data and code for the paper "Diverse Text Generation via Variational Encoder-Decoder Models with Gaussian Process Priors" (SPNLP@ACL2022)

GP-VAE This repository provides datasets and code for preprocessing, training and testing models for the paper: Diverse Text Generation via Variationa

Wanyu Du 18 Dec 29, 2022
Implementation of Restricted Boltzmann Machine (RBM) and its variants in Tensorflow

xRBM Library Implementation of Restricted Boltzmann Machine (RBM) and its variants in Tensorflow Installation Using pip: pip install xrbm Examples Tut

Omid Alemi 55 Dec 29, 2022
Network Pruning That Matters: A Case Study on Retraining Variants (ICLR 2021)

Network Pruning That Matters: A Case Study on Retraining Variants (ICLR 2021)

Duong H. Le 18 Jun 13, 2022
The Medical Detection Toolkit contains 2D + 3D implementations of prevalent object detectors such as Mask R-CNN, Retina Net, Retina U-Net, as well as a training and inference framework focused on dealing with medical images.

The Medical Detection Toolkit contains 2D + 3D implementations of prevalent object detectors such as Mask R-CNN, Retina Net, Retina U-Net, as well as a training and inference framework focused on dealing with medical images.

MIC-DKFZ 1.2k Jan 4, 2023
This repo contains the official implementations of EigenDamage: Structured Pruning in the Kronecker-Factored Eigenbasis

EigenDamage: Structured Pruning in the Kronecker-Factored Eigenbasis This repo contains the official implementations of EigenDamage: Structured Prunin

Chaoqi Wang 107 Apr 20, 2022
code for "AttentiveNAS Improving Neural Architecture Search via Attentive Sampling"

code for "AttentiveNAS Improving Neural Architecture Search via Attentive Sampling"

Facebook Research 94 Oct 26, 2022
This repository holds the code for the paper "Deep Conditional Gaussian Mixture Model forConstrained Clustering".

Deep Conditional Gaussian Mixture Model for Constrained Clustering. This repository holds the code for the paper Deep Conditional Gaussian Mixture Mod

null 17 Oct 30, 2022
Repository of Jupyter notebook tutorials for teaching the Deep Learning Course at the University of Amsterdam (MSc AI), Fall 2020

Repository of Jupyter notebook tutorials for teaching the Deep Learning Course at the University of Amsterdam (MSc AI), Fall 2020

Phillip Lippe 1.1k Jan 7, 2023
Re-implementation of the Noise Contrastive Estimation algorithm for pyTorch, following "Noise-contrastive estimation: A new estimation principle for unnormalized statistical models." (Gutmann and Hyvarinen, AISTATS 2010)

Noise Contrastive Estimation for pyTorch Overview This repository contains a re-implementation of the Noise Contrastive Estimation algorithm, implemen

Denis Emelin 42 Nov 24, 2022
ByteTrack with ReID module following the paradigm of FairMOT, tracking strategy is borrowed from FairMOT/JDE.

ByteTrack_ReID ByteTrack is the SOTA tracker in MOT benchmarks with strong detector YOLOX and a simple association strategy only based on motion infor

Han GuangXin 46 Dec 29, 2022
Code for the paper "How Attentive are Graph Attention Networks?"

How Attentive are Graph Attention Networks? This repository is the official implementation of How Attentive are Graph Attention Networks?. The PyTorch

null 175 Dec 29, 2022
Scalable Attentive Sentence-Pair Modeling via Distilled Sentence Embedding (AAAI 2020) - PyTorch Implementation

Scalable Attentive Sentence-Pair Modeling via Distilled Sentence Embedding PyTorch implementation for the Scalable Attentive Sentence-Pair Modeling vi

Microsoft 25 Dec 2, 2022
Dynamic Attentive Graph Learning for Image Restoration, ICCV2021 [PyTorch Code]

Dynamic Attentive Graph Learning for Image Restoration This repository is for GATIR introduced in the following paper: Chong Mou, Jian Zhang, Zhuoyuan

Jian Zhang 84 Dec 9, 2022
A Structured Self-attentive Sentence Embedding

Structured Self-attentive sentence embeddings Implementation for the paper A Structured Self-Attentive Sentence Embedding, which was published in ICLR

Kaushal Shetty 488 Nov 28, 2022
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context Code in both PyTorch and TensorFlow

Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context This repository contains the code in both PyTorch and TensorFlow for our paper

Zhilin Yang 3.3k Jan 6, 2023
The first public PyTorch implementation of Attentive Recurrent Comparators

arc-pytorch PyTorch implementation of Attentive Recurrent Comparators by Shyam et al. A blog explaining Attentive Recurrent Comparators Visualizing At

Sanyam Agarwal 150 Oct 14, 2022