Skip to content
raven-mlPublic

About

Modern scientific computing for OCaml

Resources

Contributing

Stars

421 stars

Watchers

6 watching

Forks

Repository files navigation

raven

modern scientific computing for OCaml

docs · install · issues


Raven is machine learning and scientific computing in OCaml, from neural networks to probabilistic inference to numerical methods, all the way down to the GPU, and it builds with nothing beyond OCaml. It covers what NumPy, JAX, PyTorch, NumPyro, SciPy, pandas and Matplotlib cover in Python, as libraries that compose as ordinary OCaml code.

Raven is alpha. APIs will change. Feedback welcome.

(* nx — n-dimensional arrays *)
let x = Nx.linspace Nx.float32 0. 10. 100
let y = Nx.sin x

(* rune — automatic differentiation *)
let grad_f = Rune.grad' (fun x -> Nx.sum (Nx.mul x x)) x

(* brot — tokenization *)
let tokenizer = Brot.from_file "tokenizer.json" |> Result.get_ok
let ids = Brot.encode_ids tokenizer "The meaning of life is"

(* jera — numerical methods *)
let cos_integral = Jera.Quad.(fixed (Rule.gauss 10) Nx.cos (Range.v (Nx.zeros_like x) x))

(* kaun — neural networks *)
let layer = Kaun.Linear.init ~key:(Nx.Rng.key 0) ~inputs:100 ~outputs:10
let logits = Kaun.Linear.apply layer x

(* talon — dataframes *)
let df = Talon.v [
  "name", Talon.Column.v Talon.Type.string [| "Alice"; "Bob"; "Charlie" |];
  "score", Talon.Column.v Talon.Type.float64 [| 85.5; 92.0; 78.5 |];
]
let top = Talon.(Query.of_table df |> Kit.top_k 2 [ Order.desc "score" ] |> Query.run)

(* hugin — plotting *)
let () = Hugin.(line ~x:(num x) ~y:(num y) () |> save "sine.png")

Packages

Package Like What it does
nx NumPy N-dimensional arrays with linear algebra operations
rig CUDA driver API Devices such as GPUs, and the order of the work they run
ᛏ tolk tinygrad Minimal ML compiler for GPU tensor computation
ᚱ rune JAX Automatic differentiation and functional transformations
ᚴ kaun Flax Neural networks and training
ᚹ vega Optax Composable gradient-based optimizers
ᛄ jera SciPy Systems, minima, integrals, interpolation, ODEs and SDEs
ᚾ norn NumPyro / Stan Probabilistic inference: models, samplers, diagnostics
ᚨ brot HF Tokenizers Fast, HuggingFace-compatible tokenization
ᛃ talon pandas / Polars Dataframes with typed queries, CSV and Parquet
ᛞ hugin Matplotlib Publication-quality plotting
ᛈ quill Jupyter + IPython Interactive REPL and markdown notebooks
ᛗ munin W&B / MLFlow Local experiment tracking with live TUI dashboard

Contrib

Packages in contrib/ build against every change to the core and release on their own schedule.

Package Like What it does
ᚠ fehu Gymnasium Reinforcement learning environments
ymir Astropy Astronomy: units, frames, FITS, photometry, cosmology
jord rasterio Earth observation: systems, grids, warps, products
alda SciPy Signals: windows, spectra, filters, resampling
mynd Pillow Images: colour, sampling, resizing, filters, masks

Getting started

opam install raven

This installs the core ecosystem. You can also install only what you need — e.g. opam install kaun for neural networks, or opam install nx for just arrays.

Add to your dune file:

(executable
 (name main)
 (libraries raven))

See the installation guide for system dependencies and editor setup.

Use of AI

Raven is developed with AI coding agents: the maintainers guide, design and review, and, since around mid-2026, agents write almost all of the code. Contributions made with AI tools are welcome, as long as you understand and have reviewed what you submit. See AI.md for how the project is built and what we expect from contributions.

Support

Building a scientific computing ecosystem takes sustained effort. Sponsorships help us ship distributed training, better developer tooling, and production deployment as static binaries.

Support Raven →

Thanks to our sponsors Ahrefs and Tarides.

License

ISC

About

Modern scientific computing for OCaml

Resources

Contributing

Stars

421 stars

Watchers

6 watching

Forks

Releases

Used by

Contributors

Languages