背景:项目中需要计算同一句子和库中所有句子的相似性,需要事先将库中所有句子的特征抽取出来,而这个特征对应到深度学习模型的中间层
方法:1)查看模型结构
pip install pydot
conda install graphviz 安装。然后在程序中使用:
或者使用 print(model.summary())
2)取中间层
名字取 model_penultimate= Model(inputs=model.input,
output=model.get_layer(‘sequential’).output
)
层数索引取 model_penultimate= Model(inputs=model.input,
model.layers[-2].output )
遇到的问题:
取-2层,
Graph disconnected: cannot obtain value for tensor Tensor(“embedding_input_46:0”, shape=(?, 20), dtype=float32) at layer “embedding_input”. The following previous layers were accessed without issue: []
查看output