DeepPavlov поставляется с набором предопределенных компонентов, работающих на TensorFlow и Keras для решения проблем, связанных с NLP.
Тот, который вы используете, является BERT для ответа на вопрос. Контекстный ответ на вопрос - это задача найти ответ на вопрос в заданном контексте (например, абзац из Википедии), где ответом на каждый вопрос является сегмент контекста.
Модель возвращает нижеприведенное при вызове model(contexts_list, questions_list)
answers_list, answers_starts_list, logits_list
Пример 1:
from deeppavlov import build_model, configs
model = build_model(configs.squad.squad_bert)
model(['DeepPavlov is library for NLP and dialog systems.'], ['What is DeepPavlov?'])
Output-
INFO:tensorflow:Restoring parameters from C:\Users\RF00538236\.deeppavlov\models\squad_bert\model
[['library for NLP and dialog systems'], [14], [158.80197143554688]]
Ответ возвращает список ответов, стартовый список ответов (ответ присутствует в 14-м символе) и список логитов.
Пример 2 : Скопировал контекст о Махатме Ганди, из здесь .
model(['Born and raised in a Hindu family in coastal Gujarat, western India, Gandhi was trained in law at the Inner Temple, London, and called to the bar at age 22 in June 1891. After two uncertain years in India, where he was unable to start a successful law practice, he moved to South Africa in 1893 to represent an Indian merchant in a lawsuit. He went on to stay for 21 years. It was in South Africa that Gandhi raised a family, and first employed nonviolent resistance in a campaign for civil rights.'],['What was Gandhi trained at?'])
Вывод -
[['law'], [91], [106616.5390625]]
В качестве альтернативы, вы можете построить deeppavlov Взаимодействующий с моделью. Вы можете взаимодействовать с моделью, запустив ее из командной строки с параметром взаимодействия и именем файла конфигурации модели (-d указывает на загрузку всех необходимых файлов). В противном случае вы можете использовать build_model из Python кода Jupyter, как в примере ниже.
Установка зависимостей -
!python -m deeppavlov install tfidf_logreg_en_faq
Пример 1 -
from deeppavlov import configs
from deeppavlov.core.common.file import read_json
from deeppavlov.core.commands.infer import build_model
faq = build_model(configs.faq.tfidf_logreg_en_faq, download = True)
a = faq(["I need help"])
a
Вывод -
[['If you have any further inquiries, you can address them to the International Students Office, which is located in the Auditorium Building, Room 315. The phone number is (7-495) 408-7043.'],
[[0.0005971888349561158,
0.0004990413077070781,
0.0003260898111600398,
0.0004955716039888539,
0.9920733828654503,
0.0004564850775432216,
0.0012178910790545932,
0.0006631341572001673,
0.0006362137679856412,
0.0010445215260383672,
0.0011939766282353169,
0.0004438081627736979,
0.00035269517790671484]]]
Пример 2 -
a = faq(["i need help on medical offices"])
a
Вывод -
[['All Russian universities have medical offices for first aid and general medical care.'],
[[0.00030839735143966185,
0.0005853193249863691,
0.0004579660993813656,
0.0004773336684218436,
0.4791163218068051,
0.00028413386610718364,
0.0009917714916957442,
0.00047599362403134946,
0.000766086074333974,
0.0007509714241461073,
0.5120912464072629,
0.0032745806081316926,
0.0004198782532568704]]]
Надеюсь, что это ответ на ваш вопрос. Счастливого обучения.