用python解释Lua代码

2024-09-30 16:29:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这段luatorch代码,并尝试将其放入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中的等价物吗?你知道吗


Tags: 代码nameimportsharedatannidentityshared
2条回答

LUA中的这段代码

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

意味着t2h\u d张量将使用存储在share\u weights[1]中的所使用的

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

表示一个线性积W.h\u t,其结果称为ih\u L, W的尺寸如下:1号,4*1号

这些精度是有用的,因为luann缺乏文档。你知道吗

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

相关问题 更多 >