Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow: Hadamard Product:: How do I get this?

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?

like image 800
Chris Avatar asked Apr 26 '16 20:04

Chris


People also ask

What does TF multiply do?

math. multiply. Returns an element-wise x * y.

Which of the following is used to find dot product of two matrix in Tensorflow?

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.

What is Tensordot in Python?

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.


2 Answers

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.

like image 122
user2357112 supports Monica Avatar answered Oct 16 '22 06:10

user2357112 supports Monica


It is tf.multiply in Tensorflow 1.11. The functions provides Hadamard product of two tensors with equal shapes.

like image 36
A.Ametov Avatar answered Oct 16 '22 08:10

A.Ametov