Skip to content

Commit 63ab35a

Browse files
authored
Handle large mutliclass better in WIT (#2385)
Models with many classes (like 100) had display issues in WIT
1 parent ff05d1a commit 63ab35a

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

tensorboard/plugins/interactive_inference/tf_interactive_inference_dashboard/tf-interactive-inference-dashboard.html

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,10 @@
10171017
margin-left: 30px;
10181018
}
10191019

1020+
.scroll-x {
1021+
overflow-x: auto;
1022+
}
1023+
10201024
.perf-table-clickable {
10211025
cursor: pointer;
10221026
}
@@ -2081,7 +2085,7 @@ <h2>Show similarity to selected datapoint</h2>
20812085
</div>
20822086
</div>
20832087
<iron-collapse opened="{{featureValueThreshold.opened}}">
2084-
<div class="perf-table-entry-expanded flex-row-reverse">
2088+
<div class="perf-table-entry-expanded flex-row-reverse scroll-x">
20852089
<div>
20862090
<template is="dom-if" if="[[shouldShowFeaturePrCharts_(selectedLabelFeature, selectedBreakdownFeature, inferences)]]">
20872091
<div class="conf-matrix-holder">
@@ -2124,7 +2128,7 @@ <h2>Show similarity to selected datapoint</h2>
21242128
</div>
21252129
</div>
21262130
</div>
2127-
<div class="perf-table-entry-expanded flex-row-reverse">
2131+
<div class="perf-table-entry-expanded flex-row-reverse scroll-x">
21282132
<template is="dom-if" if="[[shouldShowOverallPrChart_(selectedLabelFeature, selectedBreakdownFeature, inferences)]]">
21292133
<div class="conf-matrix-holder">
21302134
<div class="conf-text">Confusion matrix</div>
@@ -5032,10 +5036,41 @@ <h2>Show similarity to selected datapoint</h2>
50325036
*/
50335037
addChart: function(chartType, featureName, data){
50345038
let chart;
5039+
let dataToChart = data;
5040+
5041+
// If multiclass and there are more inferred classes than the set
5042+
// number of classes to display, then filter the classes to display
5043+
// in the chart down to the top scoring classes.
5044+
if (this.isMultiClass_(this.modelType, this.multiClass)) {
5045+
dataToChart = [];
5046+
for (let modelIdx = 0; modelIdx < data.length; modelIdx++) {
5047+
let modelDataToChart = {};
5048+
if (Object.keys(data[modelIdx]).length >
5049+
Number(this.maxInferenceEntriesPerRun)) {
5050+
const exampleId = this.selected &&
5051+
this.selected.length > 0 ? this.selected[0] : 0;
5052+
// Get the class labels of the top scoring classes from the most
5053+
// recent inference.
5054+
const currentExample = this.examplesAndInferences[exampleId];
5055+
const lastInference = currentExample.inferences[
5056+
currentExample.inferences.length - 1];
5057+
const labels = lastInference[modelIdx].slice(
5058+
0, this.maxInferenceEntriesPerRun);
5059+
for (let labelIdx = 0; labelIdx < labels.length; labelIdx++) {
5060+
const label = labels[labelIdx].label;
5061+
modelDataToChart[label] = data[modelIdx][label];
5062+
}
5063+
} else {
5064+
modelDataToChart = data[modelIdx];
5065+
}
5066+
dataToChart.push(modelDataToChart);
5067+
}
5068+
}
5069+
50355070
if (chartType == 'numeric'){
5036-
chart = this.makeLineChart(featureName, data);
5071+
chart = this.makeLineChart(featureName, dataToChart);
50375072
} else if (chartType == 'categorical'){
5038-
chart = this.makeBarChart(featureName, data);
5073+
chart = this.makeBarChart(featureName, dataToChart);
50395074
} else {
50405075
console.error('Unknown chartType: ' + chartType);
50415076
}

0 commit comments

Comments
 (0)