Hello all, I want to measure the feature importance in a multivariate time series. The model definition is as follows -
class Network(nn.Module): def __init__(self, input_size = 4, hidden_dimensions = 16, num_layers = 3, num_outputs = 2, seq_length = 3): super(Network, self).__init__() self.num_layers = num_layers self.hidden_size = hidden_dimensions self.seq_length = seq_length self.GRU = nn.GRU(input_size = input_size, hidden_size = hidden_dimensions, num_layers = num_layers, bias = True, batch_first = True, bidirectional = True) self.predictor = nn.Linear(in_features = 2 * hidden_dimensions * seq_length, out_features = num_outputs) def forward(self, input): batch_size = input.shape h0 = torch.randn((2 * self.num_layers, batch_size,self.hidden_size)) out, h_n = self.GRU(input, h0) out = out.reshape(batch_size, 2 * self.hidden_size * self.seq_length) out = self.predictor(out) return out
The time series has 3-time steps with 4 feature channels and predicts 2 values that have to regressed.
Therefore, the output of the model is
I use Integrated Gradients to find the feature performance as follows -
integratedGradients = IntegratedGradients(model) attributions_ig, delta = integratedGradients.attribute(aisData, target=Coordinate, return_convergence_delta=True)
I however run into the issue mentioned in the heading.
The full trace is as follows -
Traceback (most recent call last): File "main.py", line 257, in <module> attributions_ig, delta = integratedGradients.attribute(aisData, target=Coordinate, return_convergence_delta=True) File "/home/atharva/.local/lib/python3.8/site-packages/captum/log/__init__.py", line 35, in wrapper return func(*args, **kwargs) File "/home/atharva/.local/lib/python3.8/site-packages/captum/attr/_core/integrated_gradients.py", line 286, in attribute attributions = self._attribute( File "/home/atharva/.local/lib/python3.8/site-packages/captum/attr/_core/integrated_gradients.py", line 351, in _attribute grads = self.gradient_func( File "/home/atharva/.local/lib/python3.8/site-packages/captum/_utils/gradient.py", line 112, in compute_gradients outputs = _run_forward(forward_fn, inputs, target_ind, additional_forward_args) File "/home/atharva/.local/lib/python3.8/site-packages/captum/_utils/common.py", line 455, in _run_forward return _select_targets(output, target) File "/home/atharva/.local/lib/python3.8/site-packages/captum/_utils/common.py", line 474, in _select_targets raise AssertionError( AssertionError: Tensor target dimension torch.Size([50, 2]) is not valid. torch.Size([50, 2])
How can I use Captum for this scenario ?