Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to reproduce the notebook for entity recognition using LSTM that i found on this link: https://medium.com/@rohit.sharma_7010/a-complete-tutorial-for-named-entity-recognition-and-extraction-in-natural-language-processing-71322b6fb090

When I try to train the model I get an error that I cannot understand (I'm quite new to tensorflow). In particular the part of code with the error is this one:

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()

The error is on the line

out = crf(model)

The error that I get is this:

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

Can someone give me an explanation?

like image 707
Paolopast Avatar asked Dec 05 '19 11:12

Paolopast


1 Answers

I also came across this problem today. what worked for me was to remove mask_zero=True from the embedding layer. unfortunately I don't know why this helps.

like image 148
moejoe Avatar answered Nov 14 '22 01:11

moejoe