@@ -145,7 +145,7 @@ def attribute( # type: ignore
145
145
) -> Union [
146
146
TensorOrTupleOfTensorsGeneric , Tuple [TensorOrTupleOfTensorsGeneric , Tensor ]
147
147
]:
148
- r""""
148
+ r"""
149
149
Args:
150
150
151
151
inputs (tensor or tuple of tensors): Input for which
@@ -165,23 +165,25 @@ def attribute( # type: ignore
165
165
Baselines can be provided as:
166
166
167
167
- a single tensor, if inputs is a single tensor, with
168
- exactly the same dimensions as inputs or the first
169
- dimension is one and the remaining dimensions match
170
- with inputs.
168
+ exactly the same dimensions as inputs or the first
169
+ dimension is one and the remaining dimensions match
170
+ with inputs.
171
171
172
172
- a single scalar, if inputs is a single tensor, which will
173
- be broadcasted for each input value in input tensor.
173
+ be broadcasted for each input value in input tensor.
174
174
175
175
- a tuple of tensors or scalars, the baseline corresponding
176
- to each tensor in the inputs' tuple can be:
177
- - either a tensor with matching dimensions to
178
- corresponding tensor in the inputs' tuple
179
- or the first dimension is one and the remaining
180
- dimensions match with the corresponding
181
- input tensor.
182
- - or a scalar, corresponding to a tensor in the
183
- inputs' tuple. This scalar value is broadcasted
184
- for corresponding input tensor.
176
+ to each tensor in the inputs' tuple can be:
177
+
178
+ - either a tensor with matching dimensions to
179
+ corresponding tensor in the inputs' tuple
180
+ or the first dimension is one and the remaining
181
+ dimensions match with the corresponding
182
+ input tensor.
183
+
184
+ - or a scalar, corresponding to a tensor in the
185
+ inputs' tuple. This scalar value is broadcasted
186
+ for corresponding input tensor.
185
187
186
188
In the cases when `baselines` is not provided, we internally
187
189
use zero scalar corresponding to each input tensor.
@@ -195,21 +197,21 @@ def attribute( # type: ignore
195
197
For general 2D outputs, targets can be either:
196
198
197
199
- a single integer or a tensor containing a single
198
- integer, which is applied to all input examples
200
+ integer, which is applied to all input examples
199
201
200
202
- a list of integers or a 1D tensor, with length matching
201
- the number of examples in inputs (dim 0). Each integer
202
- is applied as the target for the corresponding example.
203
+ the number of examples in inputs (dim 0). Each integer
204
+ is applied as the target for the corresponding example.
203
205
204
206
For outputs with > 2 dimensions, targets can be either:
205
207
206
208
- A single tuple, which contains #output_dims - 1
207
- elements. This target index is applied to all examples.
209
+ elements. This target index is applied to all examples.
208
210
209
211
- A list of tuples with length equal to the number of
210
- examples in inputs (dim 0), and each tuple containing
211
- #output_dims - 1 elements. Each tuple is applied as the
212
- target for the corresponding example.
212
+ examples in inputs (dim 0), and each tuple containing
213
+ #output_dims - 1 elements. Each tuple is applied as the
214
+ target for the corresponding example.
213
215
214
216
Default: None
215
217
additional_forward_args (any, optional): If the forward function
@@ -232,9 +234,11 @@ def attribute( # type: ignore
232
234
computing final attribution scores. This function can take
233
235
at least one and at most three arguments with the
234
236
following signature:
235
- - custom_attribution_func(multipliers)
236
- - custom_attribution_func(multipliers, inputs)
237
- - custom_attribution_func(multipliers, inputs, baselines)
237
+
238
+ - custom_attribution_func(multipliers)
239
+ - custom_attribution_func(multipliers, inputs)
240
+ - custom_attribution_func(multipliers, inputs, baselines)
241
+
238
242
In case this function is not provided, we use the default
239
243
logic defined as: multipliers * (inputs - baselines)
240
244
It is assumed that all input arguments, `multipliers`,
@@ -608,21 +612,21 @@ def attribute( # type: ignore
608
612
corresponding references. Baselines can be provided as:
609
613
610
614
- a single tensor, if inputs is a single tensor, with
611
- the first dimension equal to the number of examples
612
- in the baselines' distribution. The remaining dimensions
613
- must match with input tensor's dimension starting from
614
- the second dimension.
615
+ the first dimension equal to the number of examples
616
+ in the baselines' distribution. The remaining dimensions
617
+ must match with input tensor's dimension starting from
618
+ the second dimension.
615
619
616
620
- a tuple of tensors, if inputs is a tuple of tensors,
617
- with the first dimension of any tensor inside the tuple
618
- equal to the number of examples in the baseline's
619
- distribution. The remaining dimensions must match
620
- the dimensions of the corresponding input tensor
621
- starting from the second dimension.
621
+ with the first dimension of any tensor inside the tuple
622
+ equal to the number of examples in the baseline's
623
+ distribution. The remaining dimensions must match
624
+ the dimensions of the corresponding input tensor
625
+ starting from the second dimension.
622
626
623
627
- callable function, optionally takes `inputs` as an
624
- argument and either returns a single tensor
625
- or a tuple of those.
628
+ argument and either returns a single tensor
629
+ or a tuple of those.
626
630
627
631
It is recommended that the number of samples in the baselines'
628
632
tensors is larger than one.
@@ -634,21 +638,21 @@ def attribute( # type: ignore
634
638
For general 2D outputs, targets can be either:
635
639
636
640
- a single integer or a tensor containing a single
637
- integer, which is applied to all input examples
641
+ integer, which is applied to all input examples
638
642
639
643
- a list of integers or a 1D tensor, with length matching
640
- the number of examples in inputs (dim 0). Each integer
641
- is applied as the target for the corresponding example.
644
+ the number of examples in inputs (dim 0). Each integer
645
+ is applied as the target for the corresponding example.
642
646
643
647
For outputs with > 2 dimensions, targets can be either:
644
648
645
649
- A single tuple, which contains #output_dims - 1
646
- elements. This target index is applied to all examples.
650
+ elements. This target index is applied to all examples.
647
651
648
652
- A list of tuples with length equal to the number of
649
- examples in inputs (dim 0), and each tuple containing
650
- #output_dims - 1 elements. Each tuple is applied as the
651
- target for the corresponding example.
653
+ examples in inputs (dim 0), and each tuple containing
654
+ #output_dims - 1 elements. Each tuple is applied as the
655
+ target for the corresponding example.
652
656
653
657
Default: None
654
658
additional_forward_args (any, optional): If the forward function
@@ -671,9 +675,11 @@ def attribute( # type: ignore
671
675
computing final attribution scores. This function can take
672
676
at least one and at most three arguments with the
673
677
following signature:
674
- - custom_attribution_func(multipliers)
675
- - custom_attribution_func(multipliers, inputs)
676
- - custom_attribution_func(multipliers, inputs, baselines)
678
+
679
+ - custom_attribution_func(multipliers)
680
+ - custom_attribution_func(multipliers, inputs)
681
+ - custom_attribution_func(multipliers, inputs, baselines)
682
+
677
683
In case this function is not provided we use the default
678
684
logic defined as: multipliers * (inputs - baselines)
679
685
It is assumed that all input arguments, `multipliers`,
0 commit comments