# What does the architecture of Flux.RNN look like?

**URL:** <https://discourse.julialang.org/t/what-does-the-architecture-of-flux-rnn-look-like/44119>\
**Category:** Machine Learning\
**Tags:** question, flux, machine-learning\
**Created:** [August 2, 2020, 4:59am UTC](https://discourse.julialang.org/t/what-does-the-architecture-of-flux-rnn-look-like/44119 "2020-08-02T04:59:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![XiaodongMa-MRI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodongma-mri/32/16171_2.png) [@XiaodongMa-MRI](https://discourse.julialang.org/u/XiaodongMa-MRI)\
**Post date:** [August 2, 2020, 4:59am UTC](https://discourse.julialang.org/t/what-does-the-architecture-of-flux-rnn-look-like/44119/1 "2020-08-02T04:59:14Z")

</div>

Hi all,  
I am confused about the architecture of RNN in Flux.jl. If I define a RNN using the code `RNN(3,3)`, will it be like the left one or the right one in the picture below?

![image](https://global.discourse-cdn.com/julialang/original/3X/c/0/c0c076762356ce780e404d8179e1a32daf6cf92e.png)

Based on the documentation, I think it is more like the right one, but I am not sure:

> [`Flux.RNN`](https://fluxml.ai/Flux.jl/stable/models/layers/#Flux.RNN)—Function
> 
> ```julia
> RNN(in::Integer, out::Integer, σ = tanh)
> 
> ```
> 
> The most basic recurrent layer; essentially acts as a `Dense` layer, but with the output fed back into the input each time step.

I actually want to define a multi-input and multi-output RNN like the right one in the figure. If `flux.RNN()` cannot achieve this, do anyone have ideas how to write it mannually?

Thanks a lot for your help!

---

<div class="post-metadata">

**Author:** ![bfried1](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bfried1](https://discourse.julialang.org/u/bfried1)\
**Post date:** [September 27, 2021, 9:40pm UTC](https://discourse.julialang.org/t/what-does-the-architecture-of-flux-rnn-look-like/44119/2 "2021-09-27T21:40:41Z")

</div>

Has there been any insight into this question?

---

<div class="post-metadata">

**Author:** ![AlexLewandowski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexlewandowski/32/18856_2.png) [@AlexLewandowski](https://discourse.julialang.org/u/AlexLewandowski)\
**Post date:** [September 27, 2021, 10:06pm UTC](https://discourse.julialang.org/t/what-does-the-architecture-of-flux-rnn-look-like/44119/3 "2021-09-27T22:06:17Z")

</div>

You can use `Flux.RNN` either way, the only difference is how you manage your inputs.

Left:

```julia
x1 = rand(Float32, 3)
x2 = rand(Float32, 3)
x3 = rand(Float32, 3)

m = Flux.RNN(3,3)

y1, y2, y3 = m.([x1, x2, x3]) # Apply the RNN to each input sequentially.

```

Right:

```julia
x1 = rand(Float32, 3)
x2 = rand(Float32, 3)
x3 = rand(Float32, 3)

x = vcat(x1,x2,x3)

m = Flux.RNN(9,3)

y1, y2, y3 = m.([x,x,x]) # Apply the RNN to the concatenated input three times.

```

You can also use a `Dense` layer to learn a weighted combination of `x1, x2, x3 `.
