Keras StringLookup: '<' not supported between instances of 'str' and 'float'

Viewed 120

I'm new to Keras and Tensorflow. Yesterday, I came across an error which is the following:

TypeError: '<' not supported between instances of 'str' and 'float'

The block of code that gave this error is:

for name, inpt in inputs.items():

    if inpt.dtype == tf.string:
        lookup = layers.StringLookup(vocabulary=np.unique(train[name]))

Here, inputs is a dictionary which contains Tensors of each column of the train dataset. All have the dtype of either float32 or string.

In the above code, I'm trying to fetch only the string dtypes but it's giving me the error that cannot compare str & float which has made me confused as the code should fetch only the string dtypes features.

Where am I doing wrong? Can you tell me?

1 Answers

One of the features in has None values. None are considered as float as np.nan. Drop them or try to replace None values with "unknown" ,...etc.

train.dropna(inplace=True)

I'm new to Tensorflow. Once I find better solution, I will post it here asap.

Related