Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the outputs from the embedding layer

from keras.models import Sequential
from keras.layers.embeddings import Embedding
from theano import function

model = Sequential()
model.add(Embedding(max_features, 128, input_length = maxlen))

I want to get the outputs from the embedding layers. I read through the source in keras but didnt find any suitable function or attribute. Anyone can help me with this?

like image 415
joydeep bhattacharjee Avatar asked Feb 08 '23 03:02

joydeep bhattacharjee


1 Answers

You can get the output of any layer, not just an embedding layer, as described here:

from keras import backend as K
get_3rd_layer_output = K.function([model.layers[0].input],
                                  [model.layers[3].output])
layer_output = get_3rd_layer_output([X])[0]

In your case, you would want model.layers[0].output instead of model.layers[3].output.

like image 126
1'' Avatar answered Feb 09 '23 15:02

1''