Downloads ยท 30 days
0
ALEXFLR/SQRTAI
SQRTAI is a machine learning model from ALEXFLR. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Downloads ยท 30 days
0
Access
Public
Updated Sep 21, 2026
Repo size
9 MB
Likes
1
Public
Click a slice to open those files.
.pth9 MB ยท 100%
From the Hugging Face model README
A PyTorch neural network trained to approximate the complex square root of real numbers.
The model receives a real number and predicts the real and imaginary components of its square root.
SQRTAI is a fully connected neural network built with PyTorch.
1 real value2 values [real, imag]GELUSmoothL1LossAdamW0.00132300Input (1)
โ
Linear(1 โ 750)
โ
GELU
โ
Linear(750 โ 1500)
โ
GELU
โ
Linear(1500 โ 750)
โ
GELU
โ
Linear(750 โ 2)
โ
[Real, Imaginary]
The model approximates:
โx = real + imagยทi
Examples:
โ100 โ 10 + 0i
โ25 โ 5 + 0i
โ-100 โ 0 + 10i
โ-25 โ 0 + 5i
The model was trained on integer values in the range:
[-2500, 2499]
The targets were generated using PyTorch complex numbers:
complex_x = x.to(torch.complex64)
complex_y = torch.sqrt(complex_x)
The real and imaginary parts were then stored as two separate target values.
Example predictions from the trained model:
| Input | SQRTAI | True |
|---|---|---|
-1000 | 0.0013 + 31.6555i | 0 + 31.6228i |
-100 | 0.0014 + 9.9772i | 0 + 10.0000i |
-25 | 0.0067 + 5.1357i | 0 + 5.0000i |
-4 | -0.0819 + 2.6917i | 0 + 2.0000i |
-1 | 0.3614 + 1.2544i | 0 + 1.0000i |
0 | 0.5484 + 0.8187i | 0 + 0i |
1 | 0.9438 + 0.4106i | 1.0000 + 0i |
4 | 2.1236 - 0.0022i | 2.0000 + 0i |
25 | 4.9417 - 0.0021i | 5.0000 + 0i |
100 | 10.0111 + 0.0040i | 10.0000 + 0i |
1000 | 31.7295 - 0.0045i | 31.6228 + 0i |
The model is an approximation, not an exact mathematical calculator.
The largest errors in the current model appear around the origin, especially at:
x = -1
x = 0
x = 1
For example:
x = -1
AI โ 0.3614 + 1.2544i
True โ 0 + 1i
x = 0
AI โ 0.5484 + 0.8187i
True โ 0 + 0i
x = 1
AI โ 0.9438 + 0.4106i
True โ 1 + 0i
This means SQRTAI does not accurately reproduce the square-root function near x = 0.
For larger absolute input values, the approximation becomes significantly closer to the mathematical result.
1 โ 750 โ 1500 โ 750 โ 22,255,2522,255,2520~8.6 MiBimport torch as t
import torch.nn as nn
class SQRTAI(nn.Module):
def __init__(self):
super().__init__()
self.l1 = nn.Linear(1, 750)
self.l2 = nn.Linear(750, 1500)
self.l3 = nn.Linear(1500, 750)
self.l4 = nn.Linear(750, 2)
self.gelu = nn.GELU()
def forward(self, x):
x = self.gelu(self.l1(x))
x = self.gelu(self.l2(x))
x = self.gelu(self.l3(x))
x = self.l4(x)
return x
device = t.device("cuda" if t.cuda.is_available() else "cpu")
model = SQRTAI().to(device)
model.load_state_dict(
t.load("SQRTAI.pth", map_location=device)
)
model.eval()
x_value = 100.0
with t.no_grad():
x = t.tensor(
[[x_value]],
dtype=t.float32
).to(device)
prediction = model(x)
real = prediction[0, 0].item()
imag = prediction[0, 1].item()
print(f"SQRTAI: {real:.4f} + {imag:.4f}i")
Input:
100
SQRTAI:
10.0111 + 0.0040i
True:
10.0000 + 0i
The trained weights are stored in:
SQRTAI.pth
Possible future versions could improve accuracy around x โ 0, increase the training dataset, and investigate alternative architectures or training strategies.
In this work, I am not attempting to replace a calculator. This is a research project aimed at investigating whether a standard MLP can solve a problem involving complex numbers in the context of square roots.
Made with PyTorch ๐ฅ