{"id":22378010,"url":"https://github.com/tonywu71/neural-processes","last_synced_at":"2026-05-18T02:05:40.538Z","repository":{"id":65761997,"uuid":"598154708","full_name":"tonywu71/neural-processes","owner":"tonywu71","description":"Replication of the \"Conditional Neural Processes\" (2018) and \"Neural Processes\" (2018) papers by Garnelo et al.","archived":false,"fork":false,"pushed_at":"2023-03-28T07:28:04.000Z","size":17713,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T07:49:10.845Z","etag":null,"topics":["bayesian","conditional-neural-processes","gaussian-processes","machine-learning","neural-processes","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tonywu71.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-06T14:17:40.000Z","updated_at":"2024-02-15T02:43:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"2bc91d33-2607-40d1-92fd-927551183cc4","html_url":"https://github.com/tonywu71/neural-processes","commit_stats":null,"previous_names":["tonywu71/neural-processes","tonywu71/conditional-neural-processes"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tonywu71/neural-processes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonywu71%2Fneural-processes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonywu71%2Fneural-processes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonywu71%2Fneural-processes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonywu71%2Fneural-processes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tonywu71","download_url":"https://codeload.github.com/tonywu71/neural-processes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonywu71%2Fneural-processes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273933745,"owners_count":25193599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian","conditional-neural-processes","gaussian-processes","machine-learning","neural-processes","tensorflow"],"created_at":"2024-12-04T22:16:48.193Z","updated_at":"2026-05-18T02:05:35.498Z","avatar_url":"https://github.com/tonywu71.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Neural Processes\nReplication of the *Conditional Neural Processes* paper by Marta Garnelo et al., 2018 [[arXiv](https://arxiv.org/abs/1807.01613)] and the *Neural Processes* paper by Marta Garnelo et al, 2018 [[arXiv](https://arxiv.org/abs/1807.01622)]. The model and data pipeline were implemented using Tensorflow 2.10.\n\nCode released in complement of the [report](https://github.com/tonywu71/conditional-neural-processes/blob/b90eb9ecf18cebaa7bcae8dcbf0bc573f987b112/report/MLMI4_CNP_LNP_report.pdf) and the [poster](https://github.com/tonywu71/conditional-neural-processes/blob/b90eb9ecf18cebaa7bcae8dcbf0bc573f987b112/report/MLMI4_CNP_LNP_poster.pdf).\n\n\n\nProject for the Advanced Machine Learning module, MPhil in MLMI, University of Cambridge.\n\nWilliam Baker, Alexandra Shaw, Tony Wu\n\n\n\n## 1. Introduction\n\nWhile neural networks excel at function approximation, Gaussian Processes (GPs) address different challenges such as uncertainty prediction, continuous learning, and the ability to deal with data scarcity. Therefore, each model is only suited for a restricted spectrum of tasks that strongly depends on the nature of available data.\n\nNeural Processes use neural networks to encode distributions over functions to approximate the dis- tributions over functions given by stochastic processes like GPs. This allows for efficient inference and scalability to large datasets. The performance of these models will be evaluated on 1D-regression and image completion to demonstrate visually how they learn distributions over complex functions.\n\n\n\n![np_poster_diagram](figs/1-introduction/np_poster_diagram.png)\n\n\u003cp align = \"center\"\u003e \u003cb\u003eFigure 1: Comparison between Gaussian Process, Neural Network and Neural Process\u003c/b\u003e\u003c/p\u003e\n\n\n\n## 2. Instructions\n\n1. Using an environment with `python 3.10.8`, install modules using:\n\n   ```\n   pip install -r requirements.txt\n   ```\n\n2. To create, train, and evaluate instances of neural processes, run the `train.py` script. Use `python train.py --help` to display its arguments. In particular, specify the `--model` flag with `CNP`, `HNP`, `LNP`, or `HNPC` to choose the used model. Example:\n\n   ```bash\n   python train.py --task regression --model cnp --epochs 50 --batch 128\n   ```\n\n3. The model will be saved in the `checkpoints` directory.\n\n\n\n## 2. Data pipeline\n\n![data_pipeline](figs/2-data_pipeline/data_pipeline.png)\n\n\u003cp align = \"center\"\u003e \u003cb\u003eFigure 2: Data pipeline and examples of generated data for Neural Processes\u003c/b\u003e\u003c/p\u003e\n\nContrarily to neural networks which predict functions, NPs predict **distributions** of functions. For this reason, we have built a specific data loader class using the `tf.data` API to produce the examples for both training and validation. Note that the class definitions for data generators can be found in the `dataloader` module directory.\n\n\n\n## 3. Models\n\n![architecture](figs/3-models/architecture.png)\n\n\u003cp align = \"center\"\u003e \u003cb\u003eFigure 3: Architecture diagram of CNP, LNP, and HNP\u003c/b\u003e\u003c/p\u003e\n\nCNP, LNP and HNP all have a similar encoder-decoder architecture. They have been implemented using classes that inherit from `tf.keras.Model`. Thus, training with the `tf.data` API is straightforward and optimized.\n\n\n\n## 4. Experiments\nTraining can either be conducted in a interactive session (iPython) with arguments set in the section beginning ln 40 (Training parameters). Or by commenting section ln40 and uncommenting section ln 25 (Parse Training parameters) the terminal and it's cmd arguments can be used.\n\n### 4.1. Regression training\n\n```bash\npython train.py --task regression\n```\n\n**Example of obtained result:**\n\n![1d_regression-fixed_kernel](figs/4-experiments/1d_regression-fixed_kernel.jpeg)\n\n\u003cp align = \"center\"\u003e \u003cb\u003eFigure 4: Comparison between GP, CNP and LNP on the 1D-regression task (fixed kernel parameter)\u003c/b\u003e\u003c/p\u003e\n\n\n\n### 4.2. MNIST training\n\n```bash\npython train.py --task mnist\n```\n\n**Example of obtained result:**\n\n![mnist-image_completion](figs/4-experiments/mnist-image_completion.png)\n\n\u003cp align = \"center\"\u003e \u003cb\u003eFigure 5: : CNP pixel mean and variance predictions on images from MNIST\u003c/b\u003e\u003c/p\u003e\n\n\n\n### 4.3. CelebA training\n\n**Instructions:** Download the aligned and cropped images from [here](https://mmlab.ie.cuhk.edu.hk/projects/CelebA.html) and extract files in the  `./data` directory.\n\n```bash\npython train.py --task celeb\n```\n\n**Example of obtained result:**\n\n![celebA-image_completion](figs/4-experiments/celebA-image_completion.jpg)\n\n\u003cp align = \"center\"\u003e \u003cb\u003eFigure 6: CNP pixel mean and variance predictions on images from CelebA\u003c/b\u003e\u003c/p\u003e\n\n\n\n### 4.4. Extension: HNP and HNPC\n\n**Objective:** Combine the deterministic link between the context representations (used by CNP) with the non-deterministic link from the latent space representation space (used by LNP) to produce a model with a richer embedding space.\n\n![extension-hnp_hnpc](figs/4-experiments/extension-hnp_hnpc.png)\n\n\u003cp align = \"center\"\u003e \u003cb\u003eFigure 7: Latent Variable Distribution - Mean and Standard Deviation Statistics during training.\u003c/b\u003e\u003c/p\u003e\n\n\n\n## 5. Appendix\n\nTo go further, read the poster and the report that can be found in the `report` folder of this repository.\n\n\u003cimg src=\"report/poster-thumbnail.jpg\" alt=\"poster-thumbnail\" style=\"zoom: 33%;\" /\u003e\n\n\u003cp align = \"center\"\u003e \u003cb\u003eFigure 8: Miniature of the CNP/LNP poster\u003c/b\u003e\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonywu71%2Fneural-processes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftonywu71%2Fneural-processes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonywu71%2Fneural-processes/lists"}