TypeError:传递到'ConcatV2'Op的'values'的列表中的张量具有[bool,float32]类型不完全匹配

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

我正在尝试使用我在此链接上找到的LSTM复制笔记本以进行实体识别:https://medium.com/@rohit.sharma_7010/a-complete-tutorial-for-named-entity-recognition-and-extraction-in-natural-language-processing-71322b6fb090

[当我尝试训练模型时,出现一个我无法理解的错误(我对tensorflow很陌生)。特别是有错误的代码部分是这一段:

from keras.models import Model, Input
from keras.layers import LSTM, Embedding, Dense, TimeDistributed, Dropout, Bidirectional
from keras_contrib.layers import CRF

# Model definition
input = Input(shape=(MAX_LEN,))
model = Embedding(input_dim=n_words+2, output_dim=EMBEDDING, # n_words + 2 (PAD & UNK)
                  input_length=MAX_LEN, mask_zero=True)(input)  # default: 20-dim embedding
model = Bidirectional(LSTM(units=50, return_sequences=True,
                           recurrent_dropout=0.1))(model)  # variational biLSTM
model = TimeDistributed(Dense(50, activation="relu"))(model)  # a dense layer as suggested by neuralNer
crf = CRF(n_tags+1)  # CRF layer, n_tags+1(PAD)
print(model)
out = crf(model)  # output

model = Model(input, out)
model.compile(optimizer="rmsprop", loss=crf.loss_function, metrics=[crf.accuracy])

model.summary()

错误在线

out = crf(model)

我得到的错误是这个:

TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have types [bool, float32] that don't all match.

有人可以给我一个解释吗?

python tensorflow keras lstm named-entity-recognition
1个回答
0
投票

我今天也遇到了这个问题。对我有用的是从嵌入层中删除mask_zero=True。不幸的是,我不知道为什么会有帮助。

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