MCPcopy Create free account
hub / github.com/pytorch/tutorials / showAttention

Function showAttention

intermediate_source/seq2seq_translation_tutorial.py:820–835  ·  view source on GitHub ↗
(input_sentence, output_words, attentions)

Source from the content-addressed store, hash-verified

818#
819
820def showAttention(input_sentence, output_words, attentions):
821 fig = plt.figure()
822 ax = fig.add_subplot(111)
823 cax = ax.matshow(attentions.cpu().numpy(), cmap='bone')
824 fig.colorbar(cax)
825
826 # Set up axes
827 ax.set_xticklabels([''] + input_sentence.split(' ') +
828 ['<EOS>'], rotation=90)
829 ax.set_yticklabels([''] + output_words)
830
831 # Show label at every tick
832 ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
833 ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
834
835 plt.show()
836
837
838def evaluateAndShowAttention(input_sentence):

Callers 1

evaluateAndShowAttentionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected