Is this tensor computation possible in CNTK?
Hi All,
I have a matrix A [ 50 x 256] and a 3D tensor B [ 2000 x 50 x 256] .
I want to do a element-wise multiplication between A, B over [ * x 50 x 256] dimensions. Then, sum over the axis of dimension 50. The output is a matrix of [ 2000 x 256] dimension.
How to do this in CNTK?
Thanks in advance.
@dongyu888 @frankseide This is little similar to your Deep Tensor Neural Network work. So, I think you guys are familiar with my question asked above.
Did you guys use CNTK for that? Do CNTK has a NDL function to do the Kronecker product?
Thanks, Lahiru
Yes, the tensor product can be implemented using CNTK’s KhatriRaoProduct node.
Which of A and B are minibatch data vs. weight matrices? A=weight, B=data?
KhatriRaoProduct is only defined for matrices. To use that, you would have to first reshape your tensor into matrix form.
Another option:
- reshape A to [1 x 50 x 256] by splitting the first axis
- do an ElementTimes between the reshaped A and B. A will broadcast along the 2000 dimension.
- Transpose(1, 2) (which for tensors will swap the first 2 axes) --> now you have [50 x 2000 x 256]
- Times ( a row of 50 ones, this) --> [1 x 2000 x 256]
- reshape to flatten the first two dimensions --> [2000 x 256]
lahiruts wrote: I have a matrix A [ 50 x 256] and a 3D tensor B [ 2000 x 50 x 256] . I want to do a element-wise multiplication between A, B over [ * x 50 x 256] dimensions. Then, sum over the axis of dimension 50. The output is a matrix of [ 2000 x 256] dimension.
@frankseide I implemented as you suggested. It works as expected. Thanks a lot.