votes up 0

`num_bins` cannot be `None` or non-positive values.

github stars 51164
Exception Class:

Raise code

    `RaggedTensor`, otherwise if any input is `SparseTensor` then output is
    `SparseTensor`, otherwise the output is `Tensor`.


  def __init__(self, num_bins, mask_value=None, salt=None, **kwargs):
    if num_bins is None or num_bins <= 0:
      raise ValueError('`num_bins` cannot be `None` or non-positive values.')
    super(Hashing, self).__init__(**kwargs)
    self.num_bins = num_bins
    self.mask_value = mask_value
    self.strong_hash = True if salt is not None else False
    if salt is not None:
      if isinstance(salt, (tuple, list)) and len(salt) == 2:

Ways to fix

votes up 2 votes down

The tf.keras.layers.experimental.preprocessing.Hashing layer transforms single or multiple categorical inputs to hashed output. It converts a sequence of int or string to a sequence of int. The parameter num_bins is to specify Number of hash bins and cannot be a None or non positive number.

Reproducing the error:

import tensorflow as tf
layer = tf.keras.layers.experimental.preprocessing.Hashing(num_bins=-3,salt=133)
inp = [['A'], ['B'], ['C'], ['D'], ['E']]


import tensorflow as tf
layer = tf.keras.layers.experimental.preprocessing.Hashing(num_bins = 3,salt=133)
inp = [['A'], ['B'], ['C'], ['D'], ['E']]

Jun 11, 2021 kellemnegasi answer
kellemnegasi 2.7k

Add a possible fix

Please authorize to post fix