tensorflow / nmt

TensorFlow Neural Machine Translation Tutorial
Apache License 2.0
6.36k stars 1.96k forks source link

Attention visualization #358

Open yapingzhao opened 6 years ago

yapingzhao commented 6 years ago

Hi, What is the command to get the alignments between source and target sentences ? Looking forward to your advice or answers. Best regards, Thank you very much!

hpulfc commented 6 years ago

@yapingzhao hack in source , when beam_width=0, nmt will output the final_state , then you can find the alignments.

JulianZhang commented 5 years ago

@hpulfc Dear, where I can find the final_state and alignments? thanks

hpulfc commented 5 years ago

@JulianZhang
see the code in nmt/attention_model.py . it in the method named _create_attention_images_summary like this:

def _create_attention_images_summary(final_context_state):
    pass
kritinemkul commented 5 years ago

@hpulfc can you please elaborate how to visualize the attention matrix for particular source and target sentence ?

ranjita-naik commented 5 years ago

you can backtrace function : plot_attention in this notebook - https://github.com/tensorflow/tensorflow/blob/r1.11/tensorflow/contrib/eager/python/examples/nmt_with_attention/nmt_with_attention.ipynb. Do let me know if it doesn't work for you.

kritinemkul commented 5 years ago

@ranjita-naik i tried but it won't work. As I have trained my model and i have corresponding translated file too using tensorflow nmt . I want to view attention of those any of input and output sentences. Would you please suggest how to visualize the attention on tensorflow nmt. Thank you in advance.

ranjita-naik commented 5 years ago

@kritinemkul, what's the error? as shown in the evaluate(sentence, encoder, decoder, inp_lang, targ_lang, max_length_inp, max_length_targ) function, are you collecting attention weights during inference?

kritinemkul commented 5 years ago

@ranjita-naik, this only works for the pairs which are printed in third cell and there is nothing any like development set and test set. If i gave the sentence other than the printed it will give error of unknown keyword. What i want is, trained the model and infer the out put sentences too as shown in the nmt tutorial. I am unable to show attention for those sentences. Is there any way to visualize attention for those sentence in tensorboard on in command prompt or in any way?