<jupyter_start><jupyter_text>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][kai].The original paper can be found [here](https://arxiv.org/abs/1706.01427).[kai]: https://github.com/pytorch/pytorch/pull/2105[nbdev]: https://nbdev.fast.ai  Install `pip install relational`  How to use This can be used to implement a relational network in PyTorch. An example would be something like:<jupyter_code>from relational.core import relation
import torch
import torch.nn as nn
#hide
_ = torch.manual_seed(0)
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()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10748560460652591, 'fraction_numerical': 0.014075495841330775, 'mean_word_length': 2.9494949494949494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '152471', 'license': 'Apache-2.0', 'n_tokens_mistral': 500, 'n_tokens_neox': 474, 'n_words': 149, 'path': 'index.ipynb', 'repo_name': 'gngdb/relational', 'size': '1563'}