CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Is this tensor computation possible in CNTK?

Open lahiruts opened this issue 10 years ago • 4 comments

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.

lahiruts avatar Apr 06 '16 05:04 lahiruts

@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

lahiruts avatar Apr 08 '16 10:04 lahiruts

Yes, the tensor product can be implemented using CNTK’s KhatriRaoProduct node.

dongyu888 avatar Apr 08 '16 14:04 dongyu888

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 avatar Apr 08 '16 16:04 frankseide

@frankseide I implemented as you suggested. It works as expected. Thanks a lot.

lahiruts avatar Apr 11 '16 08:04 lahiruts