Skip to content

Commit

Permalink
factoid qa fixes (#143)
Browse files Browse the repository at this point in the history
* Fix requirements.txt (#84)

* fix itsdangerous requirements

* pin itsdangerous requirements for all flask==1.1.1 servers

* factoid qa fixes

* update

* reformat

* update kbqa

* codestyle

* codestyle

* fix tests

* codestyle

* update requests version

* fixes

* fixes

* fixes

* fixes

* fixes

* add get_factoid function

* codestyle

* use get_factoid

* codestyle

Co-authored-by: Andrii.Hura <[email protected]>
Co-authored-by: mtalimanchuk <[email protected]>
Co-authored-by: Dilyara Baymurzina <[email protected]>
  • Loading branch information
4 people authored Apr 29, 2022
1 parent 75b1010 commit 5fb0798
Show file tree
Hide file tree
Showing 13 changed files with 618 additions and 28 deletions.
3 changes: 2 additions & 1 deletion annotators/entity_detection/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pyopenssl==22.0.0
Flask==1.1.1
itsdangerous==2.0.1
nltk==3.2.5
numpy==1.15.4
gunicorn==19.9.0
requests==2.22.0
requests==2.27.1
jinja2<=3.0.3
Werkzeug<=2.0.3
sentry-sdk==0.12.3
2 changes: 1 addition & 1 deletion annotators/kbqa/kbqa_cq_mt_bert_lite.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{
"class_name": "rel_ranking_infer",
"id": "rel_r_inf",
"ranker": {"config_path": "{CONFIGS_PATH}/classifiers/rel_ranking_bert_lite.json"},
"ranker": {"config_path": "/src/rel_ranking_bert_en.json"},
"load_path": "{DOWNLOADS_PATH}/wikidata_eng",
"rel_q2name_filename": "wiki_dict_properties.pickle",
"rels_to_leave": 40
Expand Down
115 changes: 115 additions & 0 deletions annotators/kbqa/rel_ranking_bert_en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"dataset_reader": {
"class_name": "sq_reader",
"data_path": "{DOWNLOADS_PATH}/rel_ranking_eng/lcquad_rel_ranking.pickle"
},
"dataset_iterator": {
"class_name": "basic_classification_iterator",
"seed": 42
},
"chainer": {
"in": ["question", "rel_list"],
"in_y": ["y"],
"pipe": [
{
"class_name": "torch_transformers_preprocessor:RelRankingPreprocessor",
"vocab_file": "{TRANSFORMER}",
"do_lower_case": true,
"max_seq_length": 64,
"add_special_tokens": ["<q>", "</q>", "<rel_sep>"],
"in": ["question", "rel_list"],
"out": ["bert_features"]
},
{
"id": "classes_vocab",
"class_name": "simple_vocab",
"fit_on": ["y"],
"save_path": "{MODEL_PATH}/classes.dict",
"load_path": "{MODEL_PATH}/classes.dict",
"in": ["y"],
"out": ["y_ids"]
},
{
"in": ["y_ids"],
"out": ["y_onehot"],
"class_name": "one_hotter",
"depth": "#classes_vocab.len",
"single_vector": true
},
{
"class_name": "torch_transformers_classifier:TorchTransformersClassifierModel",
"n_classes": "#classes_vocab.len",
"return_probas": "true",
"num_special_tokens": 3,
"pretrained_bert": "{TRANSFORMER}",
"save_path": "{MODEL_PATH}/model",
"load_path": "{MODEL_PATH}/model",
"optimizer": "AdamW",
"optimizer_parameters": {
"lr": 1e-05
},
"learning_rate_drop_patience": 5,
"learning_rate_drop_div": 2.0,
"in": ["bert_features"],
"in_y": ["y_ids"],
"out": ["y_pred_probas"]
},
{
"in": ["y_pred_probas"],
"out": ["y_pred_ids"],
"class_name": "proba2labels",
"max_proba": true
},
{
"in": ["y_pred_ids"],
"out": ["y_pred_labels"],
"ref": "classes_vocab"
}
],
"out": ["y_pred_probas"]
},
"train": {
"epochs": 3,
"batch_size": 30,
"metrics": [
{
"name": "roc_auc",
"inputs": [
"y_onehot",
"y_pred_probas"
]
},
"accuracy",
"f1_macro"
],
"validation_patience": 5,
"val_every_n_batches": 100,
"log_every_n_batches": 100,
"show_examples": false,
"evaluation_targets": [
"train",
"valid",
"test"
],
"class_name": "torch_trainer"
},
"metadata": {
"variables": {
"ROOT_PATH": "~/.deeppavlov",
"DOWNLOADS_PATH": "{ROOT_PATH}/downloads",
"MODELS_PATH": "{ROOT_PATH}/models",
"TRANSFORMER": "haisongzhang/roberta-tiny-cased",
"MODEL_PATH": "{MODELS_PATH}/classifiers/rel_ranking_bert_eng_torch"
},
"download": [
{
"url": "http://files.deeppavlov.ai/kbqa/wikidata/rel_ranking_bert_eng_torch.tar.gz",
"subdir": "{MODELS_PATH}/classifiers/rel_ranking_bert_eng_torch"
},
{
"url": "http://files.deeppavlov.ai/kbqa/wikidata/lcquad_rel_ranking.pickle",
"subdir": "{DOWNLOADS_PATH}/rel_ranking_eng"
}
]
}
}
5 changes: 4 additions & 1 deletion annotators/kbqa/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
pyopenssl==22.0.0
sentry-sdk[flask]==0.14.1
flask==1.1.1
itsdangerous==2.0.1
gunicorn==19.9.0
requests==2.22.0
requests==2.27.1
jinja2<=3.0.3
Werkzeug<=2.0.3
click==7.1.2
torch==1.6.0
transformers==4.6.0
3 changes: 2 additions & 1 deletion annotators/kbqa/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def respond():
kbqa_input = [sanitized_questions, sanitized_questions, template_types, sanitized_entities, entity_types]
else:
kbqa_input = [sanitized_questions]
logger.info(f"kbqa_input: {kbqa_input}")
default_resp = {"qa_system": "kbqa", "answer": "", "confidence": 0.0}
out_res = [default_resp for _ in questions]
try:
Expand All @@ -71,7 +72,7 @@ def respond():
answer, conf = res[cnt_fnd]
out_res.append({"qa_system": "kbqa", "answer": answer, "confidence": float(conf)})
cnt_fnd += 1
logger.info(f"kbqa exec time: {time.time() - st_time}")
logger.info(f"kbqa exec time: {time.time() - st_time} out_res {out_res}")
except Exception as e:
sentry_sdk.capture_exception(e)
logger.exception(e)
Expand Down
Loading

0 comments on commit 5fb0798

Please sign in to comment.