使用 Python 解释 Lua 代码

我有一段 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 代码吗?

点赞
用户88888888
用户88888888

以下是 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}

这段代码表示对 h_t 进行一个线性操作 W.h_t,结果被命名为 ih_L, 其中,矩阵 W 的大小为:size1, 4 * size1。

这些细节对于 LUA nn 缺乏文档的情况非常有用。

2016-05-22 05:09:12
用户6262499
用户6262499

我认为你可以尝试使用一个名为“ lutorpy” 的 Python 库。这样你就可以在 Python 中使用所有的 Lua/Torch 库和函数。它还实现了在 Torch 张量和 NumPy 数组之间进行转换的功能,这对你也可能很有兴趣。

2016-05-30 08:48:29