---
title: "TypeNN — Neural networks in TypeScript"
description: "Write Tensor operations in TypeScript, run them through the TypeShade compiler and runtime, and try the framework in your browser."
url: https://nn.typeshade.dev/
language: en
---

A TypeScript neural network framework

# Build neural networks in TypeScript.

Use Tensor operations and Module classes to define models. TypeNN records those operations in a deferred graph; TypeShade compiles and runs their kernels on CPU and supported GPU backends.

[Try the playground](https://nn.typeshade.dev/playground/) [Read the guide](https://nn.typeshade.dev/guide/)

Pre-release · source and examples are the current usage reference.

Tensor API example.ts

```ts
import * as nn from "typenn";

const device = await nn.device();
const input = device.tensor([1, 2, 3, 4], { shape: [2, 2] });
const weight = device.tensor([5, 6, 7, 8], { shape: [2, 2] });
const output = input.matmul(weight).relu();

console.log(await output.data());
// Float32Array [19, 22, 43, 50]
await output.disposeGraph();
await device.dispose();
```

Float32Array `[19, 22, 43, 50]` Example output

Execution

## How TypeNN executes Tensor operations

[How execution works](https://nn.typeshade.dev/guide/execution/)

01

### Define

Tensor calls define shapes and operations. TypeNN records each call as a graph node.

`tensor.matmul(weight).relu()`

02

### Call kernel functions

Each node holds a TypeShade kernel function. When you call `data()`, TypeNN runs the function with that node's input and output arrays.

`TypeShade kernel`

03

### Run the graph

When needed, `data()` runs the kernels for the requested result on the selected tier.

`CPU · WebGPU · WebGL2*`

\* WebGL2 and the CPU tier run the same kernel functions apart. Only WebGPU fuses an elementwise chain into one dispatch.

Try TypeNN

## Try TypeNN in your browser

Run matrix operations in the browser, then read the guides to learn about graph execution, automatic differentiation, and model training.

[**Playground** Run real TypeNN operations in this browser.](https://nn.typeshade.dev/playground/) [**Train a model** Train an MLP to classify MNIST digits.](https://nn.typeshade.dev/guide/training/) [**API reference** Look up the current Tensor and Module APIs.](https://nn.typeshade.dev/api/) [**Examples** Read complete source examples and current limits.](https://nn.typeshade.dev/examples/)

Current implementation

## Training and execution

When `data()` computes a new result, it runs the required kernels. After a plan runs, inspect `device.lastReport` for its execution tier and dispatches. SGD and Adam update parameters on the device; tiled MatMul remains future work.

[Read implementation status](https://github.com/typeshade/typenn/blob/main/TODO.md)
