简体   繁体   English

在python中解释Lua代码

[英]interpreting Lua code in python

I have this piece of Lua-Torch code and try to put into Python code. 我有这段Lua-Torch代码,并尝试放入Python代码中。 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 ? 有人可以知道numpy python中的等效方法吗?

This piece of code in LUA LUA中的这段代码

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

means t2h_d tensor will use the used stored in share_weights[1] 表示t2h_d张量将使用存储在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 表示完成了线性乘积W.h_t,结果称为ih_L,W的大小如下:size1,4 * size1

Those precisions are useful since LUA nn lacks of documentation. 由于LUA nn缺乏文档,因此这些精度非常有用。

I think you could try a python library named " lutorpy ". 我认为您可以尝试一个名为“ lutorpy ”的python库。 So you can use all the lua/torch libraries and functions in python. 因此,您可以在python中使用所有lua / torch库和函数。 It also implemented features for converting between torch tensor and numpy array, which could also be interesting for you. 它还实现了在割炬张量和numpy数组之间转换的功能,这对您也可能很有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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