user5497885
user5497885

Reputation:

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 ?

Upvotes: 0

Views: 376

Answers (2)

Wei
Wei

Reputation: 164

I think you could try a python library named "lutorpy". So you can use all the lua/torch libraries and functions in python. It also implemented features for converting between torch tensor and numpy array, which could also be interesting for you.

Upvotes: 1

user5497885
user5497885

Reputation:

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.

Upvotes: 0

Related Questions