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

attention trick implementation #2525

Closed
kingfengji opened this issue Apr 27, 2016 · 5 comments
Closed

attention trick implementation #2525

kingfengji opened this issue Apr 27, 2016 · 5 comments

Comments

@kingfengji
Copy link

kingfengji commented Apr 27, 2016

Hey guys!
Inspired by the attention LSTM,

Each time I have 3 input vectors, say x_1, x_2 and x_3.

I wish to first make a linear combination layer_I = a_1_x1+a2_x2+a3*x3

Then I merge this layer with some other sequencial layers.

I wish to learn the a_1 a_2 and a_3

How to do it in keras????

THANKS !!!!!!!!!!!!
with love

@braingineer
Copy link
Contributor

Typically the attention is done with a single MLP that maps vectors to scores, then uses those scores in a softmax to get a probability distribution over the vectors. Finally, you hadamard the probability distribution and initial vectors, sum over the sequence dimension (dimension 1).

here's some code I wrote to do this.
https://gist.github.com/braingineer/27c6f26755794f6544d83dec2dd27bbb

Though, you should definitely read up on attention further. Bahdanau et al have a great paper on it.

@philipperemy
Copy link

Have a look at this:

https://github.com/philipperemy/keras-simple-attention-mechanism

It's a very simple Hello world attention mechanism but might address your needs!

@v1nc3nt27
Copy link

@braingineer Thanks for your code. Do you have a toy example on how to use it?

@stale
Copy link

stale bot commented Nov 15, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

@stale stale bot added the stale label Nov 15, 2017
@ghost
Copy link

ghost commented Jun 6, 2018

@briangineer does your code include bahdanu's attention

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

5 participants