繁体   English   中英

在python中解释Lua代码

[英]interpreting Lua code in python

我有这段Lua-Torch代码,并尝试放入Python代码中。 我很难理解以下内容的含义结果/过程:

= 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')

有人可以知道numpy python中的等效方法吗?

LUA中的这段代码

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

表示t2h_d张量将使用存储在share_weights [1]中的

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

表示完成了线性乘积W.h_t,结果称为ih_L,W的大小如下:size1,4 * size1

由于LUA nn缺乏文档,因此这些精度非常有用。

我认为您可以尝试一个名为“ lutorpy ”的python库。 因此,您可以在python中使用所有lua / torch库和函数。 它还实现了在割炬张量和numpy数组之间转换的功能,这对您也可能很有趣。

暂无
暂无

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

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