Deep Learning with Javascript 2.4-2.4.3

Posted on April 2, 2020

Notes on chapter two of Deep Learning with Javascript

2.4 How to Interpret Your Model 2.4.1 Extracting Meaning from Learned Weights 2.4.2 Extracting Internal Weights from the Model 2.4.3 Caveats to Interpretability

2.4 How to Interpret Your Model

Goals

  1. Extract learned weights from a model
  2. Interpret thos weights to weigh them against what one might think they should be

2.4.1 Extracting Meaning from Learned Weights

The linear function example was scalar however the features and the kernel here are both vectors Here we are taking the dot product of the two vectors.

output = kernel · features + bias

This basically amounts to a relationship between the kernel and the features, where small learned values are learned to have little impact and and positive relationships increase predicted output and negative relationships decrease predicted output.

2.4.2 Extracting Internal Weights from the Model

Since this model has only one layer we can grab the output layer with the following

> model.layers[0]

Then we get the weights with the getWeights() since we’re using a dense layer the returned array of weights will always have two elements the kernel and the bias..

We can access the tensor we’re interested in with

> model.layers[0].getWeights()[0]

We can access the contents of the tensor with a call to the data() function since its an async function we use the promised value as in the previous post marked as kernelAsArray

2.4.3 Caveats to Interpretability

If weights are different in a model for a feature that is included twice they can be switched around so we cannot say very much about this feature. Correlation and causality must also be looked at carefully in order to avoid mistakes when making statements about features relationships to outputs…