Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

get alignments using attention #138

Open
kmario23 opened this issue Oct 6, 2017 · 7 comments
Open

get alignments using attention #138

kmario23 opened this issue Oct 6, 2017 · 7 comments

Comments

@kmario23
Copy link

kmario23 commented Oct 6, 2017

Hi,
With a trained model checkpoint, I evaluated it on a set of 'test' sentences. In the result, I get some <unk> tokens in translated sentences. Now, I'd like to solve this issue by figuring out which words in source sentence caused these unk tokens.

For this, as far as I understand, we can use the attention mechanism to get the word alignments? But, I'm not sure where exactly I should start doing this in the current NMT codebase. could someone please point out the exact point where such an implementation can be done?

Or is there any other way to get the alignment of words?

Interestingly, a dictionary can be extracted from alignment with scores as mentioned here: En-Vi alignment dictionary

It'd be nice to know how to get this dictionary. Maybe @lmthang can offer suggestions please?

Thanks!

@oahziur
Copy link
Contributor

oahziur commented Oct 12, 2017

Hi @kmario23 ,

We save the alignment as an image in the _sample_decode method if you don't use a beam search decoder with an attention model. The image can be visualized in tensorboard.

You can look at this method to see how we extract the alignment history from the final state.

@d2sys
Copy link

d2sys commented Nov 21, 2017

Hi @kmario23 ,

Have you solved it?

Thanks

@Chen-Wang-CUHK
Copy link

Hi @oahziur ,
If we use a beam search decoder with an attention model, is there any convenient method to get the "alignment_history" ?
Thanks!

@ttrouill
Copy link

ttrouill commented Feb 9, 2018

I do use a beam search decoder too, and also with num_translations_per_input > 1,
I am quite interested in getting the alignments too.

Can you point us to where to look at to get the alignments with a beam search decoder?
And when num_translations_per_input > 1, how to get the alignments of each output translation for a single input?

@tslater
Copy link

tslater commented Apr 17, 2018

@oahziur, I see that they check if beam width is 0. Is there a reason? Does beam search prevent the alignment from happening?

@kritinemkul
Copy link

I try to get alignment using beam width 0 but can't. Is there any way to visualize the alignment for a particular sentence?

@durson
Copy link

durson commented Nov 6, 2018

Is there any progress in solving that issue?

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

No branches or pull requests

8 participants