tf.lookup.KeyValueTensorInitializer

Table initializers given keys and values tensors.

Used in the notebooks

Used in the guideUsed 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)

keysThe tensor for the keys.
valuesThe tensor for the values.
key_dtypeThe keys data type. Used when keys is a python array.
value_dtypeThe values data type. Used when values is a python array.
nameA name for the operation (optional).

key_dtypeThe expected table key dtype.
value_dtypeThe expected table value dtype.

Methods

initialize

View source

Initializes the given table with keys and values tensors.

Args
tableThe table to initialize.

Returns
The operation that initializes the table.

Raises
TypeErrorwhen the keys and values data types do not match the table key and value data types.