File size: 2,392 Bytes
19b0465
288f3fd
19b0465
288f3fd
 
 
 
 
 
 
457482e
 
19b0465
288f3fd
 
 
 
 
 
 
 
 
789388d
288f3fd
 
 
 
 
49c979f
288f3fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49c979f
 
 
 
 
c72a313
288f3fd
c72a313
 
 
288f3fd
c72a313
 
 
 
288f3fd
c72a313
 
 
 
 
 
 
 
 
 
288f3fd
44604e6
49c979f
288f3fd
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
language: en
license: mit
tags:
- pytorch
- regression
- dot-product
- bilinear-networks
metrics:
- loss
pipeline_tag: tabular-regression

---

# SBL-NET (Scalar Bilinear Linear Network)

A hybrid PyTorch neural network designed to **highly accurately compute the scalar (dot) product** of split sub-vectors without any data normalization (Z-score, etc.).

## 🔬 Architecture & Features

The main highlight of this model is the integration of a rare **bilinear layer (`nn.Bilinear`)** at the input stage, combined with classic fully connected layers (`nn.Linear`) and the `SELU` activation function.
* The network accepts an input tensor of shape `[batch, 4]` and splits it into two vectors: `A [batch, 2]` and `B [batch, 2]`.
* The bilinear layer efficiently extracts cross-features between the vectors, allowing the model to reduce the error to an impressive **0.185%**.

## 📊 Training Results

* **Loss Function:** Smooth L1 Loss
* **Optimizer:** Adam (with StepLR scheduler)
* **Error Rate:** ~0.185%
* **Extreme Test Case:** 
  * Input: `[[-6.0, 70.0, 4.0, -196.0]]`
  * Expected Mathematical Answer: `-13744.0000`
  * Actual Network Prediction: `-13769.5225`

## 🧮 Model Statistics

* **Total Parameters:** 52,101
* **Trainable Parameters:** 52,101
* **Non-trainable Parameters:** 0
* **Model Size:** ~208 KB (Weights in FP32)
* **Input Shape:** `[batch_size, 4]`
* **Output Shape:** `[batch_size, 1]`

## 💻 How to Use

You can download the architecture file and the model weights directly from this repository:

```python
import torch as t
import torch.nn as nn
import torch.optim as opt
from torch.utils.data import DataLoader, Dataset

class WebAISC(nn.Module):

    def __init__(self):
        super().__init__()
        self.bilinear = nn.Bilinear(in1_features=2, in2_features=2, out_features=250)

        self.x2 = nn.Linear(250, 100)
        self.x3 = nn.Linear(100, 250)
        self.x4 = nn.Linear(250, 1)
        self.selu = nn.SELU()

    def forward(self, x):
        a = x[:, 0:2]
        b = x[:, 2:4]

        x = self.selu(self.bilinear(a, b))

        x = self.selu(self.x2(x))
        x = self.selu(self.x3(x))
        x = self.x4(x)
        return x

model = WebAISC()

test_input = t.tensor([[-6.0, 70.0, 4.0, -196.0]], dtype=t.float32)
with t.no_grad():
    prediction = model(test_input)
    print(f"Model prediction: {prediction.item():.4f}")
```