如何从嵌入层获取输出 [英] 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))
我想从嵌入层获取输出.我通读了keras中的源代码,但没有找到任何合适的函数或属性.有人可以帮我吗?
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?
推荐答案
您可以获取任何层的输出,而不仅仅是嵌入层,如此处:
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]
在您的情况下,您希望使用model.layers[0].output
而不是model.layers[3].output
.
In your case, you would want model.layers[0].output
instead of model.layers[3].output
.
这篇关于如何从嵌入层获取输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文