Trouble printing results of 'model_qa'

I could ran the below code snippet, but not able to find out how to print the answer. I noticed model_qa has five array elements, but not able to figure out how to eventually print the answer to this question. Pls help.

from deeppavlov import build_model, configs
model_qa = build_model(configs.squad.squad_bert, download=True)
model_qa(["In meteorology, precipitation is any product of the condensation of atmospheric water vapor that falls under gravity."],
     ["What is precipitation?"])

Hi, @KG_KG
In your case model_qa returns list with only 3 elements (could you write 5 elements that you are talking about if I am wrong):

  • list of predicted answers
  • list with indexes of answers start in context string (first model_qa argument)
  • list of logits

Thus to print answer to this question you have to run following code:

from deeppavlov import build_model, configs
model_qa = build_model(configs.squad.squad_bert, download=True)
answers, ans_indexes, logits = model_qa(["In meteorology, precipitation is any product of the condensation of atmospheric water vapor that falls under gravity."],
                                        ["What is precipitation?"])
print(answers[0])

Thanks a lot. It worked like a charm. :slightly_smiling_face:

1 Like