Table initializers given keys
and values
tensors.
View aliases
Compat aliases for migration
See Migration guide for more details.
tf.lookup.KeyValueTensorInitializer(
keys, values, key_dtype=None, value_dtype=None, name=None
)
Used in the notebooks
Used in the guide | Used in the tutorials |
---|---|
keys_tensor = tf.constant(['a', 'b', 'c'])
vals_tensor = tf.constant([7, 8, 9])
input_tensor = tf.constant(['a', 'f'])
init = tf.lookup.KeyValueTensorInitializer(keys_tensor, vals_tensor)
table = tf.lookup.StaticHashTable(
init,
default_value=-1)
table.lookup(input_tensor).numpy()
array([ 7, -1], dtype=int32)
Methods
initialize
initialize(
table
)
Initializes the given table
with keys
and values
tensors.
Args | |
---|---|
table
|
The table to initialize. |
Returns | |
---|---|
The operation that initializes the table. |
Raises | |
---|---|
TypeError
|
when the keys and values data types do not match the table key and value data types. |