0
$\begingroup$

Problem Description:

I am trying to access the individual elements (i.e., scalar) from a softmax layer's output (with dimension (,2)) and multiply this with a tensor from another model, which has a dimension of (,10). A mock-up digram describing my problem is shown in the attached Figure.

I am using Keras with Tensorflow as the back-end. So far, my approach has been the following: Lets say the output dimension of the softmax layer is (,2) (i.e., a vector of size 2). First, my plan is to access the individual elements of this vector (tensor according to the Keras/tensorflow) using the keras.backend.gather(a_k_p,0). Where, the variable a_k_p references the SoftmaxLayer. However, gather simply gives the entire row and does not give the individual element. So, my first question is how to access individual elements of a layer's output?

Assuming I get an answer to the above question, I am describing my idea to multiply a scalar with a tensor as follows. First, replicate this scalar element to create a vector (i.e., a tensor) of size that matches with the DenseLayerA and DenseLayerB (in this case (,10)) and perform the multiplication. Now, I am not sure if this is the right approach since I am unsuccessful in retrieving the individual elements of the Sofmax Layer's output. So, is my approach correct? if not, what is the right way to solve my problem.

Refer This

$\endgroup$

1 Answer 1

0
$\begingroup$

This line of code will select the highest value in your softmax function. If you'd like more than one value just change the 1 to whichever value you'd like. I hope this helps.

top_value = tf.nn.in_top_k(logits, y, 1)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.