From 6a002d89594a62b1c3bf02bcf8fd047f40f12055 Mon Sep 17 00:00:00 2001 From: Vivek Miglani Date: Tue, 22 Mar 2022 09:24:18 -0700 Subject: [PATCH 1/2] Fix lime example --- captum/attr/_core/lime.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/captum/attr/_core/lime.py b/captum/attr/_core/lime.py index b568c5cd0a..e1a8dd956d 100644 --- a/captum/attr/_core/lime.py +++ b/captum/attr/_core/lime.py @@ -394,6 +394,10 @@ def attribute( >>> # input will be different and may have a smaller feature set, so >>> # an appropriate transformation function should be provided. >>> + >>> def to_interp_transform(curr_sample, original_inp, + >>> **kwargs): + >>> return curr_sample + >>> >>> # Generating random input with size 2 x 5 >>> input = torch.randn(2, 5) >>> # Defining LimeBase interpreter @@ -403,7 +407,7 @@ def attribute( perturb_func=perturb_func, perturb_interpretable_space=False, from_interp_rep_transform=None, - to_interp_rep_transform=lambda x: x) + to_interp_rep_transform=to_interp_transform) >>> # Computes interpretable model, returning coefficients of linear >>> # model. >>> attr_coefs = lime_attr.attribute(input, target=1, kernel_width=1.1) From 73a07b6582728cf1ed92d084ca9c8a732886ee91 Mon Sep 17 00:00:00 2001 From: Vivek Miglani Date: Tue, 22 Mar 2022 09:45:32 -0700 Subject: [PATCH 2/2] Fix --- captum/attr/_core/lime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/captum/attr/_core/lime.py b/captum/attr/_core/lime.py index e1a8dd956d..5099eaad5a 100644 --- a/captum/attr/_core/lime.py +++ b/captum/attr/_core/lime.py @@ -398,8 +398,8 @@ def attribute( >>> **kwargs): >>> return curr_sample >>> - >>> # Generating random input with size 2 x 5 - >>> input = torch.randn(2, 5) + >>> # Generating random input with size 1 x 5 + >>> input = torch.randn(1, 5) >>> # Defining LimeBase interpreter >>> lime_attr = LimeBase(net, SkLearnLinearModel("linear_model.Ridge"),