-
Notifications
You must be signed in to change notification settings - Fork 0
Language Tour
MLPL combines array-language concision with explicit ML concepts and an inspectable environment. It is suitable both for teaching and for expressing small executable experiments.
v = range(6)
M = reshape(v, [2, 3])
M * 10
transpose(M)
reduce_add(M, 1)
Arithmetic is element-wise with scalar broadcasting. The language includes reshape, transpose, indexing, rotation, composition, reductions, matrix multiplication, math functions, comparisons, random generation, structural introspection, and the running_sum and running_product scan specializations.
Length-one arrays broadcast like scalars, at(v, i) indexes a vector directly, and comparisons may use either builtin calls or the infix operators <, >, <=, >=, ==, and !=.
Named axes attach meaning to dimensions:
X : [batch, feature] = reshape(range(12), [4, 3])
labels(X)
reduce_add(X, "feature")
Shape and label mismatches become structured errors rather than unexplained downstream failures.
MLPL supports user functions, iteration, scoped constructs, conditional behavior, try/catch, Result propagation with ?, and functional lenses for nested structures. APL2-inspired structure functions such as depth, disp, size, and tally make mixed and nested values inspectable.
Functions are values: namespace-qualified references, partial application, and call support higher-order code. each, table, atop, and over provide common array-oriented mapping and composition patterns.
flowchart LR
Params[Parameters] --> Forward[Forward expression]
Batch[Training batch] --> Forward
Forward --> Loss[Loss]
Loss --> Tape[Reverse-mode tape]
Tape --> Grad[Gradients]
Grad --> Optimizer[Adam or momentum SGD]
Optimizer --> Params
Loss --> Telemetry[Loss history and telemetry]
The reverse-mode tape covers the array operations used by the model layer. grad differentiates an expression with respect to parameters; adam and momentum_sgd update them. train N { ... } binds the current step, captures losses, and can stream metrics when evaluated through the server.
Models are composable values, not opaque external objects. Important building blocks include linear and LoRA linear layers, activation layers, chains, residual connections, normalization, embeddings, positional encodings, attention and causal attention, recurrent pieces, and Engram memory components.
mdl = chain(
linear(8, 16, 1),
relu_layer(),
residual(chain(linear(16, 16, 2), relu_layer())),
linear(16, 3, 3)
)
y = apply(mdl, X)
Use params(mdl), :models, and :describe mdl to inspect the model rather than treating it as a black box.
The runtime can tag values with semantic roles such as logits, probabilities, losses, gradients, weights, biases, activations, learning rates, labels, and attention maps. Producers automatically attach many tags; consumers can reject incompatible values with tutoring-oriented errors. Tags are gradual and additive rather than a mandatory static type system.
-
loadreads sandboxed native data;load_preloadedworks with compiled-in datasets. -
shuffle,batch, andsplitsupport dataset workflows. - Byte tokenization and BPE training/application/decoding are built in.
-
experiment "name" { ... }groups reproducible work; native modes can persist run records. - Model feasibility helpers estimate parameters, memory, and training time, and can calibrate against a device.
Primitive visualization types include scatter, line, bar, heatmap, decision boundaries, 3-D scatter, and specialized renderers. Higher-level helpers cover histograms, labeled scatter, loss curves, confusion matrices, model diagrams, Life animations, and 3-D or image-oriented views. Browser mode renders inline; CLI/server modes store or serve artifacts.
dataflow(nodes, edges) produces structural SVG diagrams with group bands, quantitative edge widths, highlighting, recurrence back-edges, and label-aware spacing.
The interpreter is the broad interactive path. For a supported subset, mlpl! embeds MLPL in Rust and mlpl build lowers a .mlpl file to Rust/native code without shipping the parser or interpreter in the output. Review subset and parity limitations before selecting compilation as a deployment target.
For exact syntax and builtins, use the source repository's language reference, usage guide, and compiler guide.
Engram support includes deterministic n-gram addressing, gathered memory rows, an engram Model DSL value, differentiable apply_engram, health statistics, and Tiny-LM integration. Engram execution uses the CPU path; MLX- and CUDA-resident Engram operations are not supported.