tf.lookup.experimental.DenseHashTable

View source on GitHub

A generic mutable hash table implementation using tensors as backing store.

tf.lookup.experimental.DenseHashTable(
    key_dtype, value_dtype, default_value, empty_key, deleted_key,
    initial_num_buckets=None, name='MutableDenseHashTable', checkpoint=True
)

Data can be inserted by calling the insert method and removed by calling the remove method. It does not support initialization via the init method.

It uses "open addressing" with quadratic reprobing to resolve collisions. Compared to MutableHashTable the insert, remove and lookup operations in a DenseHashTable are typically faster, but memory usage can be higher. However, DenseHashTable does not require additional memory for temporary tensors created during checkpointing and restore operations.

Example usage:

table = tf.lookup.DenseHashTable(key_dtype=tf.int64,
                                 value_dtype=tf.int64,
                                 default_value=-1,
                                 empty_key=0,
                                 deleted_key=-1)

sess.run(table.insert(keys, values))
out = table.lookup(query_keys)
print(out.eval())

Args:

Attributes:

Raises:

Methods

erase

View source

erase(
    keys, name=None
)

Removes keys and its associated values from the table.

If a key is not present in the table, it is silently ignored.

Args:

Returns:

The created Operation.

Raises:

export

View source

export(
    name=None
)

Returns tensors of all keys and values in the table.

Args:

Returns:

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

insert

View source

insert(
    keys, values, name=None
)

Associates keys with values.

Args:

Returns:

The created Operation.

Raises:

insert_or_assign

View source

insert_or_assign(
    keys, values, name=None
)

Associates keys with values.

Args:

Returns:

The created Operation.

Raises:

lookup

View source

lookup(
    keys, name=None
)

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

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

Args:

Returns:

A tensor containing the values in the same shape as keys using the table's value type.

Raises:

remove

View source

remove(
    keys, name=None
)

Removes keys and its associated values from the table.

If a key is not present in the table, it is silently ignored.

Args:

Returns:

The created Operation.

Raises:

size

View source

size(
    name=None
)

Compute the number of elements in this table.

Args:

Returns:

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