Views
No views yet
| A | B | C |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |

import torch
import torch.nn as nn
from huggingface_hub import PyTorchModelHubMixin
# Let's create two column vectors containing `0`s and `1`s.
batch = {'a': torch.tensor([[0], [0], [1], [1]]), 'b': torch.tensor([[0], [1], [0], [1]])}
class OR(nn.Module, PyTorchModelHubMixin):
def __init__(self):
super().__init__()
self.operation = "C = A OR B"
def forward(self, x):
a = x['a']
b = x['b']
inputs = torch.cat([a, a, b, b], axis=1)
column_sum = torch.sum(inputs, dim=1, keepdim=True)
output = (column_sum >= 2).long()
return output
# Instantiate:
logical_or = OR.from_pretrained("sadhaklal/or")
# Forward pass:
output = logical_or(batch)
print(output)