Search code examples
pythonluatorch

interpreting Lua code in python


I have this piece of Lua-Torch code and try to put into Python code. I have difficulty to understand the meaning result/process of:

= nn.Linear(size1
t2h_d.data.module:share(

   import 'nn'
   import 'nngraph'

   nh_t= nn.identity(d)
   h_d= nn.identity(d)

    size1= 5
    t2h_d = nn.Linear(size1, 4 * size1)(h_t):annotate{name='ih_'..L}  
    d2h_d = nn.Linear(size1, 4 * size1)(h_d):annotate{name='hh_'..L}  


    t2h_d.data.module:share(shared_weights[1], 'weight', 'bias', 'grdWeight', 'grdBias')
    d2h_d.data.module:share(shared_weights[2], 'weight', 'bias', 'grdWeight', 'grdBias')

Can somebody knows the equivalent in numpy python ?


Solution

  • This piece of code in LUA

    t2h_d.data.module:share(shared_weights[1], 'weight', 'bias')
    

    means t2h_d tensor will use the used stored in share_weights[1]

    nn.Linear(size1, 4 * size1)(h_t):annotate{name='ih_'..L}  
    

    means a linear product W.h_t is done and the result is called ih_L, W has the following size: size1, 4 * size1

    Those precisions are useful since LUA nn lacks of documentation.