Tensorflow has the function:
tf.matmul
Which multiplies two vectors and produces a scalar.
However, I need to do the following:
# dense dim: (?,227)
dense_part = tf.nn.relu(some stuff here)
# softmax matrix dim: (?,227,19) or (?,19,227) or (?,227,227), where I
# ....can slice the last dim down to (?,227,19)
softmax_matrix = tf.matmul(dense_part,softmax_weight_variable)
However, there is nothing I can set softmax_weight_variable to in order to accomplish this with a matrix multiplication. I need to use the "Tensor Product" (also called "Outer Product"...) but this function doesn't seem to be implemented.
How do I implement a Hadamard (element-wise) multiplication and Outer Product in TensorFlow?
math. multiply. Returns an element-wise x * y.
js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf. dot() function is used to compute the dot product of two given matrices or vectors, t1 and t2.
Tensordot (also known as tensor contraction) sums the product of elements from a and b over the indices specified by axes . This operation corresponds to numpy. tensordot(a, b, axes) . Example 1: When a and b are matrices (order 2), the case axes=1 is equivalent to matrix multiplication.
Elementwise multiplication of x
and y
is just tf.mul(x, y)
. This also supports NumPy-style broadcasting, which you should be able to use to get an outer product if you need one.
It is tf.multiply
in Tensorflow 1.11. The functions provides Hadamard product of two tensors with equal shapes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With