Reputation: 1037
In keras, there is an example with sentiment classification with IMDB datasets. The code looks like this
top_words = 5000
(X_train, y_train), (X_test, y_test) = imdb.load_data(nb_words=top_words)
max_review_length = 500
X_train = sequence.pad_sequences(X_train, maxlen=max_review_length)
X_test = sequence.pad_sequences(X_test, maxlen=max_review_length)
embedding_vecor_length = 32
model = Sequential()
model.add(Embedding(top_words, embedding_vecor_length, input_length=max_review_length))
model.add(LSTM(100))
......
I want to see the output of this line Embedding(top_words, embedding_vecor_length, input_length=max_review_length)
. When I try to debug or run that line in the terminal, I see it returns an object of class Embedding
. As I read, Embedding
is a matrix. So how can I see that matrix?
Upvotes: 1
Views: 1916
Reputation: 14619
Use model.layers[0].get_weights()[0]
. Embedding
is the first layer of the model, and the matrix you want to see is the first (and only) weight of this layer.
Upvotes: 2