-
Notifications
You must be signed in to change notification settings - Fork 35
/
start_demo.py
50 lines (48 loc) · 1.61 KB
/
start_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pathlib
import gdown
import argparse
import torch
from allennlp.models.archival import Archive, load_archive, archive_model
from allennlp.data.vocabulary import Vocabulary
from smbop.modules.relation_transformer import *
from allennlp.common import Params
from smbop.models.smbop import SmbopParser
from smbop.modules.lxmert import LxmertCrossAttentionLayer
from smbop.dataset_readers.spider import SmbopSpiderDatasetReader
import itertools
import smbop.utils.node_util as node_util
import numpy as np
from allennlp.models import Model
from allennlp.common.params import *
from allennlp.data import DatasetReader, Instance
import tqdm
from allennlp.predictors import Predictor
import json
overrides = {
"dataset_reader": {
"tables_file": "dataset/tables.json",
"dataset_path": "dataset/database",
},
"validation_dataset_reader": {
"tables_file": "dataset/tables.json",
"dataset_path": "dataset/database",
}
}
predictor = Predictor.from_path(
"model.tar.gz", cuda_device=0, overrides=overrides
)
instance_0 = predictor._dataset_reader.text_to_instance(
utterance="asds", db_id="aircraft"
)
predictor._dataset_reader.apply_token_indexers(instance_0)
def inference(question,db_id):
instance = predictor._dataset_reader.text_to_instance(
utterance=question, db_id=db_id,
)
predictor._dataset_reader.apply_token_indexers(instance)
with torch.cuda.amp.autocast(enabled=True):
out = predictor._model.forward_on_instances(
[instance, instance_0]
)
return out[0]["sql_list"]
print(inference("How many films cost below 10 dollars?","cinema"))