Downloads · 30 days
0
JMullings/ts-xor-demo
ts-xor-demo is a tabular classification model from JMullings. Use it for the tabular classification task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
In this example, we will use TensorFlow.js to train a neural network for the XOR (exclusive OR) problem. The XOR problem is a classic problem in machine learning where the model needs to learn a non-linear decision bo…
Downloads · 30 days
0
Access
Public
Updated Jul 29, 2023
Repo size
434 MB
Likes
0
Public
Click a slice to open those files.
.md2.6 KB · 37%
From the Hugging Face model README
In this example, we will use TensorFlow.js to train a neural network for the XOR (exclusive OR) problem. The XOR problem is a classic problem in machine learning where the model needs to learn a non-linear decision boundary to correctly classify inputs.
The neural network used for this XOR problem consists of an input layer with two neurons, a hidden layer with two neurons, and an output layer with one neuron. The activation function used in the hidden layer is ReLU (Rectified Linear Unit), and the output layer uses the sigmoid activation function to produce values between 0 and 1.
The XOR dataset consists of four samples, each with two features (inputs) and one label (output). The dataset is as follows:
| Input 1 | Input 2 | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The training is performed using TensorFlow.js with the following hyperparameters:
Below is the code implementation for training the XOR neural network using TensorFlow.js:
// Import TensorFlow.js library
import * as tf from '@tensorflow/tfjs-node-gpu';
this.model = await tf.loadLayersModel(`file://${this.model_path}/model.json`);
this.model.compile({
optimizer: tf.train.sgd(0.1),
loss: 'binaryCrossentropy', // Binary classification loss
metrics: ['accuracy'],
});
this.model.summary();
const x = tf.tensor2d([[1,1]]);
const prediction = this.model.predict(x) as tf.Tensor;
The resulting predictions for the XOR dataset after training the model are as follows:
Tensor
[[0.0020679],
[0.9994502],
[0.9994048],
[0.0002599]]
Please note that this example assumes you have set up your project with the necessary dependencies and have a basic understanding of JavaScript and TensorFlow.js.