简体   繁体   English

如何在批处理数据上使用点生产?

[英]how to use dot production on batch data?

I am trying to apply tanh(dot(x,y)) ; 我正在尝试使用tanh(dot(x,y)) ; x and y are batch data of my RNN. x和y是我的RNN的批处理数据。

x,y have shape (n_batch, n_length, n_dim) like (2,3,4) ; x,y的形状为(n_batch,n_length,n_dim)像(2,3,4); 2 samples with 3 sequences, each is 4 dimensions. 具有3个序列的2个样本,每个样本为4维。

I want to do inner or dot production to last dimension. 我想对最后一个尺寸进行内部或点生产。 Then tanh(dot(x,y)) should have shape of (n_batch, n_length) = (2, 3) 然后tanh(dot(x,y))的形状应为(n_batch,n_length)=(2,3)

Which function should I use? 我应该使用哪个功能?

This expression should do the trick: 这个表达式应该可以解决这个问题:

theano.tensor.tanh((x * y).sum(2)) theano.tensor.tanh((x * y).sum(2))

The dot product is computed 'manually' by doing element-wise multiplication, then summing over the last dimension. 点积是通过逐元素相乘,然后对最后一个维度求和来“手动”计算的。

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

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