# How to build Stacked RNN in Flux.jl?

**URL:** <https://discourse.julialang.org/t/how-to-build-stacked-rnn-in-flux-jl/115098>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [June 3, 2024, 8:24am UTC](https://discourse.julialang.org/t/how-to-build-stacked-rnn-in-flux-jl/115098 "2024-06-03T08:24:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeroBlackstone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/neroblackstone/32/208679_2.png) [@NeroBlackstone](https://discourse.julialang.org/u/NeroBlackstone)\
**Post date:** [June 3, 2024, 8:24am UTC](https://discourse.julialang.org/t/how-to-build-stacked-rnn-in-flux-jl/115098/1 "2024-06-03T08:24:55Z")

</div>

How to build [Stacked RNN](https://abhijatsarari.medium.com/stacked-rnns-in-nlp-936e6eecf37a) in Flux.jl?

Is the following code the correct way?

```julia
using Flux
model = Chain(GRUv3(27 => 32),GRUv3(32 => 32),Dense(32 => 27))

```

```julia
Chain(
  Recur(
    GRUv3Cell(27 => 32), # 5_792 parameters
  ),
  Recur(
    GRUv3Cell(32 => 32), # 6_272 parameters
  ),
  Dense(32 => 27), # 891 parameters
) # Total: 12 trainable arrays, 12_955 parameters,
          # plus 2 non-trainable, 64 parameters, summarysize 1.938 KiB.

```

---

<div class="post-metadata">

**Author:** ![jeremiedb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeremiedb/32/29150_2.png) [@jeremiedb](https://discourse.julialang.org/u/jeremiedb)\
**Post date:** [June 18, 2024, 2:25am UTC](https://discourse.julialang.org/t/how-to-build-stacked-rnn-in-flux-jl/115098/2 "2024-06-18T02:25:17Z")

</div>

Yes I think you have it correct!  
You may want to have a `Embedding` or `Dense` as first operator to reproject the input data to the 27 dimensions expected by the GRU cell, but otherwise it looks fine.
