Single YatNMN Neuron Model for the XOR Problem
This repository contains a PyTorch model with a single, non-linear YatNMN neuron that has been trained on the XOR dataset.
Model Description
This model demonstrates that the XOR problem can be solved by a single neuron, provided the neuron is sufficiently complex. Unlike a standard nn.Linear layer, which is a linear operator, this model uses a YatNMN neuron from the nmn library.
The YatNMN neuron is an inherently non-linear operator inspired by physical inverse-square laws, allowing it to learn the non-linear decision boundary required to solve XOR.
Training Results
- Final Loss: 0.3466
- Accuracy: 100.00%
With sufficient training using the Adam optimizer, the model achieves 100% accuracy, correctly learning the XOR function. This contrasts with a standard single neuron, which typically stalls at 50% or 75% accuracy.
How to Use
import torch
import torch.nn as nn
# Make sure to install the nmn library: pip install nmn
from nmn.torch.nmn import YatNMN
# Define the model architecture
class SingleNonLinearNeuron(nn.Module):
def __init__(self, input_size, output_size):
super(SingleNonLinearNeuron, self).__init__()
self.non_linear = YatNMN(input_size, output_size, bias=False)
def forward(self, x):
return self.non_linear(x)
# Instantiate the model and load the weights from the hub
# Note: You'll need to have huggingface_hub installed
from huggingface_hub import hf_hub_download
model = SingleNonLinearNeuron(input_size=2, output_size=1)
model_path = hf_hub_download(repo_id="mlnomad/xor-single-nmn-neuron", filename="xor-single-nmn-neuron-model.pth")
model.load_state_dict(torch.load(model_path))
model.eval()
# Example prediction
input_data = torch.tensor([[1.0, 1.0]]) # Expected XOR output: 0
with torch.no_grad():
logits = model(input_data)
prob = torch.sigmoid(logits)
prediction = (prob > 0.5).float().item()
print(f"Input: [1.0, 1.0], Prediction: {prediction}") # Should correctly predict 0.0
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
๐
Ask for provider support