lstm-tagger Linear Layer

6 views
Skip to first unread message

ZEYNEP ABALI

unread,
Nov 12, 2021, 11:06:14 AM11/12/21
to COMP541
Hi,

I am receiving the following error during the implementation of the Linear layer cell. 

P(Knet.KnetArrays.KnetVector{Float32}(200))
P(Knet.KnetArrays.KnetMatrix{Float32}(200,100))
MethodError: no method matching randn(::Param{Knet.KnetArrays.KnetVector{Float32}}, ::Param{Knet.KnetArrays.KnetMatrix{Float32}})

Stacktrace:
 [1] Linear(inputsize::Param{Knet.KnetArrays.KnetMatrix{Float32}}, outputsize::Param{Knet.KnetArrays.KnetVector{Float32}}, atype::Type, scale::Float64)
   @ Main ./In[9]:25
 [2] Linear(inputsize::Param{Knet.KnetArrays.KnetMatrix{Float32}}, outputsize::Param{Knet.KnetArrays.KnetVector{Float32}})
   @ Main ./In[9]:23
 [3] Linear(inputsize::Int64, outputsize::Int64, atype::Type, scale::Float64)
   @ Main ./In[9]:28
 [4] Linear(inputsize::Int64, outputsize::Int64)
   @ Main ./In[9]:23
 [5] top-level scope
   @ In[9]:39
 [6] eval
   @ ./boot.jl:360 [inlined]
 [7] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1116


---
If I print outputsize and inputsize in the function, then it prints them as integers.

If I put the exact test values instead of the variable names (outputsize, inputsize), then I get a StackOverflow error, or else it never stops.

I am trying to implement it similarly to the implementation of Embedding.

Also, the embedding cell (which is already implemented), passes the test when I run it on Colab, but not on my machine. It was passing with 1.5.4 with the non-updated version.

Thank you for any help.

Best,
Zeynep

Shadi Sameh Hamdan

unread,
Nov 12, 2021, 12:35:32 PM11/12/21
to ZEYNEP ABALI, COMP541
Hello Zeynep,

It seems you are passing the wrong arguments to the call to Linear. I am guessing that it is a constructor issue. Are you trying something like:

struct Linear
     w
     b
     function Linear(input_dim, output_dim)
          w = randn...
          b = randn...
          Linear(w, b)
     end
end

In this situation, you are not defining the constructor properly. This is because the constructor function you defined is recursively calling itself, hence the stack overflow. When defining a constructor in this way, you should use the new() function to construct an instance of Linear. Please review the julia documentation and difference between inner and outer constructors.

Best,
Shadi 

--
You received this message because you are subscribed to the Google Groups "COMP541" group.
To unsubscribe from this group and stop receiving emails from it, send an email to COMP541+u...@ku.edu.tr.
To view this discussion on the web visit https://groups.google.com/a/ku.edu.tr/d/msgid/COMP541/CAPWEfCLRgOqjXvkMHgesRCtpeG_RZn7iiCVt-8KhETwv0wBCMw%40mail.gmail.com.

ZEYNEP ABALI

unread,
Nov 12, 2021, 2:42:05 PM11/12/21
to Shadi Sameh Hamdan, COMP541
Hi,

Thank you for your answer. I solved it. Also, in the implementation of NERTagger I am failing the test as below, but the rest of the code works including the full training. Is this difference acceptable?

┌ Info: Testing forward pass of NERTagger
└ @ Main In[42]:25
Test Failed at In[42]:32
  Expression: sum(output) == 0.4713313f0
   Evaluated: 0.47133106f0 == 0.4713313f0
There was an error during testing
Stacktrace:

Thank you for your help.

Best,
Zeynep

Shadi Sameh Hamdan

unread,
Nov 12, 2021, 2:46:50 PM11/12/21
to ZEYNEP ABALI, COMP541
Hello Zeynep,

Yes, a difference of that scale shouldn't be an issue if everything else works fine.

Best,
Shadi
Reply all
Reply to author
Forward
0 new messages