Applying softmax to non-zero elements in the matrix across a dimension

ساخت وبلاگ
چکیده : Vote count: 0 Perhaps this is trivial,... با عنوان : Applying softmax to non-zero elements in the matrix across a dimension بخوانید :

Vote count: 0

Perhaps this is trivial, but perhaps it is not. I have spent way too much time trying to figure out how to make this work. Here is the code:

# batch x time x events
batch = 2
time = 3
events = 4
tensor = np.random.rand(batch, time, events)

tensor[0][0][2] = 0
tensor[0][0][3] = 0

tensor[0][1][3] = 0

tensor[0][2][1] = 0
tensor[0][2][2] = 0
tensor[0][2][3] = 0

tensor[1][0][3] = 0

non_zero = ~tf.equal(tensor, 0.)

s = tf.Session()
g = tf.global_variables_initializer()
s.run(g)

s.run(non_zero)

I am trying to apply tf.nn.softmax to the non-zero values across each of the time dimensions. However, when I am using tf.boolean_mask then it actually gathers all of the non-zero values together. That is not what I want. I want to preserve the dimensions.

Here is the screenshot of what the tensor looks like: enter image description here

So tf.nn.softmax should be applied to only those groups and it should "put them back" into their original positions. Does anyone know how to do this?

asked 21 secs ago
i squared - Keep it Real

back soft...
ما را در سایت back soft دنبال می کنید

نویسنده : استخدام کار بازدید : 21 تاريخ : پنجشنبه 28 تير 1397 ساعت: 1:43