-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxtrack2_interactive.py
76 lines (60 loc) · 1.84 KB
/
xtrack2_interactive.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import time
import json
import logging
import numpy as np
import os
import dstc_util
from data_model import Dialog
from xtrack_data2 import XTrackData2
from xtrack2_dstc_tracker import XTrack2DSTCTracker
from utils import pdb_on_error
from model import Model
def main(model_file):
logging.info('Loading model from: %s' % model_file)
model = Model.load(model_file, build_train=False)
x = []
x_score = []
x_switch = []
y_seq_id = []
y_time = []
while True:
words = raw_input('Input:')
words = words.lower()
tokens = words.split()
seqs = []
for token in tokens:
x.append(model.vocab.get(token, model.vocab['#OOV']))
x_score.append(11)
x_switch.append(0)
seqs.append({
'data': x,
'data_score': x_score,
'data_actor': x_switch,
'data_switch': x_switch,
'labels': [
{
'time': len(x) - 1,
'slots': {
},
'score': 0.0
}
],
'token_labels': []
})
data = model.prepare_data_predict(seqs, [])
p = model._predict(*data)
for slot_name, p_slot in zip(model.slots, p):
print '#', slot_name
preds = {}
for cls_name, i in model.slot_classes[slot_name].iteritems():
preds[cls_name] = p_slot[0][i]
for cls, pp in sorted(preds.iteritems(), key=lambda x: -x[1])[:1]:
print '%10s: %.2f' % (cls, pp, )
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--model_file', required=True)
pdb_on_error()
from utils import init_logging
init_logging()
main(**vars(parser.parse_args()))