An option to get answer URIs from KBQA model

Dear community,

I was recently exploring the KBQA system of DeepPavlov. Currently, the answers that I get from KBQA are just strings, e.g.:

kbqa_model(['What is the currency of Sweden?'])
>>> ["Swedish krona"]

Is there an option to get the actual URIs (when applicable)? For example,

kbqa_model(['What is the currency of Sweden?'])
>>> ["https://www.wikidata.org/wiki/Q122922"]

In line 53 of the config file indicate

"return_answer_ids": true

Then the system will return answers in tuples (answer_string, answer_id).

2 Likes

Thanks for your reply, any guidance on how do I do it from python code, or how can I add my own config?

You can change existing configs from python code using this code snippet:

from deeppavlov.core.common.file import read_json
from deeppavlov import configs, build_model

config_file = read_json(configs.kbqa.kbqa_cq_en)
config_file['chainer']['pipe'][7]['return_answer_ids'] = True

kbqa_model = build_model(config_file)
kbqa_model(['What is the currency of Sweden?'])
>>> [('Swedish krona', 'Q122922')]

Thanks for your help!