Documentation menu
Packages

Package Manager

Serez Code has a built-in package manager. Packages install into a ./packages/ folder in your project — one command, no config files needed.

Installing a package

sz install serez-ai
sz install serez-ui

This creates ./packages/serez-ai/ in your current directory. Packages are local to the project — nothing is installed globally.

Removing a package

sz uninstall serez-ai

Using a package

Import a package at the top of your script with its name:

import "serez-ai"

let model = new Sequential()
model.add(new Dense(2, 32, "relu"))
model.add(new Dense(32, 1, "sigmoid"))

Running a package's commands

Some packages expose runnable commands (a packer, a generator…) through a bin entry in their manifest. Run one from your project root with sz run <command> — extra arguments are forwarded as key=value tokens (serez-code ≥ 4.6.2):

sz run apipack port=8080 tag=my-api:latest       # serez-apipack
sz run pack entry=app.sz name=MyApp format=msi   # serez-pack

sz run looks for a script in your own serez.json first, then a package command; if two packages share a name, disambiguate with sz run <package>:<command>. Building a package that exposes its own command? See Create & publish a package.

serez-ai

A neural network library with a Keras-like API. Build, train, and run models in just a few lines.

A complete training loop

import "serez-ai"

Random.seed(42)

// XOR dataset — inputs/targets are tensors
let X = Tensor.from([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]])
let y = Tensor.from([[0.0], [1.0], [1.0], [0.0]])

// Build the network
let model = new Sequential()
model.add(new Dense(2, 16, "relu"))
model.add(new Dense(16, 1, "sigmoid"))

// Train — fit_opt returns the per-epoch loss history
let opt     = new Adam(0.01, 0.9, 0.999)
let history = model.fit_opt(X, y, new BCE(), 1000, opt, false)

out "Final loss: {history[history.length() - 1]}"

// Predict — forward returns a tensor; read it with .get(row, col)
let pred = model.forward(Tensor.from([[1.0, 0.0]]))
out "XOR(1, 0) = {pred.get(0, 0)}"   // → ~0.97

Available layers

LayerWhat it does
Dense(in, out, activation)Fully connected. Activations: relu, sigmoid, tanh, linear
Conv2D(in_ch, out_ch, kernel, stride, activation)2D convolution for image data
MaxPool2D(pool, stride) / Flatten()Downsample conv maps / flatten to 1D
Embedding(vocab_size, embed_dim)Token id → dense vector lookup
LSTM / GRU(input_size, hidden_size)Recurrent layers for sequences
MultiHeadAttention(d_model, n_heads)Transformer self-attention
LayerNorm(d_model, eps) / TransformerBlock(d_model, n_heads, d_ff)Normalization / full transformer block

Optimizers & loss functions

// Optimizers
let opt1 = new Adam(lr, beta1, beta2)
let opt2 = new SGD(lr)
let opt3 = new Momentum(lr, momentum)

// Loss functions
let loss1 = new MSE()    // Mean Squared Error
let loss2 = new BCE()    // Binary Cross-Entropy

// Train with optimizer (returns the per-epoch loss history)
let history = model.fit_opt(X, y, new BCE(), epochs, new Adam(0.01, 0.9, 0.999), false)

Tensors & autodiff

import "serez-ai"

// Create tensors with Tensor.from
let a = Tensor.from([[1.0, 2.0], [3.0, 4.0]])
let b = Tensor.from([[2.0, 0.0], [1.0, 3.0]])

// Record operations on a tape — gradients tracked automatically
Autodiff.tape()
let c    = a.add(b)
let loss = a.matmul(b).relu().mean()

// Backward from a scalar, then read gradients
Autodiff.backward(loss)
let ga = Autodiff.gradient(a)
out ga.shape()   // gradient shape of a

serez-ui

A React-style UI library — components return JSX from render() and run in the terminal (TUI) or a real native window (GUI) from the same code.

import "serez-ui"

// Components extend Window; state lives in `this` and re-renders on change
class Counter:Window {
    public Counter() {
        super()
        this.count = 0
    }

    public render() {
        return (
            <div>
                <h1>Counter</h1>
                <h2>{this.count}</h2>
                <Button onClick={() => { this.count = this.count + 1 }}>Increment</Button>
            </div>
        )
    }
}

let app = new Counter()
app.runGui("Counter", 400, 300)   // or app.runTui() for the terminal

Built-in tags & components

Tag / componentWhat it is
div, h1–h3, p, span, hr, ul, li, section, formPrimitive structure tags the renderer draws
ButtonClickable button — onClick, disabled (text is the children)
InputText field — value, placeholder, type, onChange, disabled
SelectCycling picker — value, options, onChange, disabled
CheckboxToggle — checked, label, onChange, disabled
TextareaMulti-line input — value, placeholder, rows, onChange, disabled