votes up 6

validate must be a bool; got %r

Package:
Exception Class:
TypeError

Raise code

    if not isinstance(partitions, (list, tuple)):
      raise TypeError("partitions must be a list or tuple")
    for partition in partitions:
      if not isinstance(partition, cls._PARTITION_TYPES):
        raise TypeError("partitions must be a list of partition objects %s;"
                        " got: %r" % (cls._PARTITION_TYPES, partition))
    if not isinstance(validate, bool):
      raise TypeError("validate must be a bool; got %r" % validate)
    return super(RaggedFeature, cls).__new__(cls, dtype, value_key, partitions,
                                             row_splits_dtype, validate)


@tf_export("io.SparseFeature", v1=["io.SparseFeature", "SparseFeature"])
class SparseFeature(
    collections.namedtuple(
😲 Agile task management is now easier than calling a taxi. #Tracklify
🙏 Scream for help to Ukraine
Today, 25th May 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 2 votes down

tf.io.RaggedFeature is a configuration class for passing a RaggedTensor input feature. When initializing an instance of of this class the parameter validate should be a boolean type.

Reproducing the error:

pipenv install tensorflow

import tensorflow as tf


features = {
    'f1': tf.io.RaggedFeature(value_key="v", dtype=tf.int64),
    'f2': tf.io.RaggedFeature(value_key="v", dtype=tf.int64, partitions=[
        tf.io.RaggedFeature.RowSplits("s1")]),
    'f3': tf.io.RaggedFeature(value_key="v", dtype=tf.int64, partitions=[
        tf.io.RaggedFeature.RowSplits("s2"),
        tf.io.RaggedFeature.RowSplits("s1")],validate=2)
}
print(features.keys())

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-1cb22e44f7c2> in <module>()
      7     'f3': tf.io.RaggedFeature(value_key="v", dtype=tf.int64, partitions=[
      8         tf.io.RaggedFeature.RowSplits("s2"),
----> 9         tf.io.RaggedFeature.RowSplits("s1")],validate=2)
     10 }
     11 print(features)

/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/parsing_config.py in __new__(cls, dtype, value_key, partitions, row_splits_dtype, validate)
    216                         " got: %r" % (cls._PARTITION_TYPES, partition))
    217     if not isinstance(validate, bool):
--> 218       raise TypeError("validate must be a bool; got %r" % validate)
    219     return super(RaggedFeature, cls).__new__(cls, dtype, value_key, partitions,
    220                                              row_splits_dtype, validate)

TypeError: validate must be a bool; got 2


Fixed version of the code:

import tensorflow as tf

features = {
    'f1': tf.io.RaggedFeature(value_key="v", dtype=tf.int64),
    'f2': tf.io.RaggedFeature(value_key="v", dtype=tf.int64, partitions=[
        tf.io.RaggedFeature.RowSplits("s1")]),
    'f3': tf.io.RaggedFeature(value_key="v", dtype=tf.int64, partitions=[
        tf.io.RaggedFeature.RowSplits("s2"),
        tf.io.RaggedFeature.RowSplits("s1")],validate=True)
}
print(features.keys())

Output:

dict_keys(['f1', 'f2', 'f3'])

Jul 14, 2021 kellemnegasi answer
kellemnegasi 29.0k

Add a possible fix

Please authorize to post fix