# Build a Build deep neural network classifier using a long short-term memory (LSTM) architecture

**URL:** https://discourse.julialang.org/t/build-a-build-deep-neural-network-classifier-using-a-long-short-term-memory-lstm-architecture/129606
**Category:** Machine Learning
**Created:** [June 3, 2025, 4:46pm UTC](https://discourse.julialang.org/t/build-a-build-deep-neural-network-classifier-using-a-long-short-term-memory-lstm-architecture/129606 "2025-06-03T16:46:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ltukondjere](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltukondjere](https://discourse.julialang.org/u/Ltukondjere)
#### Post date: [June 3, 2025, 4:46pm UTC](https://discourse.julialang.org/t/build-a-build-deep-neural-network-classifier-using-a-long-short-term-memory-lstm-architecture/129606/1 "2025-06-03T16:46:35Z")

</div>

Good day,

Please help me. I recently started with Julia and i am trying to use it to build a deep neural network classifier using a long short-term memory (LSTM) architecture. I manage to load my data, did text preprocessing and tokenization, i build my vocabulary and embeddings, load my embeddings, create embedding matrix and covert my text to sequence of indices. I am now stuck at building a model. When i am trying to implement a training loop for a neural network using Flux.jl, i am getting just revolving errors. when i change this one, i get another one, and i am now stuck at building the loop. Kindy help me. my code i below this text. I thank you so much for help.

````for
    Flux.reset!(model)
    
    train_correct = 0
    train_total = 0
    
    # Create batches iterator
    batches = eachbatch((train_X, train_y_onehot), size=batch_size)
    
    for (x, y) in batches
        # 1. Forward pass and accuracy calculation
        ŷ = model(x)
        train_correct += sum(onecold(ŷ) .== onecold(y))
        train_total += size(y, 2)
        
        # 2. Compute gradient
        grads = gradient(model) do m
            ŷ = m(x)
            return Flux.crossentropy(ŷ, y)
        end
        
        # 3. Optimizer update
        opt_state, ps = Optimisers.update(opt, ps, grads[1], opt_state)
    end
    
    # Calculate epoch statistics
    train_acc = train_correct / train_total
    println("Epoch $epoch: Train Accuracy = $train_acc")
end```

and below is the error that i am getting:

```MethodError: no method matching iterate(::Optimisers.Adam)

The function `iterate` exists, but no method is defined for this combination of argument types.

Closest candidates are:

  iterate(::Base.MethodSpecializations)

   @ Base reflection.jl:1299

  iterate(::Base.MethodSpecializations, ::Nothing)

   @ Base reflection.jl:1305

  iterate(::Base.MethodSpecializations, ::Int64)

   @ Base reflection.jl:1306

  ...

Stack trace
Here is what happened, the most recent locations are first:

_zip_iterate_some
from 
iterators.jl:444
_zip_iterate_all
from 
iterators.jl:436
iterate(z::Base.Iterators.Zip{…}) ...show types...
from 
julia → iterators.jl:426
 
foreach(::Function, ::Optimisers.Adam, ::@NamedTuple{…}, ::@NamedTuple{…}, ::Vararg{…}) ...show types...
from 
julia → abstractarray.jl:3188
 
foreachvalue(::Function, ::Optimisers.Adam, ::@NamedTuple{…}, ::Vararg{…}) ...show types...
from 
Optimisers → utils.jl:10
 
_grads!(::IdDict{…}, ::Optimisers.Adam, ::@NamedTuple{…}, ::@NamedTuple{…}, ::Vararg{…}) ...show types...
from 
Optimisers → interface.jl:118
 
update!(tree::Optimisers.Adam, model::@NamedTuple{…}, grad::@NamedTuple{…}, higher::@NamedTuple{…}) ...show types...
from 
Optimisers → interface.jl:74
 
update(tree::Optimisers.Adam, model::@NamedTuple{…}, grad::@NamedTuple{…}, higher::@NamedTuple{…}) ...show types...
from 
Optimisers → interface.jl:67
 
from 
This cell: line 23
        # 3. Optimizer update
        opt_state, ps = Optimisers.update(opt, ps, grads[1], opt_state)
    end```

The Julia version i am using is 1.11.4, 

Thank you for your help.
````

---

<div class="post-metadata">

### Author: ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)
#### Post date: [June 3, 2025, 5:56pm UTC](https://discourse.julialang.org/t/build-a-build-deep-neural-network-classifier-using-a-long-short-term-memory-lstm-architecture/129606/2 "2025-06-03T17:56:23Z")

</div>

Hard to say what is wrong without seeing more code, but that call to `update` on line 23 as mentioned in the error message has an extra argument compared to the [documentation](https://fluxml.ai/Optimisers.jl/stable/api/#Optimisers.update). Did you try

```
opt_state, ps = Optimisers.update(opt_state, ps, grads[1])

```

For that to work, you probably need to change whatever code created `opt` to create `opt_state`.

---

<div class="post-metadata">

### Author: ![Ltukondjere](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@Ltukondjere](https://discourse.julialang.org/u/Ltukondjere)
#### Post date: [June 3, 2025, 6:14pm UTC](https://discourse.julialang.org/t/build-a-build-deep-neural-network-classifier-using-a-long-short-term-memory-lstm-architecture/129606/3 "2025-06-03T18:14:59Z")

</div>

I just did that but i am getting same error.

`opt_state, ps = Optimisers.update(opt, ps, grads[1])`

Okay, thanks. I will try again.

---

<div class="post-metadata">

### Author: ![CarloLucibello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carlolucibello/32/3278_2.png) [@CarloLucibello](https://discourse.julialang.org/u/CarloLucibello)
#### Post date: [June 4, 2025, 4:30am UTC](https://discourse.julialang.org/t/build-a-build-deep-neural-network-classifier-using-a-long-short-term-memory-lstm-architecture/129606/4 "2025-06-04T04:30:03Z")

</div>

`ps` should be replaced by `model` in the `update` call. Make sure you have an updated Flux version and read the corresponding documentation.
