def process(question, candidates=None, top_n=1, n_docs=5):
predictions = DrQA.process(
question, candidates, top_n, n_docs, return_context=True
)
table = prettytable.PrettyTable(
['Rank', 'Answer', 'Doc', 'Answer Score', 'Doc Score']
)
for i, p in enumerate(predictions, 1):
table.add_row([i, p['span'], p['doc_id'],
'%.5g' % p['span_score'],
'%.5g' % p['doc_score']])
print('Top Predictions:')
print(table)
print('\nContexts:')
for p in predictions:
text = p['context']['text']
start = p['context']['start']
end = p['context']['end']
output = (text[:start] +
colored(text[start: end], 'green', attrs=['bold']) +
text[end:])
print('[ Doc = %s ]' % p['doc_id'])
print(output + '\n')
评论列表
文章目录