-
Notifications
You must be signed in to change notification settings - Fork 253
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
GradientSimilarity
- allow models of any input type
#912
GradientSimilarity
- allow models of any input type
#912
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #912 +/- ##
==========================================
- Coverage 85.32% 85.28% -0.05%
==========================================
Files 74 74
Lines 8804 8834 +30
==========================================
+ Hits 7512 7534 +22
- Misses 1292 1300 +8
|
Can you give me an idea of the use case by describing a simple example? Is it just that if you have a model with a text embedding layer you might want |
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.
LGTM for the most part. I have some minor questions but once they're answered I'm happy to merge.
One thing is that a lot of the logic is conditional statements of the form if instance(x, np.ndarray) ... else ...
which if may be possible to refactor into something more modular. If the logic is really generic then can we just add a method that deals with each input type:
def _format(self, x):
if isinstance(x, Tensors):
# other formatting that makes sense here
return x[None]
elif isinstance(x, List):
return [x]
This way if we add new cases later then it's just a case of extending this function rather than making lots of small changes... I'm not sure the above is possible though, just something to think about!
bfe563e
to
94dc01a
Compare
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.
Looks good, a few minor comments.
Was wondering if there would be much effort to add a small end-to-end test calculating explanations on a model operating on List[Any]
?
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.
LGTM
Gradient Similarity
- allow models of any input type
Gradient Similarity
- allow models of any input typeGradientSimilarity
- allow models of any input type
This PR extends the support for the
GradientSimilarity
explainer to support other data types apart fromnp.ndarray
,torch.Tensor
andtf.Tensor
.This extension is useful when a user defines a custom model for text modality, for example, for which the input is a list of strings. Note that for
tensorflow
we can get around this issue by casting the input to anumpy
array of string. This is becausetensorflow
can convert fromnumpy
string totensorflow
string tensors. Unfortunately, forpytorch
the string type is not supported.