I am reviewing someone else’s code and came across this anonymous functions. Could you please help me understand: (1) when it is executed and how it is called, and (2) the syntax why there is “(token)” the second type passed in separate pair of parenthesis. I would have expected “function(m::Int64, token)”
The code exactly as you typed should not work (extra space) and what you are seeing is most likely not an anonymous function. I don’t know where you get that code from but you are most likely seeing (d::Int)(x::Int) = d + x?
My question is more about how this function is defined and executed.
function (m::SentimentModel)(token_onehot)
Flux.reset!(m.lstm1)
Flux.reset!(m.lstm2)
embed(x) = m.W_Embed * x’
e = embed.(token_onehot)
w = @. m.lstm2(m.lstm1(e))
logits = m.d(m.lstm2.state[1]) # We just need the last hidden state of the LSTM
return Flux.softmax(logits), logits
end