Class Activation Map with IMDB Sentiment Analysis from lesson 5

Once again, congratulations for the great course and forum.

I was trying to explore a little bit more with th IMDB Sentiment Analysis from Lesson 5, and thought it would be great to have some kind of Class Activation Map as the one described here for images (https://arxiv.org/pdf/1512.04150.pdf).

It woul be great for each case to inspect what words or regions of the text are the most relevant to the classification.

It seems to me I should change MaxPooling for AveragePooling and use a 2 category (1 and 0) with Softmax, right? Like that:

conv1 = Sequential([
Embedding(vocab_size, 32, input_length=seq_len, dropout=0.2),
Dropout(0.2),
Convolution1D(64, 5, border_mode=‘same’, activation=‘relu’),
Dropout(0.2),
AveragerPooling1D(),
Flatten(),
Dense(100, activation=‘relu’),
Dropout(0.7),
Dense(2, activation=‘softmax’)])

Then, I should extract the output of the convolution layer and multiply for the weights of each class of the softmax layer. Is that it? I tried a lot of things with the last part, but could not make it work.

Any ideas or sugestions?

Thank you very much!

2 Likes

Hi, I found this post looking for the same idea. Have you tried it? Did you find any other solution to explore how each token affects the final prediction? Thanks