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, with no dependencies. 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 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 ~inputs:768 ~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")| 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 |
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 |
| ᛋ | sowilo | OpenCV | Differentiable computer vision |
| ymir | Astropy | Astronomy: units, frames, FITS, photometry, cosmology |
opam install ravenThis 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.
Building a scientific computing ecosystem takes sustained effort. Sponsorships help us ship distributed training, better developer tooling, and production deployment as static binaries.