-
Notifications
You must be signed in to change notification settings - Fork 4
/
MCexampleVis.py
executable file
·33 lines (27 loc) · 983 Bytes
/
MCexampleVis.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
from visPackage import MCModule
from bidaf_src import bidafModelInterface
# translation perturbation require googleclound key
# from NLPutility import translationPerturbation
from NLPutility import sentenceGenerator
#initialize machine comprehension model
model = bidafModelInterface(
wordDict="data/bidaf/squad.word.dict",
wordVec="data/bidaf/glove.hdf5",
model="data/bidaf/bidaf_clip5_20.ema")
# gen = translationPerturbation()
gen = sentenceGenerator()
# visualization components
# attention is linked to paragraph
visLayout = {
"column":[{"row": ["Paragraph",
"AttentionSubMatrix"]},
{"row": ["AttentionAsymmetric"]}]
}
#setup interface
modelVis = MCModule(visLayout)
modelVis.setPredictionHook(model.predict)
modelVis.setAttentionHook(model.attention)
modelVis.setReloadModelCallback(model.reloadModel)
modelVis.setSentencePerturbationHook(gen.perturbSentence)
#open browser for visualization
modelVis.startServer()