# Tree-based neural networks in owl

**URL:** <https://discuss.ocaml.org/t/tree-based-neural-networks-in-owl/6957>\
**Category:** Learning\
**Tags:** owl\
**Created:** [December 11, 2020, 5:43pm UTC](https://discuss.ocaml.org/t/tree-based-neural-networks-in-owl/6957 "2020-12-11T17:43:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nephanth](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@nephanth](https://discuss.ocaml.org/u/nephanth)\
**Post date:** [December 11, 2020, 5:43pm UTC](https://discuss.ocaml.org/t/tree-based-neural-networks-in-owl/6957/1 "2020-12-11T17:43:45Z")

</div>

Hi !  
I am kind of new to owl, and I have a bit of a problem with neural networks :  
Basically I am trying to implement a network that takes non-matricial data.

More specifically I am trying to code a neural network that takes trees as input (a variant of tbcnn)  
The problem I am encountering is that, the input being binary trees, it does not always have the same structure  
this is theoretically not a problem (since the differentiation is normally done on the parameters, but only on the optimization parameters), i tried to write the layers that operate on trees (the convolution layers) as Lambda nodes in owl.  
But, if I got owl requires all input for a NN node to be Algodiff.t . (which my trees are not)  
The solution I have found is to encode my binary trees as matrices (using a list of nodes ordered depth-first). It should work (i have not finished), but is not very elegant.  
Do you know if there is a more elegant way ?

---

<div class="post-metadata">

**Author:** ![tachukao](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/tachukao/32/2577_2.png) [@tachukao](https://discuss.ocaml.org/u/tachukao)\
**Post date:** [December 11, 2020, 7:24pm UTC](https://discuss.ocaml.org/t/tree-based-neural-networks-in-owl/6957/2 "2020-12-11T19:24:43Z")

</div>

Hi there! Will you be needing a lot of the neural network layers (e.g. conv nets, lstms etc.) in Owl?  
If not, it might be easier to directly work with `Algodiff`, and write your own neural networks and differentiable loss functions. You can optimize your parameters using [https://github.com/owlbarn/owl\_opt](https://github.com/owlbarn/owl_opt)  
This might be a bit more verbose, but could also be more efficient.

---

<div class="post-metadata">

**Author:** ![nephanth](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@nephanth](https://discuss.ocaml.org/u/nephanth)\
**Post date:** [December 13, 2020, 5:14pm UTC](https://discuss.ocaml.org/t/tree-based-neural-networks-in-owl/6957/3 "2020-12-13T17:14:11Z")

</div>

Thanks for your answer. The problem is that I will need several neural network layers (some FC, but probably also LSTM).  
Thank for the link to owl\_opt though, I will look into it !
