-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WIT ability to consume arbitrary prediction-time information #2660
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b1f5d9c
extra outputs
jameswex 54969d4
fix
jameswex 2784fda
fix spacing
jameswex b0cb9ed
review comments
jameswex dcbf3e1
lint
jameswex 1578373
fix
jameswex 82b72c4
Merge branch 'master' into extra_outputs
jameswex 4f7afee
review comments
jameswex b5b47b1
typing
jameswex 1636fa3
Merge branch 'master' into extra_outputs
jameswex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3266,6 +3266,10 @@ <h2>Show similarity to selected datapoint</h2> | |
observer: 'newInferences_', | ||
value: () => ({}), | ||
}, | ||
extraOutputs: { | ||
type: Object, | ||
observer: 'newExtraOutputs_', | ||
}, | ||
// Attributions from inference. A dict with two fields: 'indices' and | ||
// 'attributions'. Indices contains a list of example indices that | ||
// these new attributions apply to. Attributions contains a list of | ||
|
@@ -3778,12 +3782,16 @@ <h2>Show similarity to selected datapoint</h2> | |
} else { | ||
this.comparedIndices = []; | ||
this.counterfactualExampleAndInference = null; | ||
const temp = this.selectedExampleAndInference; | ||
this.selectedExampleAndInference = null; | ||
this.selectedExampleAndInference = temp; | ||
this.refreshSelectedDatapoint_(); | ||
} | ||
}, | ||
|
||
refreshSelectedDatapoint_: function() { | ||
const temp = this.selectedExampleAndInference; | ||
this.selectedExampleAndInference = null; | ||
this.selectedExampleAndInference = temp | ||
}, | ||
|
||
findClosestCounterfactual_: function() { | ||
const selected = this.selected[0]; | ||
const modelInferenceValueStr = this.strWithModelName_( | ||
|
@@ -5856,6 +5864,71 @@ <h2>Show similarity to selected datapoint</h2> | |
this.updatedExample = false; | ||
}, | ||
|
||
newExtraOutputs_: function(extraOutputs) { | ||
// Set attributions from the extra outputs, if available. | ||
const attributions = []; | ||
for (let i = 0; i < extraOutputs.extra.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i -> modelNum would be better here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if ('attributions' in extraOutputs.extra[i]) { | ||
attributions.push(extraOutputs.extra[i].attributions); | ||
} | ||
} | ||
if (attributions.length > 0) { | ||
this.attributions = { | ||
'indices': extraOutputs.indices, | ||
'attributions': attributions, | ||
}; | ||
} | ||
|
||
// Add extra output information to datapoints | ||
for (let i = 0; i < extraOutputs.indices.length; i++) { | ||
const idx = extraOutputs.indices[i]; | ||
const datapoint = Object.assign({}, this.visdata[idx]); | ||
for ( | ||
let modelNum = 0; | ||
modelNum < extraOutputs.extra.length; | ||
modelNum++ | ||
) { | ||
const keys = Object.keys(extraOutputs.extra[modelNum]); | ||
for (let j = 0; j < keys.length; j++) { | ||
const key = keys[j]; | ||
// Skip attributions as they are handled separately above. | ||
if (key == 'attributions') { | ||
continue; | ||
} | ||
let val = extraOutputs.extra[modelNum][key][i]; | ||
|
||
// Update the datapoint with the extra info for use in | ||
// Facets Dive. | ||
datapoint[datapointKey] = val; | ||
|
||
// Convert the extra output into an array if necessary, for | ||
// insertion into tf.Example as a value list, for update of | ||
// examplesAndInferences for the example viewer. | ||
if (!Array.isArray(val)) { | ||
val = [val]; | ||
} | ||
const isString = val.length > 0 && | ||
(typeof val[0] == 'string' || val[0] instanceof String); | ||
const datapointKey = this.strWithModelName_(key, modelNum); | ||
const exampleJsonString = JSON.stringify( | ||
this.examplesAndInferences[idx].example | ||
); | ||
const copiedExample = JSON.parse(exampleJsonString); | ||
copiedExample.features.feature[datapointKey] = isString ? | ||
{bytesList: {value: val}} : {floatList: {value: val}}; | ||
this.examplesAndInferences[idx].example = copiedExample; | ||
} | ||
} | ||
this.set(`visdata.${idx}`, datapoint); | ||
} | ||
this.refreshDive_(); | ||
|
||
// Update selected datapoint so that if a datapoint is being viewed, | ||
// the display is updated with the appropriate extra output. | ||
this.computeSelectedExampleAndInference(); | ||
this.refreshSelectedDatapoint_(); | ||
}, | ||
|
||
newAttributions_: function(attributions) { | ||
if (Object.keys(attributions).length == 0) { | ||
return; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some comments here like you did with attributions below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to define the type using closure type syntax? It does not have to be correct but it is for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added @type {indices: Array, extra: Array<{Object}>} but am not too familiar with closure.
If I want to specify that the Object above is a dict with arbitrary keys where each value in the dict is an array of numbers or strings, can I do that as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, TypeScript types are all expressable in Closure and vice a versa. I believe you can do
!Object<string, number>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx done