-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
35 lines (30 loc) · 979 Bytes
/
index.html
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
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"></script>
</head>
<body>
<div id="output"></div>
</body>
<script>
// Your script goes here!
// Creating a model to predict the output
async function predictOutput() {
const model = tf.sequential();
model.add(tf.layers.dense({ units: 8, inputShape: 2, activation: 'tanh' }));
model.add(tf.layers.dense({ units: 1, activation: 'sigmoid' }));
model.compile({ optimizer: 'sgd', loss: 'meanSquaredError', lr: 0.6 });
// Creating dataset
const xs = tf.tensor2d([[0, 0], [0, 1], [1, 0], [1, 1]]);
xs.print();
const ys = tf.tensor2d([[0], [1], [1], [0]]);
ys.print();
// Train the model
await model.fit(xs, ys, {
batchSize: 1,
epochs: 5000
});
document.getElementById("output").innerText = model.predict(xs);
}
predictOutput();
</script>
</html>