Fitting a Keras model yields error "constant folding failed: Invalid argument: Unsupported type: 21" Fitting a Keras model yields error "constant folding failed: Invalid argument: Unsupported type: 21" python-3.x python-3.x

Fitting a Keras model yields error "constant folding failed: Invalid argument: Unsupported type: 21"


There is one key difference between the Tutorial mentioned in the link, https://www.tensorflow.org/beta/tutorials/load_data/text and your Dataset.

In the tutorial, Labels are 0, 1 and 2, i.e., all the sentences in cowper.txt are Labelled as 0, all the sentences in derby.txt are Labelled as 1, all the sentences in butler.txt are Labelled as 2. But in your Dataset, Labels are at the end of each sentence of the Text Files.

I have executed the code taking part of your Dataset, as shown below:

FILE_NAMES = ['001.dev', '001.test', '001.train', '002.dev', '002.test', '002.train']parent_dir = "Issue_55902068/OC"parent_dir

In order to handle the difference mentioned above, the function, labeler should be modified as shown below:

def labeler(example, index):  Label = tf.strings.split(example, sep="")[-1] #It will give 0 or 1 in Str format  Label = tf.strings.to_number(Label)  return example, tf.cast(Label, tf.int64)

After that, I changed the loss function to binary_crossentropy and the optimizer to RMSprop as shown below:

model.compile(optimizer='RMSprop', loss='binary_crossentropy', metrics=['accuracy'])

It is working as expected. Screenshot of the output is shown below.

enter image description here