Skip to main content

A Minimal Relational Function

PyTorch/Numpy agnostic function implementing the relational block from "A simple neural network module for relational reasoning".

I wrote this to learn how to use nbdev. I'm pretty sure it's correct but it only implements the core function for using relational networks and none of the other stuff (such as nn.Module classes etc) that Kai included in the pull request.

The original paper can be found here.

Install

pip install relational

How to use

This can be used to implement a relational network in PyTorch. An example would be something like:

from relational.core import relation
import torch
import torch.nn as nn
class SetNet(nn.Module):
    def __init__(self, datadim, n_hidden):
        super(SetNet, self).__init__()
        self.n_hidden = n_hidden
        self.g = nn.Sequential(nn.Linear(datadim*2, n_hidden), 
                               nn.ReLU(),
                               nn.Linear(n_hidden, n_hidden))
        self.f = nn.Sequential(nn.Linear(n_hidden, n_hidden),
                               nn.ReLU(),
                               nn.Linear(n_hidden, n_hidden))

    def forward(self, x):
        n, t, d = x.size()
        x = relation(x, self.g, reduction='mean')
        return self.f(x)
x = torch.randn(4, 8, 16)
setnet = SetNet(x.size(2), 10)
setnet(x).size()
torch.Size([4, 10])

Metadata

Release files for relational 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for relational 0.0.1
File Size Uploaded
relational-0.0.1.tar.gz 10.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for relational 0.0.1
File Interpreter ABI Platform
relational-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / relational-0.0.1.tar.gz

Download URL relational-0.0.1.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7d59d45465b39380ed1b6f4a5c272aa9c5f32fa59cf7c9615eacfa1334be704f
BLAKE2b-256 checksum
How to use checksums
06a1124e6f45d9a88c8168fef64ed54b0d40131eebb075106a18c0420d4d5a27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Release files / relational-0.0.1-py3-none-any.whl

Download URL relational-0.0.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
888003da117b268c1acd13dec8a0d1ad267165994a542f79cd64c28ca3e919f0
BLAKE2b-256 checksum
How to use checksums
c808846dd4f44b192b7d473e8d2002b6aa680b387fe3ba640038aec2c09620bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page