简体   繁体   中英

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 ?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM