Pao*_*ast 6 python named-entity-recognition lstm keras tensorflow
我正在尝试使用我在此链接上找到的 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()
Run Code Online (Sandbox Code Playgroud)
错误就行了
out = crf(model)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是这样的:
TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have types [bool, float32] that don't all match.
Run Code Online (Sandbox Code Playgroud)
有人可以给我一个解释吗?
| 归档时间: |
|
| 查看次数: |
5378 次 |
| 最近记录: |