votes up 0

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

Package:
keras
github stars 51164
Exception Class:
ValueError

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)
    base_preprocessing_layer.keras_kpl_gauge.get_cell('Hashing').set(True)
    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']]
layer(inp)

Fix:

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

Jun 11, 2021 kellemnegasi answer
kellemnegasi 2.7k

Add a possible fix

Please authorize to post fix