-
Notifications
You must be signed in to change notification settings - Fork 4
/
NLIexampleVis.py
executable file
·50 lines (42 loc) · 1.57 KB
/
NLIexampleVis.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
## FIXME fix the import ###
from visPackage.nlizeModule import nlizeModule
from nli_src import modelInterface
# from NLPutility import translationPerturbation
from NLPutility import sentenceGenerator
from NLPutility import dependencyTree
#initialize NLP model
model = modelInterface(
wordDict="data/snli_1.0/snli_1.0.word.dict",
wordVec="data/glove.hdf5", model="data/local_300_parikh")
#sentence perturbation
# gen = translationPerturbation()
gen = sentenceGenerator()
#dependency parsing
dep = dependencyTree()
#visualization components
visLayout = {
"column":[{"row":["Summary", "Sentence", "Pipeline"]},
{"row":["AttentionGraph", "AttentionMatrix", "Prediction"]}]
}
# visLayout = {
# "column":[{"row":["Summary", "Sentence", "LatentRepresentation"]},
# {"row":["AttentionGraph", "AttentionMatrix", "Prediction"]}]
# }
# visLayout = {
# "column":[{"row":["Summary", "Sentence", "Prediction"]},
# {"row":["AttentionGraph", "AttentionMatrix"]}]
# }
#setup interface
modelVis = nlizeModule(visLayout)
modelVis.setPredictionHook(model.predict)
modelVis.setAttentionHook(model.attention)
modelVis.setPredictionUpdateHook(model.updatePrediction)
modelVis.setAttentionUpdateHook(model.updateAttention)
modelVis.setReloadModelCallback(model.reloadModel)
modelVis.setLayerHook(model.layerValues)
modelVis.setPipelineStatisticHook(model.pipelineStatistic)
modelVis.setSentencePerturbationHook(gen.perturbSentence)
modelVis.setSentenceParserHook(dep.getDependencyTree)
#open browser for visualization
# modelVis.show()
modelVis.startServer()