I want to know how to find for a source word its correspondent target word in translation tokens in OpenNMT-py
Maybe look at the
-attn_debug translation option that prints attention information of each target words.
Thank you , I found it
I have one doubt regarding attention debug which I am using through ctranslate module.
I am doing the below translation english to hindi:
src: He is a learned counsel from India.
tgt: वह भारत के विद्वत अधिवक्ता हैं।
here the translation of learned counsel is विद्वत अधिवक्ता
if I see the attention vector for 3rd target subword ‘▁विद्वत’,
the maximum value is at 4th position(i=3) which refers to src token ‘▁learned’, which is absolutely correct.
But when I look at attenton scores for next target subword ‘▁अधिवक्ता’,
I should ideally get the max attention score at position 5(i=4) which should refer to ‘▁counsel’,
however this is not happening and for 5th target token(subword) the maximum attention score for src token refers to ‘▁.’] and after that this ‘▁is’,
Kindly clarify my doubt.I am using transformer based NMT system.
Did you train your Transformer model with guided alignment? If not, the attention probabilities usually can not be used as alignment.
could you please elaborate this point about guided alignement. How to achieve that?
And my aim is to have this alignment.
See for example:
I see that has been implemented in OpenNMT-py
do we have instructions on how to achieve this in OpenNmt
Do you mean OpenNMT-tf? If yes, this is documented here: https://opennmt.net/OpenNMT-tf/alignments.html
for OpenNmt-py only
You should look at the pull request linked above: https://github.com/OpenNMT/OpenNMT-py/pull/1615
There also is an entry in the FAQ: https://opennmt.net/OpenNMT-py/FAQ.html#can-i-get-word-alignment-while-translating
is it a good idea to train your transformer with fast align or giza as suggested in FAQ. The point is nowadays everyone uses subword based model. These will give alignment for subwords which may not exactlty make sense at word level.
Also are these fast align and giza++ language agnostic?? will it support all languages pair alignment?
For subwords, see my reply here, and the paper mentioned: Best way to handle emojis during translation
Not sure it’s 100% language agnostic, as the results may vary depending on the language pair (and you may need to apply some preprocessing, tokenization for instance, to your data), but it should work for most pairs (https://www.aclweb.org/anthology/N13-1073.pdf).