【问题标题】:how to get the outputs from the embedding layer如何从嵌入层获取输出
【发布时间】:2016-08-26 01:42:49
【问题描述】:
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 中的源代码,但没有找到任何合适的函数或属性。任何人都可以帮助我吗?

【问题讨论】:

    标签: python theano deep-learning keras


    【解决方案1】:

    您可以获得任何层的输出,而不仅仅是嵌入层,如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

    【讨论】:

    • 对我来说 get_3rd_layer_output = K.function([model.layers[0].input, K.learning_phase()], [model.layers[3].output]) 有效。
    • 我仍在试图弄清楚 X 的含义
    • 无论如何感谢您的回答。它向我展示了正确的方法
    • @joydeepbhattacharjee 你知道X是什么吗?
    • @YanLong 我希望如此。这发生在很久以前,我现在不记得了。希望我已经弄清楚了,或者我使用了不同的方法。
    猜你喜欢
    • 2023-03-12
    • 2018-12-16
    • 2020-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 2015-08-18
    相关资源
    最近更新 更多