# Using LSTM cell in Lux with explicit parameters

**URL:** <https://discourse.julialang.org/t/using-lstm-cell-in-lux-with-explicit-parameters/110199>\
**Category:** Machine Learning\
**Tags:** question, package\
**Created:** [February 14, 2024, 4:06am UTC](https://discourse.julialang.org/t/using-lstm-cell-in-lux-with-explicit-parameters/110199 "2024-02-14T04:06:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kunal](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@kunal](https://discourse.julialang.org/u/kunal)\
**Post date:** [February 14, 2024, 4:06am UTC](https://discourse.julialang.org/t/using-lstm-cell-in-lux-with-explicit-parameters/110199/1 "2024-02-14T04:06:26Z")

</div>

Hi,  
I was referring to the Simple LSTM tutorial, which combines classifier(Dense layer) with LSTMCell using AbstractExplicitContainerLayer.

> **[Training a Simple LSTM | LuxDL Docs](https://lux.csail.mit.edu/dev/tutorials/beginner/3_SimpleRNN)**
>
> Elegant Deep Learning in Julia

Also, in my case I am passing explicit parameters to the neural net.

```julia
NN = Lux.Chain(Lux.Dense(3, 6, relu),
             Lux.Dense(6, 2, relu)) 
          
NNparams, st = Lux.setup(rng, NN)
parameters = ComponentArray(NNparams = NNparams, uhat = uhat)
u_hat = NN(u, parameters.NNparams, states.st)[1] # Network prediction

#This works for neural net.

```

I tried to update the network using LSTMCell, however it does not work, seems to be arguments and definition error.

```julia
NN = Lux.Chain(Lux.Dense(3 => 3), 
                Lux.StatefulRecurrentCell(Lux.LSTMCell(3 => 6)), 
                Lux.Dense(6 => 2))

# NN = Lux.Chain(Lux.Dense(3 => 3), 
# Lux.Recurrent(Lux.LSTMCell(3 => 6)), 
# Lux.Dense(6 => 2))

```

```julia

MethodError: no method matching (::LSTMCell{true, false, false, Tuple{typeof(WeightInitializers.zeros32), typeof(WeightInitializers.zeros32), typeof(WeightInitializers.ones32), typeof(WeightInitializers.zeros32)}, NTuple{4, typeof(glorot_uniform)}, typeof(WeightInitializers.zeros32), typeof(WeightInitializers.zeros32)})(::Vector{Float64}, ::ComponentVector{Float64, SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}, Tuple{Axis{(weight_i = ViewAxis(1:72, ShapedAxis((24, 3), NamedTuple())), weight_h = ViewAxis(73:216, ShapedAxis((24, 6), NamedTuple())), bias = ViewAxis(217:240, ShapedAxis((24, 1), NamedTuple())))}}}, ::@NamedTuple{rng::StableRNGs.LehmerRNG})

Closest candidates are:
  (::LSTMCell{use_bias, false, false})(!Matched::AbstractMatrix, ::Any, ::NamedTuple) where use_bias
   @ Lux C:\Users\rathorek\.julia\packages\Lux\5xfGO\src\layers\recurrent.jl:397
  (::LSTMCell{true})(!Matched::Tuple{AbstractMatrix, Tuple{AbstractMatrix, AbstractMatrix}}, ::Any, ::NamedTuple)
   @ Lux C:\Users\rathorek\.julia\packages\Lux\5xfGO\src\layers\recurrent.jl:436

```
