Numpy theano,索引一个值相对较小的大型矩阵,但超出了边界
这是我的theano代码的一部分,用于dl4mt(神经机器翻译),带有行号。 src_positions是int64的向量,我打印了结果,值不超过16。 但是当我使用src_位置索引注意力_掩码_时,其形状是(100100)。它得到了索引越界错误 奇怪的是:Numpy theano,索引一个值相对较小的大型矩阵,但超出了边界,numpy,theano,Numpy,Theano,这是我的theano代码的一部分,用于dl4mt(神经机器翻译),带有行号。 src_positions是int64的向量,我打印了结果,值不超过16。 但是当我使用src_位置索引注意力_掩码_时,其形状是(100100)。它得到了索引越界错误 奇怪的是: 首先,注意遮罩和高斯遮罩形状相同 当我使用0.1*src_位置进行索引时(将第5行替换为注释的第4行)。第8行保持不变,程序运行良好 更奇怪的是,当我用注释过的第7行替换第8行,但保持第5行不变时,程序仍然可以运行 我不确定问题是否是。。。
1] p_t_s = p_t * sntlens # n_samples * 1, pt in equation
2] src_positions = tensor.cast(tensor.floor(p_t_s), 'int64') # (n_samples, 1)
3] src_positions = src_positions.reshape([src_positions.shape[0], ])
4] # batch_mask = attention_mask_[tensor.cast(src_positions * 0.1, 'int64')] # n_sample * maxlen
5] batch_mask = attention_mask_[src_positions] # n_sample * maxlen
6] attn_mask = batch_mask[:, :msk_.shape[0]] * msk_.T # n_sample * n_timestep
7] # batch_gauss_mask = gaussian_mask_[tensor.cast(src_positions * 0.1, 'int64')] # n_sample * maxlen
8] batch_gauss_mask = gaussian_mask_[src_positions] # n_sample * maxlen
9] gauss_mask = batch_gauss_mask[:, :msk_.shape[0]] * msk_.T # n_sample * n_timestep
问题似乎发生在src_位置的基础上。根据你的描述,不会有任何问题。可能src_位置是由您的代码更改的,而不是您发布的零件是的,没错。我发现了这个bug,它是由我的代码的其他部分引起的。非常感谢