Help protect the Great Barrier Reef with TensorFlow on Kaggle Join Challenge


A generic hash table that is immutable once initialized.

Inherits From: TrackableResource

Used in the notebooks

Used in the tutorials

Example usage:

keys_tensor = tf.constant(['a', 'b', 'c'])
vals_tensor = tf.constant([7, 8, 9])
input_tensor = tf.constant(['a', 'f'])
table = tf.lookup.StaticHashTable(
    tf.lookup.KeyValueTensorInitializer(keys_tensor, vals_tensor),
array([ 7, -1], dtype=int32)

Or for more pythonic code:

array([ 7, -1], dtype=int32)

The result of a lookup operation has the same shape as the argument:

input_tensor = tf.constant([['a', 'b'], ['c', 'd']])
array([[ 7,  8],
       [ 9, -1]], dtype=int32)

initializer The table initializer to use. See HashTable kernel for supported key and value types.
default_value The value to use if a key is missing in the table.
name A name for the operation (optional).
experimental_is_anonymous Whether to use anonymous mode for the table (default is False). In anonymous mode, the table resource can only be accessed via a resource handle. It can't be looked up by a name. When all resource handles pointing to that resource are gone, the resource will be deleted automatically.

default_value The default value of the table.
key_dtype The table key dtype.
name The name of the table.
resource_handle Returns the resource handle associated with this Resource.
value_dtype The table value dtype.



View source

Returns tensors of all keys and values in the table.

name A name for the operation (optional).

A pair of tensors with the first tensor containing all keys and the second tensors containing all values in the table.


View source

Looks up keys in a table, outputs the corresponding values.

The default_value is used for keys not present in the table.

keys Keys to look up. May be either a SparseTensor or dense Tensor.
name A name for the operation (optional).

A SparseTensor if keys are sparse, a RaggedTensor if keys are ragged, otherwise a dense Tensor.

TypeError when keys or default_value doesn't match the table data types.


View source

Compute the number of elements in this table.

name A name for the operation (optional).

A scalar tensor containing the number of elements in this table.