解释 python 中的 Lua 代码
interpreting Lua code in python
我有这一段Lua-Torch代码,试着把它放到Python代码中。
我很难理解 result/process 的含义:
= 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 库和函数。它还实现了在 torch 张量和 numpy 数组之间转换的功能,这对您来说也很有趣。
我有这一段Lua-Torch代码,试着把它放到Python代码中。 我很难理解 result/process 的含义:
= 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 库和函数。它还实现了在 torch 张量和 numpy 数组之间转换的功能,这对您来说也很有趣。