Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in AdditiveAttentionForSeq call function due to incompatible dimensions #1

Open
rozhix opened this issue Jul 22, 2024 · 0 comments

Comments

@rozhix
Copy link

rozhix commented Jul 22, 2024

Hello,

I'm using the attention-GRU-piecewise-linear RUL Prediction.ipynb notebook. There is an error in the AdditiveAttentionForSeq class, specifically in the call function at the line concat = tf.concat((state_rep, encoder_outputs), axis = -1). It tries to concatenate a 4D array with a 3D array, which is not possible.

I modified the call function as follows:

def call(self, state, encoder_outputs):
seq_len = encoder_outputs.shape[1]
averaged_state = tf.reduce_mean(tf.stack(state, axis = 1), axis = 1)
state_rep = tf.repeat(tf.expand_dims(averaged_state, axis = 1), repeats = seq_len, axis = 1)
shape = tf.shape(state_rep)
seq_len = shape[1]
batch_size = shape[2]
hidden_dims2 = shape[3]
state_rep = tf.reshape(state_rep, (batch_size, seq_len, hidden_dims2))
concat = tf.concat((state_rep, encoder_outputs), axis = -1)
scores = tf.nn.tanh(self.attention(concat))
attention_weights = tf.nn.softmax(tf.reduce_sum(scores, axis = -1), axis = -1)
return tf.matmul(tf.expand_dims(attention_weights, axis = 1), encoder_outputs)

However, I'm not entirely sure if this is the correct approach to fix the error. Could you please help verify this fix or suggest the correct way to handle this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant