Toy Autograd Engine in OCaml with Apple Accelerate Backend

I have been venturing to learn a new language and I landed on OCaml after hearing a few interesting talks from Jane Street. I just made public a toy autograd engine in OCaml with an Apple Accelerate backend if anyone is interested:

I would really appreciate any feedback in terms of the OCaml code that I wrote so that I can improve. If anyone is willing to quickly take a look it would mean a lot :slight_smile:

5 Likes

I had a very quick look at your repo, its very cool !
I think you might want to delete the bin folder, or rename it examples or something because this project is a lib.
You could also use ocamlformat to format the code.

You could also use include subdirs qualified so that you do not have a separate Tensor library, but a Tensor module inside your main lib.
I think it would also be a little more idiomatic to have a type Tensor.t instead of Tensor.tensor and then instead of

open Tensor

(* Loss Functions *)
val mean_squared_error : tensor -> tensor -> tensor
val binary_cross_entropy : tensor -> tensor -> tensor

You have :

val mean_squared_error : Tensor.t -> Tensor.t -> Tensor.t
val binary_cross_entropy : Tensor.t -> Tensor.t -> Tensor.t

As this is a lib, it’s probably good to have documentation comments on each public function (the syntax is (** ... *).

@EmileTrotignon Thank you so much for taking the time! I will update shortly with your suggestions they are very helpful :slight_smile:

1 Like