Skip to main content

Probabilistic programming using pytorch.

Project description

Borch

pipeline status coverage report lifecycle Code style: black docs

Getting Started | Documentation | Contributing

Borch is a universal probabilistic programming language (PPL) framework developed by Desupervised, that uses and integrates with PyTorch. Borch was designed with special attention to support Bayesian neural networks in a native fashion. Further, it's designed to

  • Flexible and scalable framework
  • Support neural networks out of the box.
  • Have bells and whistles a universal PPL needs.

It can be installed with

pip install borch

Usage

See our full tutorials here.

As a quick example let's look into how the neural network interface looks. The module borch.nn provides implementations of neural network modules that are used for deep probabilistic programming and provides an interface almost identical to the torch.nn modules. In many cases it is possible to just switch

import torch.nn as nn

to

import borch.nn as nn

and a network defined in torch is now probabilistic, without any other changes in the model specification, one also need to change the loss function to infer.vi.vi_loss.

For example, a convolutional neural network can be written as

import torch
import torch.nn.functional as F
from borch import nn

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(1, 6, 5)
        self.conv2 = nn.Conv2d(6, 16, 5)
        self.fc1 = nn.Linear(16 * 5 * 5, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)

    def forward(self, x):
        x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))
        x = F.max_pool2d(F.relu(self.conv2(x)), 2)
        x = x.view(-1, self.num_flat_features(x))
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x

    def num_flat_features(self, x):
        size = x.size()[1:]
        num_features = 1
        for s in size:
            num_features *= s
        return num_features

Installation

Borch can be installed using

pip install borch

Docker

The Borch Docker images are available as both CPU and GPU versions at gitlab.com/desupervised/borch/container_registry. The latest CPU images can be used as

docker run registry.gitlab.com/desupervised/borch/cpu:master

Contributing

Please read the contribution guidelines in CONTRIBUTING.md.

Citation

If you use this software for your research or business please cite us and help the package grow!

@misc{borch,
  author = {Belcher, Lewis and Gudmundsson, Johan and Green, Michael},
  title = {Borch},
  howpublished = {https://gitlab.com/desupervised/borch},
  month        = "Apr",
  year         = "2021",
  note         = "v0.1.0",
  annote       = ""
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

borch-0.1.2.tar.gz (65.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

borch-0.1.2-py3-none-any.whl (81.6 kB view details)

Uploaded Python 3

File details

Details for the file borch-0.1.2.tar.gz.

File metadata

  • Download URL: borch-0.1.2.tar.gz
  • Upload date:
  • Size: 65.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for borch-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b39f0b369aa1e430b82fdbde37c50ae851e3b2f92ea755cb0a952fe1467f2649
MD5 beb91ea0e35703911606745f533ca5fd
BLAKE2b-256 10c0d54711e746df02075a9c8fc7f1d65bb704e5a9180b4f1e2ea67033c4ea58

See more details on using hashes here.

File details

Details for the file borch-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: borch-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 81.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for borch-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 560505dac795344b8890275374942ce34fdf86b8b28100c7b0a142892afaefbd
MD5 76ab9c0f9d5ee1b904ccdcdee6750b62
BLAKE2b-256 8f2027ba0aa2ea2027c8d424592664256c26b811e8234dc519b6aae9917d5f79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page