掩盖层导致错误InvalidArgumentError:不兼容的形状:[128,0]与[Keras中的[128,6]]

问题描述 投票:0回答:1

我的模特如下。

model = Sequential()
model.add(Embedding(input_dim=wordEmbeddings.shape[0]+2, output_dim=wordEmbeddings.shape[1], input_length=n_in,  trainable=False))       
model.add(Masking(mask_value=0.))
model.add(Bidirectional(LSTM(200, return_sequences=True, recurrent_dropout=0.5, dropout=0.5, name='bilstm1')))
model.add(TimeDistributed(Dense(100, activation="relu")))
crf = CRF(n_out,sparse_target=True)
model.add(crf)

型号摘要

enter image description here当我使用不带遮罩层的模型时,此模型可以正常工作。但是损失是负面的。因此,作为一种解决方案,我尝试添加遮罩,然后出现此错误,说

Blockquote enter image description here

keras recurrent-neural-network masking ner crf
1个回答
0
投票

根据您的描述,第一件事是您应该使用input_dim = wordEmbeddings.shape [0] +1而不是+2,在文档中说您应该使用max_index + 2,但是max_index = shape [0]-1,因此您应该使用+1而不是+2。然后,您只需将所有0传递给wordEmbeddings权重的第一行,然后将经过预训练的嵌入传递给其余的权重。

© www.soinside.com 2019 - 2024. All rights reserved.