0

I'm trying to identify the most and least relevant input features of an ANN model (implemented with TF 2). Since TF 2 returns the kernels and the bias calculated for each layer, the way to achieve so that I can imagine is by recalculating the weights of every node in the model manually. As example, let's assume that my model have 4 input features, one hidden layer with 2 nodes and a single node in the output layer.

    N1
    N2        N1         N1
    N3        N2
    N4
  layer0     layer1    layer2

Then my algorithm would look like this:

weight of path N11-N21-N31 = (layer[0].kernels[0] + layer[0].bias[0]) + (layer[1].kernels[0] + layer[1].bias[0]) + (layer[2].bias[0])

weight of path N11-N22-N31: (layer[0].kernels[0] + layer[0].bias[0]) + (layer[1].kernels[1] + layer[1].bias[1]) + (layer[2].bias[0])

...

Though I think this mechanism can work, I still have some questions:

  1. What's the operator to concatenate the weights of two layers (addition, multiplication, other)? I mean:
(layer[0].kernels[0] + layer[0].bias[0]) + (layer[1].kernels[0] + layer[1].bias[0])

or

(layer[0].kernels[0] + layer[0].bias[0]) * (layer[1].kernels[0] + layer[1].bias[0])
  1. Does Keras or TF provide an automatic tool or API to get this info?
  • Why not use ```tf.keras.Model``` ? – DachuanZhao Dec 01 '20 at 10:51
  • @DachuanZhao, my model is a tf.keras.Model. I just want to know how the input features are weighted during training. I can access the kernels and bias of every layer through the API but I'm not sure if I should add or multiply between layers. In any case, if there were a built-in too for doing so it'd be great. – heisenberg Dec 01 '20 at 15:10

0 Answers0