I don't know if I understand what your problem is. But to make a plot similar to that of the figure, I would do something like this:
import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt
sentence = ('list' 'of' 'words' 'that' 'make' 'up' 'the' 'sentence' 'in' 'which' 'the' 'answer' 'is' 'found')
y_pos = np.arange(len(sentence))
probability = [0.1, 0.2, 0.1, 0.8, 0.6]
plt.bar(y_pos, probability, align='center', alpha=0.5)
plt.xticks(y_pos, sentence)
plt.ylabel('Answer probability')
plt.title('Words of the sentence')
plt.show()
So assuming that the answer lies within a larger sentence/paragraph, what I would do is insert all the words of the sentence/paragraph into the x axis of a bar plot (variable sentence
- text.txt I suppose), while on the y axis the percentage indicating the probability that a particular word is the beginning or ending word of the answer (variable probability
). Obviously the two variables sentence
and probability
will have the same length, where the first sentence variable corresponds to the first probability value and so on.
For instance answer_start_scores
and answer_end_scores
will be the words with the highest score, therefore their "bar" of the bar plot will be the highest (highest value in the list of probability).
Finally in answer_start_scores
and answer_end_scores
you should have all the scores for which the starting and ending word is most likely.
EDIT:
Maybe, you could also make two separate bar plots for the initial word of the answer and the final word and then join them together by adding the percentages.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…