• Stars
    star
    211
  • Rank 186,867 (Top 4 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Powerful Powerful Machine Learning library with GPU, CPU and WASM backends


Netsaur


netsaur stars netsaur releases netsaur License


Powerful Machine Learning library for Deno.

Features

  • Lightweight and easy-to-use neural network library for Deno.
  • Blazingly fast and efficient.
  • Provides a simple API for creating and training neural networks.
  • Can run on both the CPU and the GPU (WIP).
  • Allows you to simply run the code without downloading any prior dependencies.
  • Perfect for serverless environments.
  • Allows you to quickly build and deploy machine learning models for a variety of applications with just a few lines of code.
  • Suitable for both beginners and experienced machine learning practitioners.

Backends

  • CPU - Native backend written in Rust.
  • WASM - WebAssembly backend written in Rust.
  • GPU (TODO)

Examples

Maintainers

QuickStart

This example shows how to train a neural network to predict the output of the XOR function our speedy CPU backend written in rust.

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

/**
 * Setup the CPU backend. This backend is fast but doesn't work on the Edge.
 */
await setupBackend(CPU);

/**
 * Creates a sequential neural network.
 */
const net = new Sequential({
  /**
   * The number of minibatches is set to 4 and the output size is set to 2.
   */
  size: [4, 2],

  /**
   * The silent option is set to true, which means that the network will not output any logs during trainin
   */
  silent: true,

  /**
   * Defines the layers of a neural network in the XOR function example.
   * The neural network has two input neurons and one output neuron.
   * The layers are defined as follows:
   * - A dense layer with 3 neurons.
   * - sigmoid activation layer.
   * - A dense layer with 1 neuron.
   * -A sigmoid activation layer.
   */
  layers: [
    DenseLayer({ size: [3] }),
    SigmoidLayer(),
    DenseLayer({ size: [1] }),
    SigmoidLayer(),
  ],

  /**
   * The cost function used for training the network is the mean squared error (MSE).
   */
  cost: Cost.MSE,
});

const time = performance.now();

/**
 * Train the network on the given data.
 */
net.train(
  [
    {
      inputs: tensor2D([
        [0, 0],
        [1, 0],
        [0, 1],
        [1, 1],
      ]),
      outputs: tensor2D([[0], [1], [1], [0]]),
    },
  ],
  /**
   * The number of iterations is set to 10000.
   */
  10000,
);

console.log(`training time: ${performance.now() - time}ms`);

/**
 * Predict the output of the XOR function for the given inputs.
 */
const out1 = (await net.predict(tensor1D([0, 0]))).data;
console.log(`0 xor 0 = ${out1[0]} (should be close to 0)`);

const out2 = (await net.predict(tensor1D([1, 0]))).data;
console.log(`1 xor 0 = ${out2[0]} (should be close to 1)`);

const out3 = (await net.predict(tensor1D([0, 1]))).data;
console.log(`0 xor 1 = ${out3[0]} (should be close to 1)`);

const out4 = (await net.predict(tensor1D([1, 1]))).data;
console.log(`1 xor 1 = ${out4[0]} (should be close to 0)`);

Use the WASM Backend

By changing the CPU backend to the WASM backend we sacrifice some speed but this allows us to run on the edge.

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

/**
 * Setup the WASM backend. This backend is slower than the CPU backend but works on the Edge.
 */
await setupBackend(WASM);

/**
 * Creates a sequential neural network.
 */
const net = new Sequential({
  /**
   * The number of minibatches is set to 4 and the output size is set to 2.
   */
  size: [4, 2],

  /**
   * The silent option is set to true, which means that the network will not output any logs during trainin
   */
  silent: true,

  /**
   * Defines the layers of a neural network in the XOR function example.
   * The neural network has two input neurons and one output neuron.
   * The layers are defined as follows:
   * - A dense layer with 3 neurons.
   * - sigmoid activation layer.
   * - A dense layer with 1 neuron.
   * -A sigmoid activation layer.
   */
  layers: [
    DenseLayer({ size: [3] }),
    SigmoidLayer(),
    DenseLayer({ size: [1] }),
    SigmoidLayer(),
  ],

  /**
   * The cost function used for training the network is the mean squared error (MSE).
   */
  cost: Cost.MSE,
});

const time = performance.now();

/**
 * Train the network on the given data.
 */
net.train(
  [
    {
      inputs: tensor2D([
        [0, 0],
        [1, 0],
        [0, 1],
        [1, 1],
      ]),
      outputs: tensor2D([[0], [1], [1], [0]]),
    },
  ],
  /**
   * The number of iterations is set to 10000.
   */
  10000,
);

console.log(`training time: ${performance.now() - time}ms`);

/**
 * Predict the output of the XOR function for the given inputs.
 */
const out1 = (await net.predict(tensor1D([0, 0]))).data;
console.log(`0 xor 0 = ${out1[0]} (should be close to 0)`);

const out2 = (await net.predict(tensor1D([1, 0]))).data;
console.log(`1 xor 0 = ${out2[0]} (should be close to 1)`);

const out3 = (await net.predict(tensor1D([0, 1]))).data;
console.log(`0 xor 1 = ${out3[0]} (should be close to 1)`);

const out4 = (await net.predict(tensor1D([1, 1]))).data;
console.log(`1 xor 1 = ${out4[0]} (should be close to 0)`);

Documentation

The full documentation for Netsaur can be found here.

License

Netsaur is licensed under the MIT License.

More Repositories

1

denon

๐Ÿ‘€ Monitor any changes in your Deno application and automatically restart.
TypeScript
1,101
star
2

deno_python

๐Ÿ Python interpreter bindings for Deno and Bun.
TypeScript
507
star
3

bench

๐Ÿ“Š Comparing deno, node and bun HTTP frameworks
TypeScript
307
star
4

mod.land

๐Ÿ“ฆ Pretty subdomains for you deno project
MDX
192
star
5

plug

๐Ÿ”Œ Deno FFI helper module
TypeScript
77
star
6

neo

๐Ÿ‘ฉโ€๐Ÿ’ป Matrix and other math, accelerated by WebGPU and WASM
TypeScript
67
star
7

crux.land

crux.land is a free registry service meant for hosting small (โ‰ค 20kB) single deno scripts.
TypeScript
66
star
8

pane

๐Ÿ–ผ๏ธ A deno module providing bindings for cross-platform windowing
Rust
65
star
9

deno_brotli

๐Ÿ—œ Brotli wasm module for deno
TypeScript
63
star
10

wait

๐ŸŒ€ Minimal terminal spinner
TypeScript
57
star
11

rutt

๐Ÿ›ฃ๏ธ A tiny and fast http request router designed for use with deno and deno deploy
TypeScript
53
star
12

cache

๐ŸฅŒ Deno cache library
TypeScript
49
star
13

event

๐Ÿ“† Strictly typed event emitter with asynciterator support
TypeScript
42
star
14

byte_type

๐Ÿ˜‹ A small helper module for working with different raw types in javascript
TypeScript
34
star
15

sodium

๐Ÿง‚ Sodium is a modern, easy-to-use library for encryption, decryption, signatures, password hashing and more
TypeScript
30
star
16

depsbot

โš™๏ธ GitHub action to check freshness of your deno dependencies
TypeScript
27
star
17

log

๐Ÿ“œ Dead-simple drop-in logging solution using streams and the native console api
TypeScript
25
star
18

pngs

๐Ÿ“ท A simple wasm png encoder/decoder module for deno
TypeScript
20
star
19

wasabi

๐Ÿฃ Template repository for deno modules that want to use wasm
TypeScript
20
star
20

ddoc

๐Ÿ“‘ Offline deno documentation in a desktop app, generated locally
TypeScript
19
star
21

emoji

๐Ÿฆ„ Emojis for dinosaurs
TypeScript
19
star
22

parry

๐Ÿ‘ท๐Ÿฝโ€โ™‚๏ธ Run deno functions in WebWorkers
TypeScript
19
star
23

deno_lz4

๐Ÿ—œ lz4 wasm module for deno
TypeScript
18
star
24

gmath

๐ŸŽฎ A wasm accelerated game and graphics maths library for deno
TypeScript
16
star
25

status

๐Ÿ—ฟ HTTP status utility for Deno. Based on Java Apache HttpStatus
TypeScript
15
star
26

tokenizer

โš™๏ธ A simple tokenizer for deno
TypeScript
15
star
27

mess

๐ŸŒ€ A modern, broker-agnostic, distributed message queue for deno
TypeScript
13
star
28

urlpattern

๐Ÿ“‹ A polyfill for URLPattern for web-browsers, older versions of deno and non-unstable deno
TypeScript
11
star
29

python.mod.land

TypeScript
11
star
30

denord

๐Ÿ—ฃ Discord API module
TypeScript
11
star
31

argontwo

#๏ธโƒฃ Argon2 hashing module for deno using wasm
TypeScript
11
star
32

deps.index

๐Ÿ“’ Registry index for deps.land
TypeScript
10
star
33

tabtab

๐Ÿ“Ž Generate CLI completions for zsh, bash, and fish
TypeScript
10
star
34

algebra

โž— Powerful math library for Deno (WIP)
Rust
10
star
35

debug

๐Ÿ“ Tiny debugging utility
TypeScript
10
star
36

commit

โœ๏ธ Parser for the conventional commits specification
TypeScript
10
star
37

sauron

๐Ÿ•ต๏ธโ€โ™‚๏ธ Deno quality metrics analyzer
Rust
9
star
38

release

๐Ÿ“ฆ Elegant releases with plugins
TypeScript
9
star
39

tty

๐Ÿ–จ Terminal utils and ansi escapes
TypeScript
9
star
40

deno_servo

๐Ÿ›ต Servo bindings for Deno (WIP)
CSS
7
star
41

gutenberg

๐Ÿ“ Complete, correct, and thoroughly tested string manipulation library.
TypeScript
7
star
42

actions

โš™๏ธ GitHub Actions in deno
TypeScript
6
star
43

opus

๐Ÿ”Š Deno bindings for libopus
TypeScript
6
star
44

typefetch

๐Ÿ“ค Magically generate `fetch` types from OpenAPI schemas for zero-cost browser-native api clients
TypeScript
5
star
45

font

๐Ÿ–Œ A simple deno module for font rasterization
TypeScript
5
star
46

deps.land

๐Ÿ‘โ€๐Ÿ—จ Experiments with deno dependencies
TypeScript
4
star
47

obj

๐ŸŒŠ A simple wavefront obj and mtl parser and loader module for deno
TypeScript
4
star
48

deps.bors

๐Ÿ—ฟ Great manager of the deps.land index
Rust
3
star
49

branch

๐Ÿ“  Denosaurs pretty logger
TypeScript
3
star
50

website

โœ๏ธ Our official documentation site
JavaScript
3
star
51

deno_json_op

๐Ÿ“‹ A macro for easing the development of deno plugins
Rust
3
star
52

exit

๐Ÿงน Execute function when you program is exiting
TypeScript
3
star
53

pm

๐Ÿ‘€ denon 3 ... in development
TypeScript
3
star
54

ssh

๐Ÿ’ป A modern SSH client for Deno.
TypeScript
2
star
55

protobuf

๐Ÿ“ฃ a protobuf implementation for deno
2
star
56

mok

๐ŸŽญ HTTP server mocking and request isolation
1
star
57

genesis_deno

๐Ÿ› Starting template for denosaurs projects
1
star
58

deps

๐Ÿ•ดdeps.ts manager for Deno [highly WIP]
TypeScript
1
star