[英]View output of keras embedding layer
In keras, there is an example with sentiment classification with IMDB datasets. 在喀拉拉邦,有一个使用IMDB数据集进行情感分类的示例。 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)
. 我想查看此行
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
. 当我尝试在终端中调试或运行该行时,我看到它返回了
Embedding
类的对象。 As I read, Embedding
is a matrix. 如我所读,
Embedding
是一个矩阵。 So how can I see that matrix? 那我怎么看那个矩阵呢?
Use model.layers[0].get_weights()[0]
. 使用
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. Embedding
是模型的第一层,而您要查看的矩阵是该层的第一(也是唯一)权重。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.