Summarised Question:
> How do I compute relevance of inputs for predicting ONE of the many outputs?
What I attempted so far:
As per your advise here, I now train my regression model in keras --> I copy over the weights and model topology (#layers, #nodes, activations), and rebuild it with lrp toolbox modules to use your LRP/DTD computation.
Now, if I want to run multitask learning, = say I have 3 output predictions (regression on all the three outputs), how do I compute relevance of the input features for predicting a certain output, say output1?
For the simple single output case, I have been doing the following:
ypred = nn.forward(xs) #xs is 2 dimensional = [#samples, #features]
Rsum = nn.lrp(ypred,'epsilon',1.).sum(axis=0)
#Summing the relevance scores across samples, Rsum=[1,#features ]
For the 3 outputs case [op0,op1,op2], to compute relevance of input features in predicting op1, do I do this??:
ypred = nn.forward(xs)[:,1] #NOTE [:,1] !!! Rest same.
Rsum = nn.lrp(ypred,'epsilon',1.).sum(axis=0)
#Summing the relevance scores across samples, Rsum=[1,#features ]
I then get this error:
Traceback (most recent call last):
File "/home/panditve/workspace/CurWorkDir/LrpExplainScikitMultiTask.py", line 833, in <module>
Rsum[0,:] = nn.lrp(ypred).sum(axis=0)
File "/home/panditve/workspace/CurWorkDir/modules/sequential.py", line 316, in lrp
R = m.lrp(R,lrp_var,param)
File "/home/panditve/workspace/CurWorkDir/modules/module.py", line 112, in lrp
return self._simple_lrp(R)
File "/home/panditve/workspace/CurWorkDir/modules/linear.py", line 129, in _simple_lrp
return ((Z / Zs) * R[:,na,:]).sum(axis=2)
IndexError: too many indices for array
In attempt to rootcause, I printed array shapes before the error line, got me this:
print(Z.shape) #Works
print(Zs.shape) #Works
print(R.shape) #Works
print(R[:,na,:].shape) # ERROR!
print(((Z / Zs) * R[:,na,:]).shape)
return ((Z / Zs) * R[:,na,:]).sum(axis=2)
(14033, 16, 3) #Z.shape
(14033, 1, 3) #Zs.shape
(14033,) #R.shape
Traceback (most recent call last):
File "/home/panditve/workspace/CurWorkDir/LrpExplainScikitMultiTask.py", line 833, in <module>
Rsum[0,:] = nn.lrp(ypred).sum(axis=0)
File "/home/panditve/workspace/CurWorkDir/modules/sequential.py", line 316, in lrp
R = m.lrp(R,lrp_var,param)
File "/home/panditve/workspace/CurWorkDir/modules/module.py", line 112, in lrp
return self._simple_lrp(R)
File "/home/panditve/workspace/CurWorkDir/modules/linear.py", line 127, in _simple_lrp
print(R[:,na,:].shape)
IndexError: too many indices for array