Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No method matching next(::AutoGrad.Rec{Dict{Symbol,Any}}, ::Int64) #109

Closed
ngphuoc opened this issue Apr 6, 2017 · 3 comments
Closed

No method matching next(::AutoGrad.Rec{Dict{Symbol,Any}}, ::Int64) #109

ngphuoc opened this issue Apr 6, 2017 · 3 comments
Assignees
Labels

Comments

@ngphuoc
Copy link

ngphuoc commented Apr 6, 2017

I am trying to add L2 regularization at the end of s2s() method in prof/s2s.jl and get the mentioned error. The added line is

sumlogp += 0.001 * sum(sumabs2(a) for (k,a) in model if isa(a, KnetArray))
@denizyuret
Copy link
Owner

denizyuret commented Apr 6, 2017 via email

@denizyuret
Copy link
Owner

I had a chance to look at this in more detail, there were several problems:

  • AutoGrad does not support Dict iteration. This can be fixed by:
Base.next{T<:Associative}(a::Rec{T},i) = ((kv,j)=next(a.value,i);(k,v)=kv;(k=>a[k],j))

I will add this to AutoGrad.

  • isa(a, KnetArray) won't work, you need isa(getval(a),KnetArray). When you index elements of a model AutoGrad changes their type to keep track of dependencies.
  • Finally this won't work either because the model has a hierarchical structure and not all values are KnetArrays. If you really want to calculate L2, I'd write a function that explicitly goes through model[:embed1], model[:encode][1], model[:encode][2] etc.

@denizyuret
Copy link
Owner

Fixed in latest AutoGrad master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants