Skip to main content
Deno 2 is finally here 🎉️
Learn more


Netsaur


netsaur stars netsaur releases netsaur License


Powerful Machine Learning library for Deno

Backends

Examples

Maintainers

Usage

import {
  Activation,
  Cost,
  CPU,
  DenseLayer,
  Sequential,
  setupBackend,
  tensor2D,
} from "https://deno.land/x/netsaur/mod.ts";

await setupBackend(CPU);

const net = new Sequential({
  size: [4, 2],
  silent: true,
  layers: [
    DenseLayer({ size: [3], activation: Activation.Sigmoid }),
    DenseLayer({ size: [1], activation: Activation.Sigmoid }),
  ],
  cost: Cost.MSE,
});

const time = performance.now();

net.train(
  [
    {
      inputs: tensor2D([
        [0, 0],
        [1, 0],
        [0, 1],
        [1, 1],
      ]),
      outputs: tensor2D([[0], [1], [1], [0]]),
    },
  ],
  10000,
);

console.log(`training time: ${performance.now() - time}ms`);
console.log((await net.predict(tensor2D([[0, 0]]))).data);
console.log((await net.predict(tensor2D([[1, 0]]))).data);
console.log((await net.predict(tensor2D([[0, 1]]))).data);
console.log((await net.predict(tensor2D([[1, 1]]))).data);

Use the WASM Backend

import {
  Activation,
  Cost,
  DenseLayer,
  Sequential,
  setupBackend,
  tensor2D,
  WASM,
} from "https://deno.land/x/netsaur/mod.ts";

await setupBackend(WASM);

const net = new Sequential({
  size: [4, 2],
  silent: true,
  layers: [
    DenseLayer({ size: [3], activation: Activation.Sigmoid }),
    DenseLayer({ size: [1], activation: Activation.Sigmoid }),
  ],
  cost: Cost.MSE,
});

const time = performance.now();

net.train(
  [
    {
      inputs: tensor2D([
        [0, 0],
        [1, 0],
        [0, 1],
        [1, 1],
      ]),
      outputs: tensor2D([[0], [1], [1], [0]]),
    },
  ],
  10000,
);

console.log(`training time: ${performance.now() - time}ms`);
console.log((await net.predict(tensor2D([[0, 0]]))).data);
console.log((await net.predict(tensor2D([[1, 0]]))).data);
console.log((await net.predict(tensor2D([[0, 1]]))).data);
console.log((await net.predict(tensor2D([[1, 1]]))).data);

Documentation

The full documentation for Netsaur can be found here.

License

Netsaur is licensed under the MIT License.