# Hidden layers in Flux

**URL:** https://discourse.julialang.org/t/hidden-layers-in-flux/39910
**Category:** Machine Learning
**Tags:** question
**Created:** [May 21, 2020, 8:28pm UTC](https://discourse.julialang.org/t/hidden-layers-in-flux/39910 "2020-05-21T20:28:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Mariana](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariana/32/15064_2.png) [@Mariana](https://discourse.julialang.org/u/Mariana)
#### Post date: [May 21, 2020, 8:28pm UTC](https://discourse.julialang.org/t/hidden-layers-in-flux/39910/1 "2020-05-21T20:28:25Z")

</div>

I’m starting to work with Flux and I want to build a neural network with 5 entries and 6 exits. I have already built a network with no hidden layers, but now I want to add hidden layers. How should I do that? I believe I need to use the Dense function, but I’m not sure how to do that.

---

<div class="post-metadata">

### Author: ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)
#### Post date: [May 21, 2020, 8:41pm UTC](https://discourse.julialang.org/t/hidden-layers-in-flux/39910/2 "2020-05-21T20:41:53Z")

</div>

An example:

```julia
model = Chain(Dense(5, n), Dense(n, 6))

```

where n is the number of neurons in the hidden layer.  
You can see the Documentation of Flux, it is improving a lot lately.

---

<div class="post-metadata">

### Author: ![Mariana](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariana/32/15064_2.png) [@Mariana](https://discourse.julialang.org/u/Mariana)
#### Post date: [May 21, 2020, 9:43pm UTC](https://discourse.julialang.org/t/hidden-layers-in-flux/39910/3 "2020-05-21T21:43:48Z")

</div>

Thank you for your answer!! But what about the number of hidden layers? How do I define that in the Dense function?

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [May 21, 2020, 10:39pm UTC](https://discourse.julialang.org/t/hidden-layers-in-flux/39910/4 "2020-05-21T22:39:37Z")

</div>

You just add an other (e.g. `Dense`) layer to the `Chain` function.

---

<div class="post-metadata">

### Author: ![Mariana](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariana/32/15064_2.png) [@Mariana](https://discourse.julialang.org/u/Mariana)
#### Post date: [May 21, 2020, 11:28pm UTC](https://discourse.julialang.org/t/hidden-layers-in-flux/39910/5 "2020-05-21T23:28:24Z")

</div>

Thank you!! So, for example, if I want to create a network with 1 hidden layer with 7 neurons, I’d have:  
model = Chain(Dense(5,7), Dense(7,6), Dense(6,6))?

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [May 22, 2020, 1:24pm UTC](https://discourse.julialang.org/t/hidden-layers-in-flux/39910/6 "2020-05-22T13:24:13Z")

</div>

Have you tried it?
