-
Notifications
You must be signed in to change notification settings - Fork 169
/
wit-inference-viewer.html
325 lines (303 loc) · 8.75 KB
/
wit-inference-viewer.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!--
@license
Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../iron-icons/iron-icons.html" />
<link rel="import" href="../tf-imports/polymer.html" />
<!-- Displays the results of inferences in the what-if tool side panel. -->
<dom-module id="wit-inference-viewer">
<template>
<style>
:host {
display: block;
}
.runs-holder {
padding: 0;
display: flex;
flex-direction: column-reverse;
overflow-y: auto;
max-height: 200px;
}
.row {
display: flex;
color: #3c4043;
font-size: 12px;
}
.header {
color: #80868b;
font-size: 12px;
padding: 4px 0;
border-bottom: solid 1px #dadce0;
border-top: solid 1px #dadce0;
}
.dark-row-one {
background: #cbf0f8;
}
.dark-row-two {
background: #fff3e0;
}
.white-row {
background: white;
}
.marker {
flex: 0.5;
margin-right: 5px;
}
.marker.mark-one {
background: #007b83;
padding-left: 1px;
}
.marker.mark-two {
background: #ff9800;
padding-left: 1px;
}
.run {
flex: 10;
}
.multi-model {
flex: 10;
}
.one-model {
display: none;
}
.show-label {
flex: 20;
display: flex;
overflow: hidden;
}
.no-label {
display: none;
}
.score {
flex: 10;
}
.arrow {
flex: 2;
}
.delta {
flex: 10;
}
.text {
margin-top: 4px;
}
.green {
color: green;
}
.red {
color: red;
}
</style>
<div class="row header">
<div class="marker"></div>
<div class="run">Run</div>
<div class$="[[getModelHeaderClass(inferences)]]">Model</div>
<div class$="[[getLabelHeaderClass(modelType)]]">Label</div>
<div class="score">[[getScoreLabel(modelType)]]</div>
<div class="arrow"></div>
<div class="delta">Delta</div>
</div>
<div class="runs-holder">
<template
is="dom-repeat"
items="[[inferences]]"
as="modelsInference"
index-as="runindex"
>
<div class="rows-for-run">
<template
is="dom-repeat"
items="[[modelsInference]]"
as="inference"
index-as="modelindex"
>
<template
is="dom-repeat"
items="[[getInferenceList(inference, maxEntriesPerRun)]]"
>
<div class$="[[getRowClass(runindex, inferences, modelindex)]]">
<div
class$="[[getMarkerClass(runindex, inferences, modelindex)]]"
></div>
<div class="run text">[[getRunNumber(runindex)]]</div>
<div class$="[[getModelClass(inferences)]]">
<div>[[getModelName(modelNames, modelindex)]]</div>
</div>
<div class$="[[getLabelClass(modelType)]]">
<div>[[getLabel(item)]]</div>
</div>
<div class="score text">[[getPrintableScore(item.score)]]</div>
<div class="arrow">
<iron-icon
icon="[[getIcon(runindex, index, modelindex)]]"
class$="[[getIconClass(runindex, index, modelindex)]]"
>
</iron-icon>
</div>
<div class="delta text">
[[getPrintableDelta(runindex, index, modelindex)]]
</div>
</div>
</template>
</template>
</div>
</template>
</div>
</template>
<script>
Polymer({
is: 'wit-inference-viewer',
properties: {
inferences: Array,
// Possible modelType values currently 'regression and 'classification'.
modelType: String,
modelNames: Array,
maxEntriesPerRun: {
type: Number,
value: 5,
},
},
getLabel: function(item) {
let label = item.label;
if (item.vocabLabel) {
label += ' (' + item.vocabLabel + ')';
}
return label;
},
getLabelClass: function(modelType) {
return modelType == 'classification' ? 'show-label text' : 'no-label';
},
getLabelHeaderClass: function(modelType) {
return modelType == 'classification' ? 'show-label' : 'no-label';
},
getModelClass: function(inferences) {
return inferences && inferences[0].length > 1
? 'multi-model text'
: 'one-model';
},
getModelHeaderClass: function(inferences) {
return inferences && inferences[0].length > 1
? 'multi-model'
: 'one-model';
},
getScoreLabel: function(modelType) {
return modelType == 'classification' ? 'Score' : 'Value';
},
getIconClass: function(runIndex, labelIndex, modelIndex) {
return this.getIconDecision(
runIndex,
labelIndex,
modelIndex,
'green',
'red'
);
},
getIcon: function(runIndex, labelIndex, modelIndex) {
return this.getIconDecision(
runIndex,
labelIndex,
modelIndex,
'icons:arrow-upward',
'icons:arrow-downward'
);
},
/**
* Returns upVal or downVal depending on if value from latest inference
* is higher or lower than from previous inference.
*/
getIconDecision: function(
runIndex,
labelIndex,
modelIndex,
upVal,
downVal
) {
// No up or down on first run.
if (runIndex == 0) {
return '';
}
const inferenceIndex = runIndex;
const label = this.inferences[inferenceIndex][modelIndex][labelIndex]
.label;
const score = this.inferences[inferenceIndex][modelIndex][labelIndex]
.score;
const previousInference = this.inferences[inferenceIndex - 1][
modelIndex
];
for (let i = 0; i < previousInference.length; i++) {
if (previousInference[i].label == label) {
if (previousInference[i].score > score) {
return downVal;
}
if (previousInference[i].score < score) {
return upVal;
}
return '';
}
}
return upVal;
},
getRunNumber: function(index) {
return index + 1;
},
getModelName: function(names, index) {
return names[index];
},
getMarkerClass: function(index, inferences, modelIndex) {
return (
'marker' +
(inferences != null && index == inferences.length - 1
? modelIndex == 0
? ' mark-one'
: ' mark-two'
: '')
);
},
getRowClass: function(index, inferences, modelIndex) {
let str = 'row ';
if (inferences != null && index == inferences.length - 1) {
str += modelIndex == 0 ? 'dark-row-one' : 'dark-row-two';
} else {
str += 'white-row';
}
return str;
},
getInference: function(inference, index) {
return inference;
},
getPrintableScore: function(score) {
return score.toFixed(3);
},
getPrintableDelta: function(runIndex, labelIndex, modelIndex) {
if (runIndex == 0) {
return '';
}
const inferenceIndex = runIndex;
const label = this.inferences[inferenceIndex][modelIndex][labelIndex]
.label;
const score = this.inferences[inferenceIndex][modelIndex][labelIndex]
.score;
const previousInference = this.inferences[inferenceIndex - 1][
modelIndex
];
for (let i = 0; i < previousInference.length; i++) {
if (previousInference[i].label == label) {
return (score - previousInference[i].score).toFixed(6);
}
}
return '';
},
getInferenceList: function(inferenceList, maxEntries) {
return inferenceList.slice(0, maxEntries);
},
});
</script>
</dom-module>