I see this type of syntax a lot in some Lua source file I was reading lately, what does it mean, especially the second pair of brackets An example, line 8 in https://github.com/karpathy/char-rnn/blob/master/model/LSTM.lua
local LSTM = {}
function LSTM.lstm(input_size, rnn_size, n, dropout)
dropout = dropout or 0
-- there will be 2*n+1 inputs
local inputs = {}
table.insert(inputs, nn.Identity()()) -- line 8
-- ...
The source code of nn.Identity
https://github.com/torch/nn/blob/master/Identity.lua
********** UPDATE **************
The ()() pattern is used in torch library 'nn' a lot. The first pair of bracket creates an object of the container/node, and the second pair of bracket references the depending node.
For example, y = nn.Linear(2,4)(x) means x connects to y, and the transformation is linear from 1*2 to 1*4. I just understand the usage, how it is wired seems to be answered by one of the answers below.
Anyway, the usage of the interface is well documented below. https://github.com/torch/nngraph/blob/master/README.md
In complement to Yu Hao's answer let me give some Torch related precisions:
nn.Identity()
creates an identity module,()
called on this module triggersnn.Module
__call__
(thanks to Torch class system that properly hooks up this into the metatable),__call__
method performs a forward / backward,In consequence every
nn.Identity()()
calls has here for effect to return anngraph.Node({module=self})
node where self refers to the currentnn.Identity()
instance.--
Update: an illustration of this syntax in the context of LSTM-s can be found here: